A compiler cache that understands C++20 modules.
cppmcache is used like ccache, as a prefix to the compiler. Unlike ccache, it caches module interface units (the object and the BMI) and the units that import modules, and it knows when a change to a module does not reach its importers.
ccache does not cache named modules: imported BMIs are not part of its key, and a hit cannot restore the BMI an interface produces (ccache#1252). On a modules project it passes most compilations straight to the compiler, or, for a unit that imports a module, may serve an object built against an older BMI.
Rebuilding from an empty build directory with a populated cache — a fresh CI job, a new checkout, a
branch switch. These rows are generated from the reports of a run of the Benchmark workflow by
tools/publish_measurements.py; that workflow runs every week and republishes them in its summary.
| Project and compiler | No cache | ccache | cppmcache | Gain |
|---|---|---|---|---|
| cppmcache itself, GCC 16.1 | 76.1 s | 75.2 s (2 units of 42 cached) | 1.0 s | 78× |
| cppmcache itself, Clang 21 on Linux | 28.6 s | 22.4 s (12 units of 42 cached) | 0.7 s | 40× |
| cppmcache itself, Clang 21 on macOS | 30.4 s | 30.8 s (2 units of 42 cached) | 1.8 s | 17× |
| cppmcache itself, MSVC 19.52 | 49.4 s | 1.6 s (42 units of 42 cached), then the build fails after an edit | 1.3 s | 39× |
Medians of 3 rounds from run 46272711849 of commit 23be186, 2026-11-29, on GitHub's shared runners; the full tables, with the lowest and highest times, are in docs/measurements.md.
On MduX, with GCC 16.1, 343 units and 24 cores, the same rebuild took 15.2 s with cppmcache (343 hits) against 75.5 s without a cache, and after a comment is edited in a core module interface, 122 units re-run by the build system took 1.8 s instead of 34.4 s (121 hits), because the BMI did not change. Those are single local runs. All 950 tests of MduX pass on a build served entirely from the cache.
Method, full tables and the cases where cppmcache gains nothing are in docs/measurements.md.
In GitHub Actions, with a released binary and the cache kept between runs:
- uses: ambroise-leclerc/cppmcache@v0.4.0
- run: cmake -S . -B build -G Ninja -DCMAKE_CXX_COMPILER_LAUNCHER=cppmcache
- run: cmake --build build
- run: cppmcache -sAnywhere else, download a binary from the releases (Linux x86_64 and aarch64 with glibc 2.35 or later, macOS 15 or later on Apple Silicon and Intel, Windows x86_64) and name it as the compiler launcher:
cmake -S . -B build -G Ninja -DCMAKE_CXX_COMPILER_LAUNCHER=/path/to/cppmcacheFrom source, inside your own build, with CPM.cmake:
CPMAddPackage("gh:ambroise-leclerc/cppmcache#<commit>")
cppmcache_enable(my_library my_executable)cppmcache -s shows the statistics, with the reasons why compilations were not cached, the most
frequent first; -z zeroes them and -C clears the cache (statistics).
The cache keeps itself under 5 GiB by evicting the entries used least recently; CPPMCACHE_MAXSIZE
changes the limit (eviction).
| Compiler | Platform | Module commands cached |
|---|---|---|
| GCC 16 | Linux | -fmodules, -fmodule-mapper=<file> |
| Clang 20+ | Linux, macOS | -fmodule-output=, -fmodule-file=name=path, --precompile |
| MSVC 19.40+ | Windows | /interface, /ifcOutput, /reference name=path |
| clang-cl | Windows, Linux | none: cl's module options are passed through |
CI builds and tests cppmcache, and runs its integration tests through it, with GCC 16.1, Clang 21
and Clang 23 with libc++ on Linux, Clang 21 on macOS, and the MSVC of GitHub's windows-2025
image (19.52 at the time of writing). Clang 22 has been tested by hand. These are the commands
CMake writes with the Ninja generator. Anything cppmcache does not
understand is passed to the compiler unchanged, so it never breaks a build it cannot cache, and
cppmcache -s says why. A compiler is recognised by its name (g++, clang++-21, cl…), by the
name a symbolic link leads to, or else, for a program of the machine named c++ or cc such as a
copy of a compiler, by what it prints when asked for --version; that answer is part of the key. A
compiler that is a script is passed through: its environment can change the compiler it runs or its
options, which nothing in the key would show.
With MSVC, Debug builds are not cached unless they use /Z7. CMake's default, /Zi, writes to a
PDB shared by the compilations of a target. Configure with
-DCMAKE_MSVC_DEBUG_INFORMATION_FORMAT=Embedded to get /Z7, which is cached
(details).
| To share between… | Set |
|---|---|
| checkouts, or CI runners | CPPMCACHE_BASEDIR to the root of the project: paths under it become relative |
| machines | CPPMCACHE_REMOTE=http://host:port, a bazel-remote or any server of Bazel's HTTP caching protocol |
| machines with different compiler dates | CPPMCACHE_COMPILERCHECK=content |
The remote cache has no TLS and no authentication yet: use it on a network you trust. Details are in docs/usage.md.
| Variable | Effect |
|---|---|
CPPMCACHE_DIR |
cache directory (default: ~/.cache/cppmcache; ~/Library/Caches/cppmcache on macOS; %LOCALAPPDATA%\cppmcache on Windows) |
CPPMCACHE_MAXSIZE |
size of the local cache beyond which the entries used least recently are evicted: 500M, 5G, 0 for no limit (default: 5G, powers of 1024) |
CPPMCACHE_BASEDIR |
absolute directory under which paths are made relative |
CPPMCACHE_COMPILERCHECK |
content: identify the compiler by the digest of its executable |
CPPMCACHE_REMOTE |
URL of a remote cache |
CPPMCACHE_REMOTE_READ_ONLY |
fetch from the remote cache but never publish to it |
CPPMCACHE_REMOTE_TIMEOUT_MS |
time allowed for one remote operation (default: 10000) |
CPPMCACHE_LOG |
file to which each call appends its outcome, the reason and the time of each phase (format) |
CPPMCACHE_DISABLE |
run the compiler directly |
CPPMCACHE_RECACHE |
ignore existing entries and replace them |
- A key per module, not per path. An imported module enters the key under its name and the digest of its BMI. The key is a Remote Execution API action digest; storage is a content-addressable store plus an action cache, locally and remotely.
- Early cutoff. A unit depends on the BMIs it imports, not on their sources. If an interface is edited and its BMI is unchanged, everything downstream is a hit.
- Interface digest. GCC writes the build time and directory into every BMI; cppmcache leaves that out of the digest, so identical interfaces compare equal.
- No preprocessor pass. Inputs are read from what the compiler reports: the dependency file and
module mapping for GCC and Clang,
/sourceDependenciesfor MSVC. - Header shadowing is detected. A header created earlier in the search order than one a unit
included changes what the compiler reads without changing any file it read. So does a header that
a
__has_includetest looks for, when it appears or disappears, even if nothing includes it. cppmcache checks the places where such a file would be, and recompiles.
The full description is in docs/design.md.
- It is a prototype: the format of the cache may change.
- Early cutoff needs the compiler to produce an identical BMI. With GCC, moving a declaration of an interface changes it; with Clang, so does any edit that changes the length of the file, and with MSVC even a comment edited in place (details).
- With GCC, CMake does not pass the
stdmodule through the launcher, so a fresh build directory compiles it again (CMake issue 28338); a workaround caches it. - With GCC, a module that imports other modules and is listed in several targets is compiled once per target: its BMI records where the BMIs it imports are (why).
- Not cached: profiling builds other than coverage, MSVC's
/Zi(/Z7is), GCC module mappers that are programs, streams or sockets (why), and linking.
The complete list is in docs/usage.md.
cppmcache is itself written with C++23 modules and import std;. It needs CMake 4.0 to 4.4, Ninja,
and GCC 16.1, Clang 20+ with libc++, or MSVC 19.40+.
cmake -S . -B build -G Ninja -DCMAKE_CXX_COMPILER=g++
cmake --build build && ctest --test-dir buildOther compilers and options are in docs/usage.md.
See CONTRIBUTING.md. The project is written in British English throughout. If cppmcache proves useful, it is intended as the basis of a proposal to ccache.
GNU General Public Licence, version 3 or (at your option) any later version, like ccache. See LICENSE.
The remote cache client is built on stdnet and
stdexec (Apache 2.0 with LLVM exceptions). The tests use
SpecLab. All are fetched at configure time by
CPM.cmake (MIT, vendored in cmake/CPM.cmake).