LinuxCommandLibrary

sccache

Cache compilations for faster builds

TLDR

Show compilation statistics

$ sccache [[-s|--show-stats]]
copy

Run gcc (or any compiler command) through sccache
$ sccache gcc [path/to/file.c]
copy

Start sccache server in the foreground and print logs
$ sccache --stop-server; SCCACHE_LOG=trace SCCACHE_START_SERVER=1 SCCACHE_NO_DAEMON=1 sccache
copy

Ask scheduler for distributed compilation status
$ sccache --dist-status
copy

SYNOPSIS

sccache is typically used as a compiler wrapper by setting environment variables or configuring build systems:
export RUSTC_WRAPPER=sccache
export CC=sccache CXX=sccache

For direct command-line operations and cache management:
sccache [OPTIONS] [COMMAND [ARG...]]
sccache --show-stats
sccache --zero-stats
sccache --start-server
sccache --stop-server
sccache --wipe

PARAMETERS

--help
    Displays the command's help message and available options.

--version
    Prints the sccache version information.

--show-stats
    Shows detailed statistics about cache hits, misses, size, and compilation times.

--zero-stats
    Resets all collected cache statistics to zero.

--start-server
    Starts the sccache daemon in the background to manage the cache efficiently.

--stop-server
    Sends a signal to stop the running sccache server daemon.

--kill-server
    Forcefully terminates the sccache server daemon process.

--purge
    Clears the entire sccache cache, removing all stored compilation results.

--clean
    Removes older, less frequently accessed cache entries to free up disk space.

--cache-dir
    Prints the path to the directory where sccache stores its cache files.

--stats-json
    Displays cache statistics in a machine-readable JSON format.

--log-level <LEVEL>
    Sets the verbosity level for logging messages (e.g., debug, info, warn, error).

DESCRIPTION

sccache is a high-performance compiler wrapper and caching tool, similar to ccache, developed by Mozilla. It significantly accelerates build times for projects written in languages like C/C++, Rust, Go, and D by caching compilation results.

When sccache is used in place of the actual compiler, it first calculates a hash of the compiler inputs (source code, arguments, environment variables). It then checks its cache for a matching result. If a hit is found, the cached output is retrieved, significantly reducing a full recompile. If a miss occurs, sccache invokes the real compiler, stores the new compilation result in its cache, and then returns it.

sccache supports various cache backends, including local disk, Amazon S3, Google Cloud Storage, and Azure Blob Storage, making it highly versatile for both local development and large-scale continuous integration (CI/CD) environments. It can operate as a persistent server daemon for optimal performance and shared caching.

CAVEATS

For optimal performance, sccache typically requires a persistent server daemon to be running. While robust, complex or non-standard compiler invocation patterns might require specific configuration or workarounds. Changes in compiler versions or environment variables not fully captured by its hashing mechanism could potentially lead to cache misses or, in rare cases, stale cache entries.

ENVIRONMENT VARIABLE CONFIGURATION

sccache relies heavily on environment variables for configuration. Examples include SCCACHE_DIR for cache location, SCCACHE_CACHE_SIZE for cache size limits, and specific variables like SCCACHE_S3_BUCKET, SCCACHE_GCS_BUCKET, or SCCACHE_AZURE_BLOB_CONTAINER for configuring cloud storage backends. These variables allow granular control over cache behavior and seamless integration with various storage solutions.

SERVER MODE OPERATION

For maximum efficiency, sccache should be run as a background server using sccache --start-server. This daemon manages the cache, handles concurrent compilation requests, and significantly reduces the overhead of starting a new sccache process for every compilation. Client processes then communicate with this central server, leveraging shared cache resources for faster builds.

SUPPORTED LANGUAGES AND COMPILERS

sccache is designed to work with various compiler toolchains, including GCC and Clang for C/C++, rustc for Rust, go build for Go, and dmd for D. Its flexible design allows it to be integrated into diverse build environments and projects across different programming languages, making it a versatile tool for build acceleration.

HISTORY

sccache was initially developed by Mozilla, written in Rust, to address the growing need for faster build times, particularly for large projects like Firefox and its extensive Rust codebase. It emerged as a modern alternative to existing compiler caches like ccache, offering enhanced performance, support for Rust's compiler (rustc), and versatile cloud-based storage backend options. Its design prioritized reliability and efficiency in continuous integration (CI/CD) pipelines, leading to its widespread adoption beyond its original Mozilla context.

SEE ALSO

ccache(1), distcc(1), make(1), ninja(1)

Copied to clipboard