Test an sccache setup by building a target cold, then again from cache, and comparing object hashes
RecipeVerified 8 Oct 2026Holds anywhere
Recipe. When to use it, the steps, and what showed that they work.
When to use#
You plan to move a CMake project's CI from ccache to sccache (or any compiler cache) and need to know that it caches your flags, that it hits, and that a hit gives the same bytes as a fresh compile.
Steps#
- Use a throwaway cache and server:
export SCCACHE_DIR=<scratch>/cache SCCACHE_CACHE_SIZE=8G; sccache --stop-server; sccache --start-server; sccache --zero-stats. - Configure with the launcher:
cmake --preset <p> -B <scratch>/C -DCMAKE_C_COMPILER_LAUNCHER=sccache -DCMAKE_CXX_COMPILER_LAUNCHER=sccache. Build one target (cmake --build <scratch>/C --target <t>), readsccache --show-stats(Compile requests, Cache hits, Cache misses, Cache errors, Non-cacheable compilations). - Delete the build directory, configure again at the SAME path, rebuild, and read the stats. Expect every request to hit. A build in a different directory missed most files (13.7% hits); the key contains absolute paths, and
SCCACHE_BASEDIRSon sccache 0.18.0 did not change that. CI builds in one fixed path, so this matters only when the path differs between jobs. - Prove correctness: build once with no launcher, hash every object (
cd <dir> && find . -name '*.o' | sort | xargs shasum -a 256), rebuild from cache at the same path, hash again, anddiffthe two lists. - Grep the sources for
__DATE__,__TIME__and__TIMESTAMP__, which would make a hit differ from a fresh compile.
Evidence#
dftracer-utils on macOS arm64 and x86-64 Linux, sccache 0.18.0: the dataframe library with its dependencies, 462 compile requests, cold 62 s, warm 9 s with 462 of 462 hits, 0 errors, 0 non-cacheable. 463 object files were identical to the build without a cache. No __DATE__, __TIME__ or __TIMESTAMP__ in src, include or python.
Also found by searching
- how do I check that sccache hits give the same object files as an uncached build
- sccache hit rate is low when the second build uses a different build directory
- sccache SCCACHE_BASEDIRS does not change the hit rate
- how can I measure compile cache hits for a cmake target before changing CI