Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

sccache

sccache caches compiled artifacts across builds, significantly reducing incremental and clean build times.

Installation

cargo install sccache

Or via Homebrew on macOS:

brew install sccache

Configuration

Set the Rust compiler wrapper in ~/.cargo/config.toml:

[build]
rustc-wrapper = "sccache"

Alternatively, export the environment variable:

export RUSTC_WRAPPER=sccache

Verify

After building the project, check cache statistics:

sccache --show-stats

CI Usage

In GitHub Actions, add sccache before cargo build:

- name: Install sccache
  uses: mozilla-actions/sccache-action@v0.0.9

- name: Build
  run: cargo build --workspace
  env:
    RUSTC_WRAPPER: sccache
    SCCACHE_GHA_ENABLED: "true"

Storage Backends

By default sccache uses a local disk cache at ~/.cache/sccache. For shared caches across CI runners, configure a remote backend:

BackendEnv VariableExample
S3SCCACHE_BUCKETmy-sccache-bucket
GCSSCCACHE_GCS_BUCKETmy-sccache-bucket
RedisSCCACHE_REDISredis://localhost

See the sccache documentation for full configuration options.