Repository navigation
Description
In my professional capacity I've adopted ccache in some places, and it's grown on me, particularly for mitigating the awful build times of conventional C++ projects. It supports Windows well, and compiles to a clean ~2MiB standalone image, ccache.exe, so it perfectly fits the philosophy here. In the simplest case this would be one new file, bin/ccache.exe, but I would also add a number of support aliases to make it easier to use. For instance, ccache can masquerade as a compiler via symlinks, so on typical unix systems you can prepend /usr/lib/ccache/ to your PATH to automatically and transparently get ccache coverage on all your builds. We could have the same in w64dk.
Symlinks are impractical on Windows, so we have src/alias.c to create "command aliases" and so do not need symlinks for this particular purpose. Unfortunately that does not work with ccache. Normally it knows not to invoke itself recursively because it notices the symlink and searches PATH manually for the real compiler. A command alias is undetectable by ccache, so a lib/ccache/gcc.exe aliased to ../../bin/ccache.exe is really just a forkbomb when lib/ccache/ is prepended to PATH. As a workaround we can use an old trick: name it lib/ccache/gcc.com. It's still a PE, not a 16-bit COM. Windows doesn't rely on the file extension to determine how to load an image, and .com is merely another way to set the executable bit. It's not recursive because ccache strictly searches for executables named .exe (look forutil::add_exe_suffix) and will skip over gcc.com.
The catch is that GNU Make follows a similar heuristic, and favors gcc.exe over gcc.com even if it appears later in PATH (GNU Make bug), so the main benefit (transparency) is lost. Doh! CMake-generated Makefiles still work because CMake does not use this heuristic, finds gcc.com (or g++.com, etc.) just fine, and hardcodes it as the compiler path in the generated configuration.
Some other ideas:
-
Write a custom command alias program just for ccache which finds the real compiler before invoking ccache, passing along the information. This essentially replaces ccache's built-in masquerading with a custom implementation.
-
Patch ccache with knowledge about command aliases, so it can handle them like it already does symlinks. But what if the target "compiler" is a command alias (e.g.
c++.exe) and we do want to invoke it? -
Patch ccache with knowledge about its
lib/ccache/symlink directory so ccache skips over it in searches. -
Fix GNU Make to treat
.comas first-class. This would fix it for other programs using the.comtrick (e.g. mpv). (update: 0cb5620)
I'd also likely add ccache-gcc and ccache-g++ command aliases to bin/, so these can be selected as the compiler without having spaces in the name (CC=ccache-gcc CXX=ccache-g++), which breaks some builds.
Beyond this, ccache itself has two required external dependencies, xxhash and zstandard, which it will eagerly download unless configured with -DDEPS=LOCAL. So adding ccache will actually introduce three new dependencies to w64dk.
For a practical demonstration, ccache makes contrib/llama.mak operate like an incremental build (make -f path/to/llama.mak CROSS='ccache '), because its full rebuilds go through the cache and only the changes get compiled. Going through CROSS= is a bit of a hack due to my shortsightedness about hardcoding g++.
Activity
Add ccache to the distribution (#327)
Peter0x44 commentedon Feb 15, 2026
I have no opinion on ccache, other than I don't currently have a need for it and probably won't use it.
But, one thing worth mentioning is that gcc can also use zstd to compress intermediate lto objects. LTO is currently disabled, but it should be used there too, if it ever does get enabled again.
skeeto commentedon Feb 15, 2026
The
ccachebranch is about where I want things to be. It includes the bugfix for GNU Make so that it works properly with Ccache, an unmodified Ccache with all optional dependencies disabled, and opt-inlib/ccachefor compiler masquerading. Everything works well so far. Ponderings:Should there be a new
w64devkit.inito easily opt intolib/ccache?Should I modify Ccache to default to running out of w64devkit? That is, it looks under
w64devkit/forccache.conf, perhaps with a default/empty configuration for better discoverability, and keeps its cache underw64devkit/. On one hand, it's important to purge the cache after upgrading w64devkit, so the cache and installation naturally share a "lifetime" of sorts. It also opens the doors to caching all builds by default, e.g. no explicitlib/ccache/, or at least making it opt-out instead of opt-in. On the other hand this expects a writablew64devkit/, which has never been a requirement, even if it's intended to be per-user (or even per project!) and private, rather than a shared installation.Good point. Two birds with one stone and all that.
I'll take that as a vote for opt-in ccache.
Add ccache to the distribution (#327)
Add ccache to the distribution (#327)
skeeto commentedon Feb 21, 2026
Thanks, @Curculigo, I did not know that. That inclines me more to including it in w64dk.
Add ccache to the distribution (#327)
fixup! Add ccache to the distribution (#327)
skeeto commentedon Feb 22, 2026
I decided on adding "feature" flags to
path type: 278cd9fWhere
+ccacheprepends masqueradingccachecompilers toPATHand usesvar/ccache/as the cache.N-R-K commentedon Feb 22, 2026
And dwarf compression with
-gz=zstdas well. You'd needgdbbuilt with zstd support also for obvious reasons.Add ccache to the distribution (#327)
Add ccache to the distribution (#327)
PNBRQK commentedon Mar 7, 2026
Just want to ask a question for which I don't know proper construction of searching keywords:
Since 'make' tools (e.g. GNU make) also avoid unnecessary recompilation, what's the advantage of ccache over 'make' tools?
Peter0x44 commentedon Mar 7, 2026
ccache is a cache at a level above that. It can check source file contents, headers, etc.
make clean && make && make clean && makewill do two builds, but if you used ccache, it would only do one.That's my understanding.
skeeto commentedon Mar 7, 2026