Cargo home avoids dependency setup
Registry archives, registry metadata, and bare Git databases can restore without treating expanded sources as portable build output.
Getting started
Guides
Docs / Adapter commands / Cargo
Restore Cargo state, reuse compiler results through sccache, run the build, and publish successful work with one command.
Registry archives, registry metadata, and bare Git databases can restore without treating expanded sources as portable build output.
A target snapshot carries fingerprints, build-script output, and artifacts when its transfer cost is justified.
When Cargo still invokes rustc, sccache can reuse matching compiler results without sharing one locked target directory across worktrees.
Prerelease CLI builds prune Cargo targets with a default budget of 40 GiB after supported commands when neither stdout nor stderr is a terminal, including read-only runs and --skip-save. Terminal commands inherit their streams and skip observation, preserving progress, colors and interactive programs. Unobserved commands invalidate existing usage evidence. Automatic pruning is intended for CI and other non-interactive runs. A terminal-only workflow does not produce usable evidence for standalone pruning; local scripts with both output streams redirected can record usage. Override target-budget under [adapters.cargo] or --target-budget on the command line. The CLI observes the original command without replaying it. Active outputs, unknown files, and groups without unchanged usage evidence are preserved even when they exceed the budget. Run boringcache prune cargo --target-dir target --dry-run to preview cleanup from recorded usage, or omit --dry-run to apply it; --json reports exact byte counts. Pruning works offline without a service connection. Flags override project settings, which override the CLI default; a budget of 0 disables pruning. Command-line overrides apply only to that invocation. GB and GiB both use binary bytes, matching other cache size settings. TB and TiB are not accepted; use GiB for larger budgets. Use the same explicit --target-scope ID on consecutive wrapped commands to protect their combined outputs. CI job IDs do not affect retention. Nested or overlapping commands run without pruning. Waiting for the pruning record lock is limited to 30 seconds; if a large or slow pruning pass holds it longer, the waiting command fails before launch. Groups containing symlinks, and incremental/ when enabled, remain protected; other recognized groups can still be pruned. If descendants keep output open after exit, forwarding stops after five seconds, the command result is preserved and pruning is skipped. Custom aliases, plugins, doc tests, clippy --fix, failed commands, and incomplete observations do not authorize deletion. Bare Cargo commands between --phase restore and --phase save are not observed, so those phases do not automatically prune. Previously unrecorded outputs remain protected until a wrapped command observes them.
Choose the cache layers for the job. Keep the compiler-cache tag and these profiles in .boringcache.toml, then use boringcache cargo --profile cargo-deps --skip-save check --locked for repeated checks. It restores Cargo home and uses sccache while keeping each worktree's target local. Use the cargo-target profile only for a deliberate checkpoint. Fresh runners can use boringcache cargo build --release --locked when moving target state is faster than rebuilding it.
[adapters.sccache] tag = "rust-main" [profiles.cargo-deps] entries = [ "cargo-registry-cache", "cargo-registry-index", "cargo-git-db" ] [profiles.cargo-target] entries = ["cargo-target"]
boringcache onboard once, then commit the cargo-deps and cargo-target profiles. New CLI releases add both during onboarding.
boringcache cargo --profile cargo-deps --skip-save check --locked; target stays local while sccache remains writable when the credential permits it.
boringcache cargo --profile cargo-target --skip-restore check --locked --all-targets.
boringcache cargo build, boringcache cargo nextest run, or the complete [adapters.cargo] command when target transport is worth its restore and publication cost.
CLI 1.32.0 adds optional local target snapshots. Enable them in .boringcache.toml to restore an empty target in another worktree of the same Git repository. Each worktree gets independent files or filesystem clones and keeps its own writable target.
[adapters.cargo.local-target-cache] enabled = true max-size = "20GiB"
The default is off. The selected profile must include cargo-target; the cargo-deps profile does not use target snapshots. Worktrees must use the same target tag and exclusions. Existing populated targets are kept.
Local snapshots need no remote credential. A successful build in a clean checkout can capture a snapshot; dirty checkouts do not publish one. The default disk budget is 20 GiB of logical file bytes, with least-recently-restored snapshots removed when space is needed.
Run boringcache cargo --profile cargo-target build --locked in the original checkout, then in an empty worktree. The CLI reports capture or restore; Cargo decides which outputs are still fresh. An oversized or busy target is skipped with a reason.
With CLI and Action 1.31.0 or later, omit [adapters.cargo].command to restore in this step and publish after the job. Run ordinary Cargo commands in later steps. A committed command runs the complete lifecycle in the Action step. Use only one Cargo Action step per job.
- uses: boringcache/one@f0fb9b2d926a32b10c543e92093ba00c5a291b79 # v1.33.0 with: trust-policy: auto mode: cargo - run: cargo test --locked
Approve the repository through Connect CI and grant the job contents: read and id-token: write. The Action uses that Machine connection. Pull requests restore by default; trusted jobs may publish. See the authentication example in the GitHub Actions reference for scoped credentials when OIDC is unavailable.
CLI 1.31.0 or later can restore before a job's Cargo commands and save afterward. A phase runs no Cargo command and ignores [adapters.cargo].command. It cannot be combined with a command, --skip-restore, or --skip-save.
boringcache cargo --phase restore cargo check --locked cargo test --locked boringcache cargo --phase save
In GitHub Actions, omit [adapters.cargo].command and use one mode: cargo step before ordinary Cargo steps. BoringCache One restores in its main step, exports the cache environment, and publishes in its post step. A committed command keeps the complete lifecycle inside the Action step.
Choose save: always to publish the state a job reached after a failed step, or save: never to disable publication. The default is save: on-success. Trust policy, credentials, and the dirty-checkout rule still apply. A failed command embedded in the repo plan does not publish through the post step.
Direct CLI phases transfer archives only; they do not start the compiler-cache proxy. Use the wrapped command or the Action when you also need sccache setup.
Deno · shared compiler-cache hits. Proteus · Cargo + sccache.
95.8%
1,333 of 1,391 compiler requests hit the shared cache in a Deno build.
Open run →47
The public catalog includes Go build cache, sccache, and Rust target cache mounts inside Docker builds.
Open run →Proteus Cargo + sccache run
Open run →Check the tool's own reference when you need cache-key rules, build settings, or version-specific behavior.
Compare every supported command, protocol, and Action mode in one place.
Adapter command index →Need help or found something unclear? Open an issue or browse the CLI repo.
We use cookies to understand how people use BoringCache. Learn more