Solved Build base from source without building clang and llvm?

Building llvm and clang takes a long time. I see there is a WITHOUT_CLANG option mentioned in src.conf(5):

Code:
     WITHOUT_CLANG
             Do not build the Clang C/C++ compiler during the regular phase of
             the build.  When set, it enforces these options:

             WITHOUT_CLANG_EXTRAS
             WITHOUT_CLANG_FORMAT
             WITHOUT_CLANG_FULL
             WITHOUT_LLVM_COV

So, does that mean that if I install clang and llvm from packages, then the build process would use those instead?

If so, any particular downsides to this approach? Am I likely to get frequently failing builds?
 
Last edited by a moderator:
src.conf is about kernel & base.
For kernel & base you want to use the default compiler. Or you might end-up with something with errors or unstable.
That's also why the default compiler is in base.
 
So, does that mean that if I install clang and llvm from packages, then the build process would use those instead?
No. The key sentence here is "during the regular phase of the build". Clang with just the features necessary for building base will still be built before that phase starts (when temporary tools are built). There might be options to tell the build to use a different compiler instead, I don't know for sure.
If so, any particular downsides to this approach? Am I likely to get frequently failing builds?
Not building clang during the regular build phase means the base system built (and installed) won't have a compiler.
 
According to src.conf(5). Although I am guessing it is not that easy.
Code:
WITHOUT_TOOLCHAIN=
WITHOUT_CROSS_COMPILER=
XCC=mycc
Yes, this looks about "right" (not tested).

I would warn not to use it. I guess it might be helpful for development (e.g. when porting to a new architecture), but certainly not meant for "production" use. If you try it:
  • Expect build issues (an OS needs some things that are not covered by the C standard, like e.g. parts that must be written in assembly)
  • Expect runtime issues (different compilers will create different binaries from the same source, only the official compiler included with base is really tested)
  • As already said, when you also disable the regular Clang build, you will have a system without compiler, making it more or less impossible to build ports on that system (you might try to install some compiler from pkg and override CC and CXX, but that's completely unsupported and probably, a lot of things will break)
As your concern was build time, better use the classic approaches to optimize that:
  • Enable "meta mode" (make sure filemon.ko is loaded, then add WITH_META_MODE=yes to your /etc/src-env.conf). This will only build parts that changed or have a changed dependency (unfortunately, the base compiler depends on the C standard library, so it will still be rebuilt on any change there...).
  • Enable WITH_CCACHE_BUILD, see src.conf(5). This will cache object files from every single compilation unit and reuse them if nothing changed.
 
Thank you all!
As your concern was build time, better use the classic approaches to optimize that:
  • Enable "meta mode" (make sure filemon.ko is loaded, then add WITH_META_MODE=yes to your /etc/src-env.conf). This will only build parts that changed or have a changed dependency (unfortunately, the base compiler depends on the C standard library, so it will still be rebuilt on any change there...).
  • Enable WITH_CCACHE_BUILD, see src.conf(5). This will cache object files from every single compilation unit and reuse them if nothing changed.
I have meta mode enabled, but didn't know about WITH_CCACHE_BUILD - thank you, have enabled that now.

I decided to take it for a test ride. Below are my src.conf and src-env.conf files:

Code:
KERNCONF=VALHALLA

WITHOUT_ASSERT_DEBUG="YES"
WITH_MALLOC_PRODUCTION="YES"
WITH_CCACHE_BUILD="YES"

# Experimental ...
WITHOUT_GSSAPI="YES
WITHOUT_KERBEROS="YES"

WITHOUT_LLVM_ASSERTIONS="YES"

Code:
WITH_META_MODE=YES

(VALHALLA just includes GENERIC, otherwise empty.)

I went to /usr/src/ and did git pull. There was only one single file that was updated - some man file somewhere within the /usr/src/share/ directory.

I then did make -j14 buildworld - which failed because I had forgotten to load the filemon module. I loaded that and then re-executed the build command which apparently kicked off a complete build of everything, including clang/llvm and so on.

Am I missing something? I don't think it should do that just for a man file?
 
If you just added ccache, this means your CC variable includes it for the first time (the "compiler" used is a ccache-wrapper around the real compiler), and (without verifying) I assume that's already enough to trigger a rebuild of everything. In any case, for ccache to be able to give an advantage, the cache must be filled first. In your next build, there will be the chance to pull object files from the cache instead of rebuilding them.

Btw, even ccache won't be able to do "magic" :cool:. If for example a source file of llvm/clang depends on a header of libc that changed, the corresponding object file still needs to be rebuilt.

Meta-mode already gets dependencies reliably correct, so in theory, it should be enough for building only what's necessary, but in practice, as the build is a "recursive" build, there will be dependencies on "directory level" (e.g. the entirety of llvm/clang depends on the entirety of libc, therefore any change in libc will cause the whole llvm/clang to be built). That's where ccache is able to optimize a bit more.

You should finally understand that because of how ccache works (by "wrapping" the compiler), you will still see every build build everything as meta-mode by itself would. It should just take less time as soon as some object files aren't really built but taken from the cache instead.
 
Thank you, zirias@ for the explanation, much appreciated.

Yes, that sounds very plausible. Fingers crossed for the next build.
 
Just a quick follow-up on this after some time has passed and I pulled new code into /usr/src/ and rebuilt:

Meta-mode with ccache works very well! Anecdotally, make -j14 buildworld took something like 5500s or more before, but this time it only took 926s! And similar speed-up when building the kernel.
 
Back
Top