43.9. ccache-4.14
Compiler cache
| Version | 4.14, release 2 |
| Shelf | buildtools — Build systems and build helpers |
| Phase | 30_foundation (Build Foundation), 94 of 127 in build order |
| Licence | GPL-3.0-or-later |
| Homepage | https://ccache.dev/ |
| Build time | 1.8 SBU |
| Installed size | 2.5 MiB in 8 files |
| Recipe | ports/core/buildtools/ccache/kpkgbuild |
About
ccache is a compiler cache: it hashes a compile’s source, its options and the compiler, and when it has seen the same compile before it hands back the stored object instead of running the compiler. For KDOS it is a build tool first. Once 30_foundation has installed it, script/env/chroot.env sends every CMake project of every later chroot step through it, and the cache in build/ccache survives make cleanbuild. The settings that keep a cached object byte-identical to a fresh compile are in The compiler cache.
The package also ships the masquerade directory /usr/lib/ccache, whose gcc, g++, cc, c++, clang and clang++ are symlinks to ccache: a user who puts that directory first on PATH gets every compile cached. The build itself never puts it on PATH, because CMake would record /usr/lib/ccache/gcc as the compiler in the files a package ships. The manual page is a separate port, ccache-manual, built once asciidoctor is installed.
Sources
ccache-4.14.tar.xz(538.1 KiB)
sha256b093ac5d38204cb4d9f29b0bbd570675aa5a592a78e6675b2c506dbe045234e7
upstream: https://github.com/ccache/ccache/releases/download/v4.14/ccache-4.14.tar.xz
archive copy: sources-1/buildtools--ccache-manual-4.14.tar.xz
Dependencies
Depends on: cmake, ninja, zlib, zstd, xxhash.
Required by (2): ccache-manual, verilator.
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/30_foundation/phase.env && kpkg install ccache'
What kpkg does
kpkg runs these steps, in this order, as root inside the chroot. The port directory is /ports/core/buildtools/ccache.
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/buildtools/ccache
echo 'b093ac5d38204cb4d9f29b0bbd570675aa5a592a78e6675b2c506dbe045234e7 ccache-4.14.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/ccache
SRC=$SRC_ROOT/ccache-4.14
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf ccache-4.14.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 . -B build -G Ninja \
-DCMAKE_INSTALL_PREFIX=/usr \
-DCMAKE_INSTALL_LIBDIR=lib \
-DCMAKE_INSTALL_LIBEXECDIR=lib \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_FLAGS_RELEASE="$CFLAGS -DNDEBUG" \
-DCMAKE_CXX_FLAGS_RELEASE="$CXXFLAGS -DNDEBUG" \
-DDEPS=LOCAL \
-DDEP_FMT=BUNDLED \
-DDEP_BLAKE3=BUNDLED \
-DDEP_CPPHTTPLIB=BUNDLED \
-DDEP_TLEXPECTED=BUNDLED \
-DCCACHE_DEV_MODE=OFF \
-DHTTP_STORAGE_BACKEND=ON \
-DREDIS_STORAGE_BACKEND=OFF \
-DENABLE_TESTING=OFF \
-DENABLE_DOCUMENTATION=OFF \
-Wno-dev
cmake --build build
DESTDIR=$PKG cmake --install build
install -d $PKG/usr/lib/ccache
for c in gcc g++ cc c++ clang clang++; do
ln -s /usr/bin/ccache $PKG/usr/lib/ccache/$c
done
The switches, and why each is set:
-DCMAKE_C_FLAGS_RELEASE="$CFLAGS -DNDEBUG"— Replace CMake’s Release flags,-O3 -DNDEBUG, with the tree’s own flags and-DNDEBUG. ccache’s C code builds at the tree’s-O2, with its assertions compiled out.-DCMAKE_CXX_FLAGS_RELEASE="$CXXFLAGS -DNDEBUG"— The same for the C++ code, which is most of ccache.-DCMAKE_INSTALL_LIBEXECDIR=lib— Point CMake’s helper-program directory at/usr/libinstead of/usr/libexec. ccache installs nothing there, but compiles the full path in as the default of itslibexec_dirssetting, the directories it searches for a remote-storage helper program,ccache-storage-<scheme>, before its own directory andPATH.-DDEPS=LOCAL— Use only libraries found on the system or bundled in the source. Under the default,AUTO, a required library missing from the system (xxhash, zstd) is downloaded, and the chroot has no network;LOCALmakes a missing one stop the configure instead. zstd and xxhash come from the ports independs.-DDEP_FMT=BUNDLED— Build against the copy of fmt insrc/third_partyeven when a system fmt is installed. fmt is a port of a later phase, so without this a build in30_foundationand a rebuild after41_systemwould link different libraries.-DDEP_BLAKE3=BUNDLED,-DDEP_CPPHTTPLIB=BUNDLED,-DDEP_TLEXPECTED=BUNDLED— The same pin for BLAKE3, cpp-httplib and tl-expected, which the tree carries no port of, so a library installed later under the same name never changes what ccache links.-DCCACHE_DEV_MODE=OFF— Dev mode is on whenever aCIvariable is in the environment or the source came from git. It adds-Werrorto the compile of ccache’s own code and makes the build probe for a faster linker (lld or gold) and link with whichever it finds, so the result would follow what the chroot happens to hold.-DHTTP_STORAGE_BACKEND=ON— Build the HTTP remote-storage backend, which lets a cache be shared through a web server. It is upstream’s default; it is what needs cpp-httplib.-DREDIS_STORAGE_BACKEND=OFF— Build no Redis remote-storage backend. It needs hiredis, which the tree does not carry, and withDEPS=LOCALa missing hiredis would stop the configure.-DENABLE_TESTING=OFF— Build no unit tests; they need doctest, which the tree does not carry.-DENABLE_DOCUMENTATION=OFF— Generate no manual. The generator is asciidoctor, a Ruby program that is installed only in a later phase;ccache-manualbuilds the page from the same source.
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/ccache, 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 ccache-4.14-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/ccache, and runs the triggers its paths call for.
Contents
Installed programs: ccache.
Installed directories: /usr/lib/ccache, /usr/share/licenses/ccache.
Notes
The masquerade directory names clang and clang++ although neither compiler is installed in 30_foundation. A link to a compiler that is not installed does nothing until it is; a compiler with no link in the directory is one that a compile through it runs uncached, with no warning.