Runtime builds for multiple targets

I trying to build a clang (tag: llvmorg-14.0.0) toolchain with corresponding runtimes for x86_64-pc-linux-gnu and i386-pc-linux-gnu but I am running into some issues. The current cmake call looks like:

cmake \
  -G "Ninja" \
  -DCMAKE_INSTALL_PREFIX=tmp_install \
  -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra;lld" \
  -DLLVM_ENABLE_RUNTIMES="compiler-rt;libcxx;libcxxabi;libunwind" \
  -DLLVM_RUNTIME_TARGETS="x86_64-pc-linux-gnu;i386-pc-linux-gnu" \
  -DLLVM_HOST_TRIPLE="x86_64-pc-linux-gnu" \
  -DLLVM_DEFAULT_TARGET_TRIPLE="x86_64-pc-linux-gnu" \
  -S $SRC_DIR/llvm-project/llvm \
  -B $WORKSPACE_DIR/build/x86_64-pc-linux-gnu/llvm
  1. The first issue is that the flags LIBCXX_USE_COMPILER_RT, LIBCXXABI_USE_LLVM_UNWINDER and LIBCXXABI_USE_LLVM_UNWINDER are not considered by the runtime builds. The cmake cache $WORKSPACE_DIR/build/x86_64-pc-linux-gnu/llvm/runtimes/runtimes-x86_64-pc-linux-gnu-bins/CMakeCache.txt contains for example LIBCXX_USE_COMPILER_RT:BOOL=OFF.

  2. The second issue is that the i386-pc-linux-gnu runtime build is failing because the SANITIZER_ALLOW_CXXABI flag is on regarding the cache and that leads to some linker issues with unresolved symbols.

I would be very grateful for further help.

The various cmake options for all of the runtime builds are not forwarded from the main built. For that reason you likely should have gotten a warning by CMake that they did not have any impact.

The way to solve this is by prefixing the cmake options with BUILTINS_${target}_<option> for the builtins built in compiler-rt, and RUNTIMES_${target}_<option> for any of the other runtimes build.
In your case that’d eg. be -DRUNTIMES_x86_64-pc-linux-gnu_LIBCXX_USE_COMPILER_RT=ON -DRUNTIMES_i386-pc-linux-gnu_LIBCXX_USE_COMPILER_RT=ON instead of -DLIBCXX_USE_COMPILER_RT=ON.
These options are then forwarded to the respective runtime build for the respective target.

As you can imagine, this turns into a big command line very quickly. One way to mitigate this issue a bit is by creating a *.cmake file that simply sets all those options using normal cmake syntax and then using it with the -C option of cmake. That basically runs that file to pre populate the cache with those options before configuring.

The best in tree example of this that I have always used to configure my runtime builds are the Fuchsia configure caches: llvm-project/Fuchsia.cmake at main · llvm/llvm-project · GitHub
But the other files in that directory should be of just as great of a help.