llvm
- Do not set
BUILD_SHARED_LIBS
- Do not depend on
PyYAML
; required forllvm-libc
LLVM_ENABLE_ASSERTIONS
isOFF
by default withRelease
builds- Do we need
LLVM_PARALLEL_COMPILE_JOBS
? - Do we need
LLVM_PARALLEL_TABLEGEN_JOBS
? - Do we need
LLVM_INSTALL_UTILS
forFileCheck
andnot
? - Do not set
LLVM_EXTERNAL_LIT
to allow the bundledlit
to run; needed for standalone builds of subprojects - Do we need
LLVM_ROOT
? - Rely on the host’s compiler instead of crafting our own for the
toolchain
stage - For list of supported targets by
LLVM_TARGETS_TO_BUILD
, checkllvm/lib/Target/
- Enable
LLVM_OPTIMIZED_TABLEGEN
to reduce build time - Disable
CLANG_ENABLE_STATIC_ANALYZER
fortoolchain
andcross
- To disable
LIBCXX_ENABLE_RTTI
disableLIBCXX_ENABLE_EXCEPTIONS
first - What is the default value for
LIBCXX_CXX_ABI
? clang
by design is a full fledged cross compilerclang
always ignores-pipe
clang
uses LLVM’s integrated assembler (llvm-as) by default on all targets where it is supported- Enable
LIBCXX_USE_COMPILER_RT
andLIBCXXABI_USE_COMPILER_RT
to usecompiler-rt
overlibgcc_s
- Enable
LIBCXXABI_USE_LLVM_UNWINDER
to uselibunwind
overlibgcc_s
- Clang defaults to gnu99 mode while GCC defaults to gnu89 mode; try passing
-std=gnu89
to clang for weird link-time errors - Should we set
CMAKE_CXX_STANDARD
to20
instead of17
LLVM_BUILD_BENCHMARKS
,LLVM_BUILD_DOCS
,LLVM_BUILD_EXAMPLES
andLLVM_BUILD_TESTS
areOFF
by defaultLLVM_BUILD_LLVM_DYLIB
is used to buildllvm
as a single shared library; it can’t be used withBUILD_SHARED_LIBS
LLVM_DEFAULT_TARGET_TRIPLE
defaults tohost
(the machine wherellvm
is being built according to the docs) if no target is explicitly specified; for cross-compilers use$TGT
insteadLLVM_ENABLE_ASSERTIONS
defaults toOFF
ifCMAKE_BUILD_TYPE
isRelease
- Explicitly disable
LLVM_BUILD_TELEMETRY
andLLVM_ENABLE_BINDINGS
; they areON
by default LLVM_ENABLE_PEDANTIC
defaults toON
- It is better to pass
compiler-rt
toLLVM_ENABLE_RUNTIMES
rather thanLLVM_ENABLE_PROJECTS
- Try setting
LLVM_ENABLE_UNWIND_TABLES
toOFF
instead of passing-fno-unwind-tables
inCFLAGS
? - Consider
LLVM_ENABLE_Z3_SOLVER=ON
in the future LLVM_INTEGRATED_CRT_ALLOC
is only relevant on Windows- Consider
LLVM_ENABLE_RPMALLOC
?; can’t be used withLLVM_USE_SANITIZER=ON
LLVM_LINK_LLVM_DYLIB=ON
impliesLLVM_BUILD_LLVM_DYLIB=ON
- If
LLVM_TABLEGEN
is explicitly set tollvm-tblgen
, then no native TableGen will be compiled, and the one provided by the host will be used; this is useful when cross-compiling to reduce build time by not having to compile a native tool that could be provided by the host itself - It is better to not have
LLVM_TARGET_ARCH
set as a triplet, as it’ll resolve via regex toX86
almost always LLVM_USE_LINKER
prefixes the value (e.g.mold
) withld.
(so it becomesld.mold
)- Set
LLVM_USE_PERF
toON
forpgo
to work; also considerLLVM_ENABLE_LIBPFM
(should beON
by default) - Do we need
LLVM_USE_SANITIZER=OFF
? It defaults to an empty string "" so no? - Do we need this early on
LLVM_ENABLE_LIBXML2
? - Not all LLVM projects require LLVM;
compiler-rt
can be built withoutllvm
LLVM_ENABLE_LTO=Thin
does not work if you are usinggcc
to buildllvm
obviouslyCLANG_VENDOR_UTI
is a macOS only optionCLANG_LINK_CLANG_DYLIB
is set toLLVM_LINK_LLVM_DYLIB
value- Do we need
CLANG_BUILD_TOOLS=ON
? Are the tools really needed for just building software? CLANG_INCLUDE_DOCS
andCLANG_INCLUDE_TESTS
are set toLLVM_INCLUDE_DOCS
andLLVM_INCLUDE_TESTS
values respectively- Prefer
CMAKE_C_COMPILER
andCMAKE_CXX_COMPILER
overC_COMPILER
andCXX_COMPILER
; the latter arellvm
only and they set the former internally - Do we need to set
CMAKE_ASM_COMPILER=clang
? LLVM_LIBDIR_SUFFIX
is set to""
by default; alsoCLANG_LIBDIR_SUFFIX
is set to its value- Do we need
COMPILER_RT_DEFAULT_TARGET_ARCH
? - Do we need
LIBUNWIND_ENABLE_CROSS_UNWINDING
? - Do we need
COMPILER_RT_USE_ATOMIC_LIBRARY
; does it usecompiler-rt
orlibatomic
? LIBCXX_HARDENING_MODE=fast
is recommended due to minimal overhead- Do we need
LIBCXX_ENABLE_TIME_ZONE_DATABASE=OFF
? - Do not set
LIBCXX_ENABLE_PEDANTIC=ON
andLIBCXXABI_ENABLE_PEDANTIC=ON
as#include_next
is used everywhere - Do not mix
libstdc++
andlibc++
as they export the same symbols… - Arch does not provide
clang-tblgen
-Wno-dev
suppresses developer warnings- To build
mesa
you only needlibllvm
and maybeclang
(andlibclc
?)
References
- https://archive.fosdem.org/2024/events/attachments/fosdem-2024-2555-building-a-linux-distro-with-llvm/slides/22812/chimera_fosdem_2024_llvm_DIVbHby.pdf
- https://bcain-llvm.readthedocs.io/projects/libunwind/en/latest/BuildingLibunwind/
- https://clang.llvm.org/c_status.html
- https://clang.llvm.org/cxx_status.html
- https://clang.llvm.org/docs/ClangCommandLineReference.html
- https://clang.llvm.org/docs/CommandGuide/clang.html
- https://clang.llvm.org/docs/CrossCompilation.html
- https://clang.llvm.org/docs/index.html
- https://clang.llvm.org/docs/InternalsManual.html
- https://clang.llvm.org/docs/Toolchain.html
- https://clang.llvm.org/docs/Tooling.html
- https://clang.llvm.org/docs/UsersManual.html
- https://clang.llvm.org/get_started.html
- https://cliutils.gitlab.io/modern-cmake/
- https://cmake.org/cmake/help/book/mastering-cmake/chapter/Cross%20Compiling%20With%20CMake.html
- https://cmake.org/cmake/help/latest/index.html
- https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html
- https://compiler-rt.llvm.org/
- https://discourse.llvm.org/
- https://github.com/llvm/llvm-project/tree/main/llvm/lib/Target
- https://github.com/llvm/llvm-zorg
- https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/CrossCompiling
- https://libcxx.llvm.org/Hardening.html
- https://libcxx.llvm.org/index.html
- https://libcxx.llvm.org/Modules.html
- https://libcxx.llvm.org/TestingLibcxx.html
- https://libcxx.llvm.org/UserDocumentation.html
- https://libcxx.llvm.org/VendorDocumentation.html
- https://llvm.org/devmtg/2023-10/slides/tutorials/Hosek-UnderstandingtheLLVMbuild.pdf
- https://llvm.org/docs/AdvancedBuilds.html
- https://llvm.org/docs/BuildingADistribution.html
- https://llvm.org/docs/CMake.html
- https://llvm.org/docs/CMakePrimer.html
- https://llvm.org/docs/genindex.html
- https://llvm.org/docs/GettingStarted.html
- https://llvm.org/docs/GoldPlugin.html
- https://llvm.org/docs/HowToCrossCompileBuiltinsOnArm.html
- https://llvm.org/docs/HowToCrossCompileLLVM.html
- https://llvm.org/docs/Lexicon.html
- https://llvm.org/docs/UserGuides.html
- https://mcilloni.ovh/2021/02/09/cxx-cross-clang/
- https://muxup.com/building-testing-and-distributing-llvm-clang-and-friends
- https://rocm.docs.amd.com/projects/llvm-project/en/latest/LLVM/llvm/html/CMake.html
- https://wiki.musl-libc.org/building-llvm.html
- https://www.youtube.com/watch?v=NMQrnVDf-rY