Skip to content
Latchkey

sccache: A Shared Compiler Cache

sccache wraps the compiler like ccache but can store its cache locally, in cloud object storage, or in Redis.

sccache is Mozilla's compiler cache. It covers C, C++, Rust, and CUDA and shines when you want a shared cache backend (S3, GCS, Redis, GitHub Actions cache) instead of a per-runner directory.

What it does

sccache runs as a background server that the compiler wrapper talks to; it hashes inputs and serves cache hits from the configured backend. You wire it in by prefixing the compiler (sccache gcc) or via build-system launcher variables, the same way as ccache, but the storage backend is pluggable.

Common usage

Terminal
export RUSTC_WRAPPER=sccache              # for Rust
export CC="sccache gcc" CXX="sccache g++" # for C/C++
# CMake launcher
cmake -B build -DCMAKE_C_COMPILER_LAUNCHER=sccache \
  -DCMAKE_CXX_COMPILER_LAUNCHER=sccache
sccache --start-server                    # start the server explicitly

Options

Mechanism / VarWhat it does
sccache gcc / sccache g++Prefix the compiler invocation
CMAKE_<LANG>_COMPILER_LAUNCHERCMake hook to run sccache
RUSTC_WRAPPERUse sccache for cargo/rustc
SCCACHE_DIRLocal disk cache directory backend
SCCACHE_CACHE_SIZEMaximum local cache size

In CI

For C/C++ use the launcher variables so reconfigures keep caching. Pick a backend that matches your runners: a persisted SCCACHE_DIR for single-runner setups, or a shared backend (S3/GHA cache) when many jobs should share results. Always print sccache --show-stats after the build to confirm hits.

Common errors in CI

"sccache: error: Server startup failed" often means a stale server or a port conflict; stop it with sccache --stop-server and retry. "error: failed to execute compile" with a wrapper that cannot find the compiler means CC points at sccache but the real compiler is not on PATH. If everything misses, the backend is not configured or not reachable.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →