60.7. clang21-21.1.8
Clang 21 libraries and compiler, installed under /usr/lib/llvm21 for zig
| Version | 21.1.8, release 2 |
| Shelf | toolchain — The native compilers, the linker, the C library, and the LLVM family |
| Phase | 31_compilers (Compilers), 8 of 22 in build order |
| Licence | Apache-2.0 WITH LLVM-exception |
| Homepage | https://clang.llvm.org/ |
| Build time | 48.7 SBU |
| Installed size | 206.3 MiB in 1344 files |
| Recipe | ports/core/toolchain/clang21/kpkgbuild |
About
Clang of the 21 series, installed under /usr/lib/llvm21 beside llvm21 for zig. Zig compiles C and C++ with clang’s libraries and links libclang-cpp.so of the same series, so the slot needs a clang as well as an LLVM. Nothing under the prefix is on PATH, so clang on the command line is still the system clang. How the slot is kept apart from the system copy is in A second version beside the first.
The 21 series is published as one tarball per component. This port carries clang’s and the shared cmake tarball, and builds standalone against llvm21’s CMake package.
Sources
clang21-21.1.8.tar.xz(25.8 MiB)
sha2566090e3f23720d003cdd84483a47d0eec6d01adbb5e0c714ac0c8b58de546aa62
upstream: https://github.com/llvm/llvm-project/releases/download/llvmorg-21.1.8/clang-21.1.8.src.tar.xz
archive copy: sources-4/toolchain--clang21-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.xz
Dependencies
Required by (1): 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 clang21'
What kpkg does
kpkg runs these steps, in this order, as root inside the chroot. The port directory is /ports/core/toolchain/clang21.
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/clang21
echo '6090e3f23720d003cdd84483a47d0eec6d01adbb5e0c714ac0c8b58de546aa62 clang21-21.1.8.tar.xz' | sha256sum -c -
echo '85735f20fd8c81ecb0a09abb0c267018475420e93b65050cc5b7634eab744de9 cmake-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/clang21
SRC=$SRC_ROOT/clang21-21.1.8
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf clang21-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"
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
cmake -B build -G Ninja \
-D CMAKE_INSTALL_PREFIX=$_prefix \
-D CMAKE_BUILD_TYPE=Release \
-D CMAKE_C_FLAGS_RELEASE="$CFLAGS -DNDEBUG" \
-D CMAKE_CXX_FLAGS_RELEASE="$CXXFLAGS -DNDEBUG" \
-D LLVM_DIR=$_prefix/lib/cmake/llvm \
-D LLVM_ENABLE_RTTI=ON \
-D LLVM_INCLUDE_TESTS=OFF \
-D CLANG_ENABLE_LIBXML2=ON \
-D CMAKE_REQUIRE_FIND_PACKAGE_LibXml2=ON \
-D CLANG_BUILD_EXAMPLES=OFF \
-D CLANG_INCLUDE_DOCS=OFF \
-D CLANG_INCLUDE_TESTS=OFF \
-D CLANG_LINK_CLANG_DYLIB=OFF \
-D BUILD_SHARED_LIBS=ON \
-D CLANG_BUILT_STANDALONE=ON \
-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/llvm21.CMAKE_C_FLAGS_RELEASE— Replaces CMake’s Release flags,-O3 -DNDEBUG, with the tree’sCFLAGSand-DNDEBUG.CMAKE_CXX_FLAGS_RELEASE— The same for C++.LLVM_DIR=$_prefix/lib/cmake/llvm— The LLVM CMake package to build against: the slot’s, not the system’s in/usr/lib/cmake/llvm, which a plain search would find first.LLVM_ENABLE_RTTI=ON— Built with C++ run-time type information, matching llvm21.CLANG_ENABLE_LIBXML2=ON— Lets clang use libxml2, which reaches onlyc-index-test’s check of libclang’s comment XML against its schema.CMAKE_REQUIRE_FIND_PACKAGE_LibXml2=ON— clang looks for libxml2 with aQUIETfind_package; this makes a missing one a configure error rather than ac-index-testbuilt without it.CLANG_BUILD_EXAMPLES=OFF— No example plugins.CLANG_INCLUDE_DOCS=OFF— No documentation targets, so no manual page is generated; the one page under the prefix isscan-build.1, which the static analyzer installs as a plain file.CLANG_INCLUDE_TESTS=OFF— No test targets; withLLVM_INCLUDE_TESTS=OFF, no tests at all.CLANG_LINK_CLANG_DYLIB=OFF— Links the clang tools against clang’s component libraries, notlibclang-cpp.so, which is built and installed all the same.BUILD_SHARED_LIBS=ON— Builds each clang component as its own shared library, as llvm21 builds LLVM’s. This port installs no static archives; its programs and libraries find each other through their$ORIGIN/../librun path.CLANG_BUILT_STANDALONE=ON— clang sets this itself when its directory is the top of the CMake tree, as it is here; naming it changes nothing.
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/clang21, 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 clang21-21.1.8-2.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/clang21, and runs the triggers its paths call for.
Contents
Installed directories: /usr/lib/llvm21/include/clang, /usr/lib/llvm21/include/clang-c, /usr/lib/llvm21/lib/clang, /usr/lib/llvm21/lib/cmake/clang, /usr/lib/llvm21/lib/libear, /usr/lib/llvm21/lib/libscanbuild, /usr/lib/llvm21/libexec, /usr/lib/llvm21/share/clang, /usr/lib/llvm21/share/man, /usr/lib/llvm21/share/scan-build, /usr/lib/llvm21/share/scan-view, /usr/share/licenses/clang21.
Notes
clang-tools-extra is not built here, so the slot has no clangd or clang-tidy; those are the system clang’s.
The mv line gives the unpacked cmake-<version>.src the name cmake, beside clang’s own directory, where clang’s CMakeLists.txt reads the shared CMake modules from ../cmake.