Skip to content

Rust

Rust CI on GitHub Actions

Cargo rebuilds the entire dependency graph on almost every CI run.

12m → 4m
Cold build
12m → 45s
Warm build
94%
Cache hit rate

Cargo rebuilds the entire dependency graph on almost every CI run.

Why it happens

target/ is not cached, or the cache key changes whenever any source file changes, so incremental state is thrown away each run.

What to change

  1. Cache ~/.cargo/registry, ~/.cargo/git and target/ keyed on Cargo.lock rather than on source files
  2. Use sccache so even a cold target/ reuses compiled artefacts across branches
  3. Split cargo check, cargo clippy and cargo test into parallel jobs sharing one cache
  4. Build release artefacts on a 16 vCPU runner — rustc scales close to linearly with codegen units

Rust on runnerhut

yaml
jobs:
test:
runs-on: runnerhut-16vcpu-ubuntu-2404
steps:
- uses: actions/checkout@v4
- uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: cargo-${{ hashFiles('**/Cargo.lock') }}
- run: cargo test --all-features
A working starting point

The only runnerhut-specific line is `runs-on: runnerhut-16vcpu-ubuntu-2404`. Everything else is standard GitHub Actions — the same actions, the same secrets and the same permissions model you use today.

Your next build could be twice as fast, at half the price

Start free. Migrating away is the same one line, and we publish that diff too.