Advanced Build Configurations

edit: I have updated this with a working build configuration for clang/llvm, so the first part in black now works

advanced build configurations is a paper on clang/llvm. It can be seen here, and this post utilizes everything you can utilize without writing any code. No coding is needed in any of this, except maybe the bash file at the end.

Start by obtaining a copy of clang/llvm for your system, if on debian/ubuntu thats via the command “sudo apt install clang llvm” and “sudo apt install clang*19*” would be even better as it would install 19, and everything about 19, into your computer.

If your on enterprise linux, then it’s something like “sudo dnf install clang llvm” but I am not exactly sure on this, and you cannot continue with this until you have clang/llvm installed.

Next we will obtain the source code for clang, to use to compile it with our begotten copy of clang++ and clang/llvm, we get the source via this command: “sudo apt install git cmake make ninja-build meson” to install, I do not know how to install on enterprise, but just look each thing up, and install them, saving the command in a file for later as that is where it will be when your system eventually goes down, putting it on a pen drive or something (flash drive). But don’t actually buy a flash drive, buy the literal hard disks, they last so much longer, like this one for example I will post one here: 4 TERABYTE $300 SSD and 2 TERABYTE $150 SSD

Those links are from newegg and I do not have any beefs with anyone that sells that many computer parts or accessories. Anyways, with our command now copied and in a place that will be registerable after a systems crashing, we can now gather up the code: (without sudo) “git clone https://github.com/llvm/llvm-project.git” that is the command on both debian/ubuntu and enterprise, same command, and we after it runs for about 20 minutes now have the full source code to the clang/llvm system! We could even, and we do, build the entire libc+, they call it libc and libcxx I think. So we “mkdir build” inside of the folder llvm-project, and then type in the following, explained command below it explained, ;

Before you enter this command, optionally read past until after the second command, the second command can be entered into this command by adding -DCLANG_ENABLE_PROJECTS=”libcxx;libcxxabi” and i’ll add it for you even, because it should be there

Bash
sudo cmake -G "Unix Makefiles" ../llvm -C "/home/madness/source-opt/clang-22-2/llvm-project/clang/cmake/caches/3-stage.cmake" -DCLANG_C_COMPILER="clang" -DLLVM_ENABLE_PROJECTS="clang;lld;lldb" -DCLANG_CXX_COMPILER="clang++" -DLLVM_ENABLE_RUNTIMES="libunwind" -DBOOTSTRAP_PASSTHROUGH="CMAKE_INSTALL_PREFIX;CMAKE_VERBOSE_MAKEFILE" -DCMAKE_INSTALL_PREFIX="/home/YOUR-USERNAME/opt/clang-22-1" -DPGO_INSTRUMENT_LTO="Thin"
Bash

mind that is all one command! We start by invoking cmake with sudo, and then declare we want them in “Unix Makefiles” that’s just a fancy word for the old, original and still sometimes in use “make” program on debian/ubuntu or enterprise. Next is the directory ../llvm which is where everything is at, the source code, and then we see -C “/home/madness/source-opt/clang-22-2/llvm-project/clang/cmake/caches/3-stage.cmake” which brings up additional rules to our build, that state that they build a compiler, with that build a 2nd compiler, and with the 2nd compiler build the 3rd compiler, at which point the 2nd and 3rd compilers are identical, or should be, that way you know your not missing anything while your doing this, and if you are I don’t know how to fix it but do not proceed down this route any farther, back on the trail, we then declare to use the c compiler “clang” and you may need to type “clang-19” here or “clang++-19” for the C++ one, bootstrap passthrough are the files that are shared between the bootstrapping process, this 3-stage build a c ompiler and-with-that-one build one process is called bootstrapping, and is very common to see if there are any improvements that you can make to your compilers, if they cannot build themselves then there is something drastically wrong with the compiler, not to say that there actually is, because today’s compilers CAN build themselves, as is the case here

and next we entered enable_lld bootstrap and build the “lld” program which is the… linker? I think? or ASSEMBLER rather for llvm/clang, turning that on we turn the bootstrap bootstrap of that, then PGO or profile guided optimizations for our project, “thin” I don’t remember what that means, and enable projects for this we shall enable clang and lld, the assembler, of the llvm system which stands for large language virtual machine, the L.L.VM. is a very powerful system if you ever get that far, you can create programming languages with it, defining your own language, and maybe someday I will write about that too, but here we are, at the end of our command, run it and…

“sudo make -j16” where 16 is the number of threads in your system monitors resources page, this will mostly use up your whole computer while it’s doing it, don’t even try to do something else unless you have at least two physical cpu’s, it only takes about 20 minutes, and then we enter the next command, sudo cmake -G “Unix Makefiles” ../llvm i’ll just write it below. But first, to install the compiler we just built, we must edit our .bashrc file in our home directory to include the following lines:

Bash
CLANG_BASE="/home/your-username/opt/clang-22-1"
CLANG_BIN="$CLANG_BASE/bin"
CLANG_LIB="$CLANG_BASE/lib"
CLANG_LIB64="$CLANG_BASE/lib64"
CLANG_EXEC="$CLANG_BASE/exec"

CLANG_ALL="$CLANG_BIN:$CLANG_LIB:$CLANG_LIB64:$CLANG_EXEC"

export PATH="$CLANG_ALL:$PATH"
Bash

Where “opt” is whereever your compiler is, by default that is ../lib/llvm-22/bin/clang++ so you wouldn’t actually include the “clang++” in there, you would just write GCC_BASE=”/lib/llvm-22″ and that’s about all you have to do for this step!

Okay now we have clang installed on our systems, and it’s linked into the terminal, so now we can go and actually repeat our compiler process, and after that repeating we shall build libc, using another make command:

Bash
sudo cmake -G "Unix Makefiles" ../llvm -DCMAKE_INSTALL_PREFIX="/home/your-username/opt/clang-22-1" -DCLANG_ENABLE_PROJECTS="libcxx;libcxxabi" -DCLANG_C_COMPILER="clang" -DCLANG_CXX_COMPILER="clang++"
Bash

This one is a bit smaller, but it builds libc, and this is my first time building libc so hold on while I investigate this,

After that configures itself, we type “sudo make -j16” where 16 is the amount of threads we have in our system monitor, and then minusing it by like 4 if you want to use your computer while this step goes (don’t, be using your computer when your doing these steps if at all possible, and unless you have dual cpu’s, 2 physical cpus or greater,) it takes awhile to build libcxx, but there it is now type “sudo make install” and then we must add libcxx to our systems.

Ahhhhhhh fuck. You can just build libcxx alongside the compiler build, son of a, well now we know, I’ll put a note to come to this sentence.

So now we have clang, and that is all for advanced build configurations this link is where I got this stuff but if you’ve read to here then you already know mostly all of that stuff.

And that is how you build a C++ compiler, but not yet how to work on one, which is like the holy grail of programming, I don’t think anyones ever managed to work on one outside of like a company setting, I know this is wrong but i’ll just leave it there, bye for now.

You may also like...

2 Responses

Leave a Reply

Your email address will not be published. Required fields are marked *