60.3. clang-23.1.2
The C/C++ compiler, plus clangd, clang-tidy and clang-format
| Version | 23.1.2, release 2 |
| Shelf | toolchain — The native compilers, the linker, the C library, and the LLVM family |
| Phase | 31_compilers (Compilers), 3 of 22 in build order |
| Licence | Apache-2.0 WITH LLVM-exception |
| Homepage | https://clang.llvm.org/ |
| Build time | 108.3 SBU |
| Installed size | 1.9 GiB in 1985 files |
| Recipe | ports/core/toolchain/clang/kpkgbuild |
About
Clang, LLVM’s C, C++ and Objective-C compiler, with its own tools, among them clang-format and the static analyzer’s scan-build, and those of clang-tools-extra, among them the language server clangd and clang-tidy. It also installs libclang, the C interface to clang’s parser, and libclang-cpp.so, the C++ libraries as one shared object.
The system C and C++ compiler stays GCC; nothing in the environment makes clang the default, and a port uses clang only when its recipe asks for it. Among the ports that do are the browsers (chromium, firefox-esr, librewolf) and thunderbird, the BPF tools (bpftrace, bcc, bpftool) and mesa. The OpenCL driver of mesa-opencl, rusticl, compiles OpenCL C with clang’s libraries. Everything that runs bindgen loads libclang at build time.
The build is standalone: it configures the clang directory of the llvm-project archive against the installed llvm, finds it through /usr/lib/cmake/llvm, and builds nothing of LLVM itself.
Why it is in KDOS
The comment above clang and llvm in script/phases/31_compilers/packages.txt:
clang and llvm are developer tools, not needed for self-hosting: they serve the projects that prefer LLVM. lldb is its own port, in 41_system.
Sources
clang-23.1.2.tar.xz(170.9 MiB)
sha256c98bbef08a2b4c2613cd50e9aa9ae7b69b1fe6c16b2c40373bc0ab6116fdf78a
upstream: https://github.com/llvm/llvm-project/releases/download/llvmorg-23.1.2/llvm-project-23.1.2.src.tar.xz
archive copy: sources-4/toolchain--clang-23.1.2.tar.xz
Dependencies
Depends on: llvm, libxml2, python3-sphinx, openmp.
Required by (32): bcc, bindgen, bpftool, bpftrace, castxml, chromium, compiler-rt, firefox-esr, hfsprogs, hurl, ispc, kdevelop, libclc, librewolf, limine, linux, lldb, mesa, mesa-opencl, networkmanager, ouch, perf, python3-pyside6, qemu, qt-creator, termusic, thunderbird, tree-sitter, v4l-utils, waypipe, wine, wiremix.
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 clang'
What kpkg does
kpkg runs these steps, in this order, as root inside the chroot. The port directory is /ports/core/toolchain/clang.
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/clang
echo 'c98bbef08a2b4c2613cd50e9aa9ae7b69b1fe6c16b2c40373bc0ab6116fdf78a clang-23.1.2.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/clang
SRC=$SRC_ROOT/clang-23.1.2
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf clang-23.1.2.tar.xz -C "$SRC" --strip-components=1
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 five paths PKGNAME, PORT_SRC, SRC_ROOT, SRC and PKG set as shell variables. Its body, verbatim:
cmake -S clang -B build -G Ninja \
-D CMAKE_INSTALL_PREFIX=/usr \
-D CMAKE_BUILD_TYPE=Release \
-D CMAKE_C_FLAGS_RELEASE="$CFLAGS -DNDEBUG" \
-D CMAKE_CXX_FLAGS_RELEASE="$CXXFLAGS -DNDEBUG" \
-D LLVM_ENABLE_RTTI=ON \
-D LLVM_ENABLE_EH=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=ON \
-D CLANG_TOOLS_EXTRA_INCLUDE_DOCS=ON \
-D LLVM_ENABLE_SPHINX=ON \
-D SPHINX_OUTPUT_HTML=OFF \
-D SPHINX_OUTPUT_MAN=ON \
-D SPHINX_WARNINGS_AS_ERRORS=OFF \
-D CLANG_INCLUDE_TESTS=OFF \
-D LIBCLANG_BUILD_STATIC=ON \
-D CLANG_LINK_CLANG_DYLIB=OFF \
-D CLANG_BUILT_STANDALONE=ON \
-D CLANG_ENABLE_CLANGD=ON \
-D CLANGD_BUILD_XPC=OFF \
-D LLVM_EXTERNAL_CLANG_TOOLS_EXTRA_SOURCE_DIR="$SRC/clang-tools-extra" \
-D LLVM_TARGETS_TO_BUILD="AMDGPU;BPF;NVPTX;WebAssembly;X86" \
-Wno-dev
cmake --build build
DESTDIR=$PKG cmake --install build
cmake --build build --target docs-clang-man docs-clang-tools-man
install -Dm644 build/docs/man/*.1 build/tools/extra/docs/man/*.1 \
-t "$PKG/usr/share/man/man1"
The switches, and why each is set:
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_ENABLE_RTTI=ON— Builds clang with C++ run-time type information, matching the llvm port.LLVM_ENABLE_EH=ON— Asks for C++ exception support. In this standalone build the installedLLVMConfig.cmakesetsLLVM_ENABLE_EHto the value the llvm port was built with, which does not enable it, and that value takes the place of the command line’s: clang is compiled with-fno-exceptions, and the installedlibclang-cpp.sohas no.gcc_except_tablesection.CLANG_ENABLE_LIBXML2=ON— Lets clang use libxml2. It reaches onlyc-index-test, which checks libclang’s comment XML against its schema.CMAKE_REQUIRE_FIND_PACKAGE_LibXml2=ON— clang looks for libxml2 with aQUIETfind_package; this makes a missing libxml2 a configure error instead of ac-index-testbuilt without it.CLANG_BUILD_EXAMPLES=OFF— Builds none of clang’s example plugins.CLANG_INCLUDE_DOCS=ON— Generates the documentation targets. It defaults toLLVM_INCLUDE_DOCS, which a standalone build never defines, so without itdocs-clang-mandoes not exist and the build after the install stops.CLANG_TOOLS_EXTRA_INCLUDE_DOCS=ON— The same forclang-tools-extra, whose target isdocs-clang-tools-man.LLVM_ENABLE_SPHINX=ON— Makes the Sphinx targets available, with python3-sphinx independs.SPHINX_OUTPUT_HTML=OFF— No HTML documentation targets.SPHINX_OUTPUT_MAN=ON— The manual-page targets.SPHINX_WARNINGS_AS_ERRORS=OFF— Keeps a Sphinx warning in the release’s own documents from failing the manual-page build.CLANG_INCLUDE_TESTS=OFF— Generates no test targets; withLLVM_INCLUDE_TESTS=OFF, no tests are configured at all.LIBCLANG_BUILD_STATIC=ON— Buildslibclang.abesidelibclang.so, for a consumer that links libclang statically.CLANG_LINK_CLANG_DYLIB=OFF— Links the clang tools against clang’s component libraries rather thanlibclang-cpp.so, as the llvm port links its tools against its components.libclang-cpp.sois built and installed either way.CLANG_BUILT_STANDALONE=ON— clang sets this itself when its directory is the top of the CMake tree, as-S clangmakes it; naming it changes nothing.CLANG_ENABLE_CLANGD=ON— Buildsclangd, the language server editors talk to.CLANGD_BUILD_XPC=OFF— No XPC transport for clangd. XPC is macOS’s inter-process mechanism, and the default is already off on Linux.LLVM_EXTERNAL_CLANG_TOOLS_EXTRA_SOURCE_DIR— Whereclang-tools-extrais. A standalone clang build reaches clangd, clang-tidy and the other extra tools only through this variable; without it the same build produces a compiler and none of them, and reports success.LLVM_TARGETS_TO_BUILD— Names five targets, but in this standalone build the installedLLVMConfig.cmakesetsLLVM_TARGETS_TO_BUILDto the list llvm was built with, every target, and that takes the place of the command line’s. The installedclanglinks the code generators of every target LLVM has, and the target-specific headers such asarm_neon.handriscv_vector.hare installed in the resource directory.
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/clang, 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 clang-23.1.2-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/clang, and runs the triggers its paths call for.
Contents
Installed programs: amdgpu-arch, analyze-build, clang, clang++, clang-23, clang-apply-replacements, clang-change-namespace, clang-check, clang-cl, clang-cpp, clang-doc, clang-extdef-mapping, clang-format, clang-include-cleaner, clang-include-fixer, clang-installapi, clang-linker-wrapper, clang-move, clang-nvlink-wrapper, clang-offload-bundler, clang-query, clang-refactor, clang-reorder-fields, clang-repl, clang-scan-deps, clang-ssaf-analyzer, clang-ssaf-format, clang-ssaf-linker, clang-sycl-linker, clang-tidy, clangd, diagtool, find-all-symbols, git-clang-format, hmaptool, intercept-build, modularize, nvptx-arch, offload-arch, pp-trace, run-clang-tidy, scan-build, scan-build-py, scan-view.
Installed libraries: libclang-cpp.so, libclang.a, libclang.so, libclangAPINotes.a, libclangAST.a, libclangASTMatchers.a, libclangAnalysis.a, libclangAnalysisFlowSensitive.a, libclangAnalysisFlowSensitiveModels.a, libclangAnalysisLifetimeSafety.a, libclangApplyReplacements.a, libclangBasic.a, libclangChangeNamespace.a, libclangCodeGen.a, libclangCrossTU.a, libclangDaemon.a, libclangDaemonTweaks.a, libclangDependencyScanning.a, libclangDirectoryWatcher.a, libclangDoc.a, libclangDocSupport.a, libclangDriver.a, libclangDynamicASTMatchers.a, libclangEdit.a, libclangExtractAPI.a, libclangFormat.a, libclangFrontend.a, libclangFrontendTool.a, libclangHandleCXX.a, libclangHandleLLVM.a, libclangIncludeCleaner.a, libclangIncludeFixer.a, libclangIncludeFixerPlugin.a, libclangIndex.a, libclangIndexSerialization.a, libclangInstallAPI.a, libclangInterpreter.a, libclangLex.a, libclangMove.a, libclangOptions.a, libclangParse.a, libclangQuery.a, libclangReorderFields.a, libclangRewrite.a, libclangRewriteFrontend.a, libclangScalableStaticAnalysisAnalyses.a, libclangScalableStaticAnalysisCore.a, libclangScalableStaticAnalysisFrontend.a, libclangScalableStaticAnalysisSourceTransformation.a, libclangScalableStaticAnalysisTool.a, libclangSema.a, libclangSerialization.a, libclangStaticAnalyzerCheckers.a, libclangStaticAnalyzerCore.a, libclangStaticAnalyzerFrontend.a, libclangSupport.a, libclangTidy.a, libclangTidyAbseilModule.a, libclangTidyAlteraModule.a, libclangTidyAndroidModule.a, libclangTidyBoostModule.a, libclangTidyBugproneModule.a, libclangTidyCERTModule.a, libclangTidyConcurrencyModule.a, libclangTidyCppCoreGuidelinesModule.a, libclangTidyCustomModule.a, libclangTidyDarwinModule.a, libclangTidyFuchsiaModule.a, libclangTidyGoogleModule.a, libclangTidyLLVMLibcModule.a, libclangTidyLLVMModule.a, libclangTidyLinuxKernelModule.a, libclangTidyMPIModule.a, libclangTidyMain.a, libclangTidyMiscModule.a, libclangTidyModernizeModule.a, libclangTidyObjCModule.a, libclangTidyOpenMPModule.a, libclangTidyPerformanceModule.a, libclangTidyPlugin.a, libclangTidyPortabilityModule.a, libclangTidyReadabilityModule.a, libclangTidyUtils.a, libclangTidyZirconModule.a, libclangTooling.a, libclangToolingASTDiff.a, libclangToolingCore.a, libclangToolingInclusions.a, libclangToolingInclusionsStdlib.a, libclangToolingRefactoring.a, libclangToolingSyntax.a, libclangTransformer.a, libclangUnifiedSymbolResolution.a, libclangdMain.a, libclangdRemoteIndex.a, libclangdSupport.a, libfindAllSymbols.a.
Installed directories: /usr/include/clang, /usr/include/clang-c, /usr/include/clang-tidy, /usr/lib/clang/23/include/cuda_wrappers, /usr/lib/clang/23/include/llvm_libc_wrappers, /usr/lib/clang/23/include/llvm_offload_wrappers, /usr/lib/clang/23/include/openmp_wrappers, /usr/lib/clang/23/include/ppc_wrappers, /usr/lib/clang/23/include/zos_wrappers, /usr/lib/cmake/clang, /usr/lib/libear, /usr/lib/libscanbuild, /usr/share/clang, /usr/share/clang-doc, /usr/share/licenses/clang, /usr/share/scan-build, /usr/share/scan-view.
Short descriptions
clang |
the Clang C, C++, and Objective-C compiler |
diagtool |
clang diagnostics tool |
scan-build |
Clang static analyzer |
Notes
The manual pages are built by target after the install and copied by hand, because nothing puts them in the default build without LLVM_BUILD_DOCS, and that would bring in every other documentation target too. docs-clang-man makes clang(1) and diagtool(1); docs-clang-tools-man makes extraclangtools(1), the clang-tools-extra manual as one page.
CLANG_DEFAULT_OPENMP_RUNTIME is left at its default, libomp, which openmp installs, so clang -fopenmp compiles against its omp.h and links libomp. The driver passes -fopenmp on to the front end only for libomp and libiomp5: pointed at GCC’s libgomp, a program would link, but every OpenMP pragma would be dropped and it would run serially with no diagnostic.
The helper scripts of the static analyzer and of intercept-build (ccc-analyzer, c++-analyzer, analyze-cc, intercept-cc and the rest) are installed in CMake’s default /usr/libexec, and must stay there: scan-build looks for ccc-analyzer and c++-analyzer only in ../libexec beside its own directory and in that directory itself, and analyze-build looks for analyze-cc only in ../libexec. Installed anywhere else, scan-build stops with 'ccc-analyzer' does not exist at '/usr/bin/ccc-analyzer'.
The LLVM options named here that LLVMConfig.cmake also sets (LLVM_ENABLE_RTTI, LLVM_ENABLE_EH, LLVM_TARGETS_TO_BUILD) follow the llvm port, whatever this command line says. A change to one of them belongs in the llvm recipe.