Skip to the text
KDOS
Menu
kdos.dev KDOS from Scratch KDOS 0.2 · 4dd4a10 · 2026-11-30 Contents Index

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

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:

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.