Solved [Solved] Is the Clang version in the 9.2 base system usable?

ShelLuser

Son of Beastie

Reaction score: 1,814
Messages: 3,600

Hi gang!

This evening I rebuilt my (virtual) FreeBSD test and play environment which I'm using in VirtualBox. I picked up a 'boot only' ISO for FreeBSD 9.2 and have been busy installing and compiling.

Now, I'm aware that clang is part of the base system. First of all there's an /usr/bin/clang entry, but I can also confirm as much by checking the source tree which I keep on my server; it becomes obvious if you come across a directory like this: /usr/src/usr.bin/clang.

However, I just started to notice that during most of the day in which I've been busy I haven't seen any Clang-generated warnings appearing on my screen. None what so ever. Which makes me wonder if GCC is still heavily in effect.

On my server I installed lang/clang33 ever since I started using the source tree (I became aware of this project shortly after I started building a custom kernel). On my virtual environment I haven't done this (yet) because I was convinced that the base system would be able to provide.

And that brings me to my question: do you need to install lang/clang33 in order to fully utilize Clang or can you already rely on the base system?

Thanks in advance for any comments!
 

sossego

Retired from the forums

Reaction score: 147
Messages: 1,557

Re: FreeBSD 9.2: is the Clang version in the base system usa

You can use either that provided by the system or what is available through /usr/ports. Certain build scripts will require you to post the entire file path. The /usr/src/usr.bin/clang is for rebuilding the system, not for using as a binary application.
 

kpa

Beastie's Twin

Reaction score: 1,826
Messages: 6,318

Re: FreeBSD 9.2: is the Clang version in the base system usa

Before I upgraded to FreeBSD 10 I had my 9.2 system using the base system clang(1) as the default compiler for everything. The base system is definitely ready for clang in 9.2 and I didn't come across that many ports that didn't compile with it. However my set of ports built is so small (and biased towards non-graphical tools and services) that it doesn't serve as proper proof that everything works as expected.
 

ljboiler

Well-Known Member

Reaction score: 142
Messages: 418

Re: FreeBSD 9.2: is the Clang version in the base system usa

AFAIK, Clang is NOT the default base compiler for FreeBSD 9.2; that switch happens with FreeBSD 10.
 
OP
ShelLuser

ShelLuser

Son of Beastie

Reaction score: 1,814
Messages: 3,600

Re: FreeBSD 9.2: is the Clang version in the base system usa

ljboiler said:
AFAIK, clang is NOT the default base compiler for FreeBSD 9.2; that switch happens with FreeBSD 10.
Correct, I think I should have been more clear.

When it comes to the source tree I enforce the usage of Clang by adding this to /etc/src.conf:

Code:
## Compiler specification
CC=clang
CPP=clang-cpp
CXX=clang++
However, when it comes to my virtual 'playground' my main concern is for the ports collection.
 

ljboiler

Well-Known Member

Reaction score: 142
Messages: 418

Re: FreeBSD 9.2: is the Clang version in the base system usa

Ah! /etc/src.conf controls options for make in the base source tree, not the ports tree from what I read in src.conf(5). https://wiki.freebsd.org/PortsAndClang suggests putting that same compiler specification you have there into /etc/make.conf for using Clang with ports for FreeBSD versions prior to 10.
 

sossego

Retired from the forums

Reaction score: 147
Messages: 1,557

Re: FreeBSD 9.2: is the Clang version in the base system usa

Formatting seems to be the most common error, followed by path, and then function when it comes to the transitioning from GCC to Clang.
 
OP
ShelLuser

ShelLuser

Son of Beastie

Reaction score: 1,814
Messages: 3,600

Re: FreeBSD 9.2: is the Clang version in the base system usa

kpa said:
The base system is definitely ready for clang in 9.2 and I didn't come across that many ports that didn't compile with it.
Great, that's exactly what I wanted to know. Then it does indeed boil down to a misconception on my end; I expected something which most likely wasn't there; but that must have been intended. That saves me the trouble of having to wait a while for Clang to build :)
 
OP
ShelLuser

ShelLuser

Son of Beastie

Reaction score: 1,814
Messages: 3,600

Re: FreeBSD 9.2: is the Clang version in the base system usa

ljboiler said:
https://wiki.freebsd.org/PortsAndClang suggests putting that same compiler specification you have there into /etc/make.conf for using clang with ports for FreeBSD versions prior to 10.
That information seems to be somewhat out of date. There has been a change to the Ports collection some time ago which makes it prefer Clang by default. See /usr/ports/UPDATING:

Code:
20131008:
  AFFECTS: all users
  AUTHOR: bapt@FreeBSD.org

  A new USES has been added: compiler.mk, this uses allows porters to
  select a compiler for a given port based on the features the port needs
  By default this will always try to find Clang > 3.3.
  If the user prefers using GCC then the following macro should be added
  to user's make.conf: FAVORITE_COMPILER=gcc
And that led up to my previous question.
 

ljboiler

Well-Known Member

Reaction score: 142
Messages: 418

Re: FreeBSD 9.2: is the Clang version in the base system usa

I saw that too, but then I read the fine print again (and looked at /usr/ports/Mk/Uses/compiler.mk): a port must have a
Code:
USES= compiler
in it to turn on that "use Clang if it's there" logic, and that
Code:
USES= compiler
furthermore must be asking for a specific compiler feature as well (such as understanding c+11). Adding those CC=, CXX=, etc lines to /etc/make.conf still seems to be the only blanket way to use Clang to build any port when Clang is not the default system compiler.
 

pkubaj

Aspiring Daemon

Reaction score: 101
Messages: 555

Re: FreeBSD 9.2: is the Clang version in the base system usa

There's also WITH_CLANG_IS_CC to be set in /etc/src.conf. It makes Clang install as /usr/bin/c{c,++,pp}.
 
OP
ShelLuser

ShelLuser

Son of Beastie

Reaction score: 1,814
Messages: 3,600

Re: FreeBSD 9.2: is the Clang version in the base system usa

Man, at times like this I miss the thanks system :\ But in order not to turn this into an endless stream of useless messages I'll just combine my response.

Thanks guys, that's very helpful!

Very well spotted @ljboiler, I only read that snippet and then assumed that it would somehow try to get Clang preferred by default. I guess I missed the fine print ;) Good thing to know that I wasn't overlooking things; Clang is indeed not being actively used on my test system. But I know how to fix that :)

And of course thanks for the build flag @pkubaj! I've only recently discovered the things you can configure in src.conf to 'manage' your base system, and although I did notice WITH_CLANG and WITH_CLANG_FULL I somehow managed to totally overlook that one. That's going to come in very handy for future builds on my servers.
 
Last edited by a moderator:
Top