60.6. llvm21-21.1.8
LLVM 21, installed under /usr/lib/llvm21 beside the system LLVM for zig
| Version | 21.1.8, release 1 |
| Shelf | toolchain — The native compilers, the linker, the C library, and the LLVM family |
| Phase | 31_compilers (Compilers), 7 of 22 in build order |
| Licence | Apache-2.0 WITH LLVM-exception |
| Homepage | https://llvm.org/ |
| Build time | 97.0 SBU |
| Installed size | 251.2 MiB in 2766 files |
| Recipe | ports/core/toolchain/llvm21/kpkgbuild |
About
LLVM of the 21 series, installed beside the system llvm under the private prefix /usr/lib/llvm21 for zig, which is built against exactly one LLVM series and refuses any other. It is the first of the three slot ports, with clang21 and lld21 built on it. Everything it installs, the tools, the libraries, the headers and the CMake package, is under the prefix, which is on no default search path, so every other port still finds the system LLVM. How the slot is kept apart from the system copy is in A second version beside the first.
The configuration follows the system llvm port’s, less the manual pages, the gold plugin (LLVM_BINUTILS_INCDIR), the perf JIT listener (LLVM_USE_PERF) and the separate directory for the test utilities. The prefix is the recipe helper _prefix, /usr/lib/llvm${version%%.*}, and series = 21 keeps the update checker on the 21 line.
Sources
llvm21-21.1.8.tar.xz(74.1 MiB)
sha256d9022ddadb40a15015f6b27e6549a7144704ded8828ba036ffe4b8165707de21
upstream: https://github.com/llvm/llvm-project/releases/download/llvmorg-21.1.8/llvm-21.1.8.src.tar.xz
archive copy: sources-4/toolchain--llvm21-21.1.8.tar.xzcmake-21.1.8.src.tar.xz(8.8 KiB)
sha25685735f20fd8c81ecb0a09abb0c267018475420e93b65050cc5b7634eab744de9
upstream: https://github.com/llvm/llvm-project/releases/download/llvmorg-21.1.8/cmake-21.1.8.src.tar.xz
archive copy: sources-4/toolchain--cmake-21.1.8.src.tar.xzthird-party-21.1.8.src.tar.xz(445.1 KiB)
sha2567fe99424384aea529ffaeec9cc9dfb8b451fd1852c03fc109e426fe208a1f1a7
upstream: https://github.com/llvm/llvm-project/releases/download/llvmorg-21.1.8/third-party-21.1.8.src.tar.xz
archive copy: sources-4/toolchain--third-party-21.1.8.src.tar.xz
Dependencies
Depends on: cmake, ninja, libffi, python3, libxml2, zstd, zlib.
Required by (3): clang21, lld21, zig.
Installation
From the repository root, inside the build container, this is the line kdosbuild runs for the port:
script/chroot/exec.sh bash -c 'source script/phases/31_compilers/phase.env && kpkg install llvm21'
What kpkg does
kpkg runs these steps, in this order, as root inside the chroot. The port directory is /ports/core/toolchain/llvm21.
1. Verify every declared source. Each file a sha256 = line names, found in the port directory or in /var/cache/kpkg/sources, must hash to its line; a mismatch stops the build before anything is unpacked.
cd /ports/core/toolchain/llvm21
echo 'd9022ddadb40a15015f6b27e6549a7144704ded8828ba036ffe4b8165707de21 llvm21-21.1.8.tar.xz' | sha256sum -c -
echo '85735f20fd8c81ecb0a09abb0c267018475420e93b65050cc5b7634eab744de9 cmake-21.1.8.src.tar.xz' | sha256sum -c -
echo '7fe99424384aea529ffaeec9cc9dfb8b451fd1852c03fc109e426fe208a1f1a7 third-party-21.1.8.src.tar.xz' | sha256sum -c -
2. Unpack. The work directory is emptied and the first source is unpacked into $SRC with its top directory stripped; any later tarball lands unstripped beside it in $SRC_ROOT, and a file that is not a tarball is copied into $SRC.
SRC_ROOT=/var/cache/kpkg/work/llvm21
SRC=$SRC_ROOT/llvm21-21.1.8
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf llvm21-21.1.8.tar.xz -C "$SRC" --strip-components=1
tar --no-same-permissions --warning=no-unknown-keyword -xf cmake-21.1.8.src.tar.xz -C "$SRC_ROOT"
tar --no-same-permissions --warning=no-unknown-keyword -xf third-party-21.1.8.src.tar.xz -C "$SRC_ROOT"
Every config.guess and config.sub older than automake’s is then replaced with automake’s, so a configure script recognises the musl target.
3. Build. build.sh is sourced in a subshell under set -e, from $SRC, with name, version, release and the recipe’s helpers _prefix, series and the five paths PKGNAME, PORT_SRC, SRC_ROOT, SRC and PKG set as shell variables. Its body, verbatim:
mv $SRC_ROOT/cmake-${version}.src $SRC_ROOT/cmake
mv $SRC_ROOT/third-party-${version}.src $SRC_ROOT/third-party
cmake -B build -G Ninja \
-D CMAKE_INSTALL_PREFIX=$_prefix \
-D CMAKE_BUILD_TYPE=Release \
-D LLVM_HOST_TRIPLE="$(cc -dumpmachine)" \
-D LLVM_DEFAULT_TARGET_TRIPLE="$(cc -dumpmachine)" \
-D CMAKE_C_FLAGS_RELEASE="$CFLAGS -DNDEBUG" \
-D CMAKE_CXX_FLAGS_RELEASE="$CXXFLAGS -include cstdint -DNDEBUG" \
-D LLVM_BUILD_LLVM_DYLIB=OFF \
-D LLVM_LINK_LLVM_DYLIB=OFF \
-D BUILD_SHARED_LIBS=ON \
-D LLVM_PARALLEL_COMPILE_JOBS="$(echo "$MAKEFLAGS" | grep -o '[0-9]*')" \
-D LLVM_INCLUDE_EXAMPLES=OFF \
-D LLVM_INCLUDE_TESTS=OFF \
-D LLVM_INCLUDE_BENCHMARKS=OFF \
-D LLVM_INCLUDE_DOCS=OFF \
-D LLVM_ENABLE_FFI=ON \
-D LLVM_ENABLE_RTTI=ON \
-D LLVM_ENABLE_BINDINGS=OFF \
-D LLVM_ENABLE_ZLIB=FORCE_ON \
-D LLVM_ENABLE_ZSTD=FORCE_ON \
-D LLVM_ENABLE_LIBXML2=FORCE_ON \
-D LLVM_ENABLE_LIBEDIT=OFF \
-D LLVM_ENABLE_LIBPFM=OFF \
-D LLVM_ENABLE_Z3_SOLVER=OFF \
-D LLVM_INSTALL_UTILS=ON \
-D LLVM_ENABLE_LIBCXX=OFF \
-D LLVM_ENABLE_LLD=OFF \
-D LLVM_OPTIMIZED_TABLEGEN=ON \
-D LLVM_TARGETS_TO_BUILD=all \
-Wno-dev
cmake --build build
DESTDIR=$PKG cmake --install build
The switches, and why each is set:
CMAKE_INSTALL_PREFIX=$_prefix— Installs everything under/usr/lib/llvm21instead of/usr.LLVM_HOST_TRIPLE— gcc’s triple,$(cc -dumpmachine), as in the llvm port. Left to itself, LLVM guesses the glibc triplex86_64-unknown-linux-gnu, under which this series’ clang would find no gcc installation and no C++ headers; see An LLVM that guessed its triple.LLVM_DEFAULT_TARGET_TRIPLE— The same triple, as the default target of the slot’s clang.CMAKE_C_FLAGS_RELEASE— Replaces CMake’s Release flags,-O3 -DNDEBUG, with the tree’sCFLAGSand-DNDEBUG.CMAKE_CXX_FLAGS_RELEASE— The same for C++, with-include cstdintadded, as in the llvm port: GCC’s C++ library headers do not bring in<cstdint>, and a file that uses the fixed-width types without including it does not compile.LLVM_BUILD_LLVM_DYLIB=OFF— NolibLLVM.so.LLVM_LINK_LLVM_DYLIB=OFF— The tools link the component libraries.BUILD_SHARED_LIBS=ON— One shared library per component, as the system LLVM is built. The programs and libraries find each other through their$ORIGIN/../librun path.LLVM_PARALLEL_COMPILE_JOBS— The compile-job limit for Ninja, taken from the-jNinMAKEFLAGS, whichscript/env/common.envkeeps in exactly that form for this recipe and the llvm one.LLVM_INCLUDE_DOCS=OFF— No documentation targets. The slot installs no manual pages, andman llcshows the system LLVM’s.LLVM_INCLUDE_EXAMPLES=OFF— No examples; withLLVM_INCLUDE_TESTS=OFFandLLVM_INCLUDE_BENCHMARKS=OFF, no tests and no benchmarks.LLVM_ENABLE_FFI=ON—llicalls native functions through libffi.LLVM_ENABLE_RTTI=ON— Built with C++ run-time type information, as the system LLVM is.LLVM_ENABLE_BINDINGS=OFF— No OCaml bindings, which would otherwise follow whether an OCaml is found.LLVM_ENABLE_ZLIB=FORCE_ON— zlib support, with a missing zlib a configure error.LLVM_ENABLE_ZSTD=FORCE_ON— The same for zstd.LLVM_ENABLE_LIBXML2=FORCE_ON— The same for libxml2, which the Windows manifest library uses.LLVM_ENABLE_LIBEDIT=OFF— No line editing: libedit is a41_systemport, and the automatic probe would make the result depend on build order.LLVM_ENABLE_LIBPFM=OFF— No libpfm, which the tree does not carry.LLVM_ENABLE_Z3_SOLVER=OFF— No Z3 solver for the static analyzer; z3 is a later phase’s port.LLVM_INSTALL_UTILS=ON— InstallsFileCheck,notand the other utilities that LLVM’s CMake package exports, under the prefix’sbin, where they collide with nothing.LLVM_ENABLE_LIBCXX=OFF— Builds against libstdc++, the tree’s C++ library.LLVM_ENABLE_LLD=OFF— Links with binutils’ld.LLVM_OPTIMIZED_TABLEGEN=ON— Matters only in a debug or assertion build; in this Release build it changes nothing.LLVM_TARGETS_TO_BUILD=all— Every code generator. Zig’s CMake refuses an LLVM that lacks any of the targets it lists, andziglinks the libraries of every one of them, as itsNEEDEDentries show.
The common switches of each build system are explained in the Flag glossary.
4. Package. kpkg removes libtool archives, the info directory index, mimeinfo.cache and every fonts.dir from $PKG, copies the source’s licence files into /usr/share/licenses/llvm21, prunes what the image does not ship, lints the tree and rolls it reproducibly:
tar --sort=name --format=gnu --numeric-owner --owner=0 --group=0 \
--mtime=@$SOURCE_DATE_EPOCH \
--use-compress-program='xz -9 -T0 --block-size=32MiB --no-adjust' \
-cf llvm21-21.1.8-1.tar.xz -C "$PKG" .
5. Adopt. kpkgadd installs the package’s files over the root, refusing a path another package owns, records the file list in /var/lib/kpkg/db/llvm21, and runs the triggers its paths call for.
Contents
Installed directories: /usr/lib/llvm21/include/llvm, /usr/lib/llvm21/include/llvm-c, /usr/lib/llvm21/lib/cmake/llvm, /usr/lib/llvm21/share/opt-viewer, /usr/share/licenses/llvm21.
Notes
The 21 series is published as one tarball per component, and the LLVM tarball expects two of its siblings beside it under set names: its CMake files read ../cmake for the shared modules, and LLVM’s support library includes the SipHash header from ../third-party/siphash. The two mv lines give the unpacked cmake-<version>.src and third-party-<version>.src those names.
Zig finds this LLVM by CMAKE_PREFIX_PATH=/usr/lib/llvm21 and records /usr/lib/llvm21/lib as its run path, so /usr/bin/zig loads the slot’s libraries directly. Removing the slot breaks zig, whatever the system LLVM’s version.