Skip to content

Add sccache (local disk backend) to the CI cache action#15147

Closed
reaperhulk wants to merge 8 commits into
mainfrom
claude/sccache-gha-caching-lfk8qj
Closed

Add sccache (local disk backend) to the CI cache action#15147
reaperhulk wants to merge 8 commits into
mainfrom
claude/sccache-gha-caching-lfk8qj

Conversation

@reaperhulk

Copy link
Copy Markdown
Member

Adds compiler-level caching via sccache to the shared CI cache composite action, layered on top of the existing Swatinem/rust-cache. The two cover complementary gaps:

  • rust-cache (unchanged) remains the fast path: warm target/, cargo registry, git deps.
  • sccache recovers the two cases rust-cache structurally can't: Cargo.lock bumps (full rust-cache key miss, e.g. every Dependabot update) and the workspace crates rust-cache deliberately prunes from every saved cache.

Design notes:

  • sccache uses its local disk backend, persisted as one actions/cache entry per job — measured ~30–40 MB per cold build flavor (entries are internally compressed). This adds exactly one cache restore and at most one save per job, so no per-object GHA cache API traffic and no rate-limit exposure, unlike SCCACHE_GHA_ENABLED.
  • The entry key is sccache-{rustc host triple + version}-{existing job key}-{Cargo.lock hash} with a restore-keys prefix fallback so entries carry across lockfile changes — exactly the moment rust-cache goes cold. Since sccache hashes its real inputs (compiler digest, args, env), a stale entry can only miss, never produce a wrong object.
  • Fail-open everywhere: the installer step is gated to X64/ARM64 (no prebuilt binaries elsewhere, e.g. the ppc64le distro job) and continue-on-error; the wrapper is only enabled after a runtime command -v sccache check. Jobs without sccache behave exactly as today.
  • SCCACHE_CACHE_SIZE=512M bounds accretion from restore-keys chains.

Expected quota impact: ≤2 GB across the whole matrix, well within the 10 GB free allowance. The sccache-action's post-job hook prints hit/miss stats in each job's logs for verification.

🤖 Generated with Claude Code

https://claude.ai/code/session_01WYvs2Ppi5y2moJF5uoWbvr


Generated by Claude Code

claude added 6 commits July 3, 2026 18:51
…warm

PEP 517 build isolation creates a temporary virtualenv with a randomized
path for every build, so PYO3_PYTHON changes on each install. Our
cryptography-cffi build script registers
rerun-if-env-changed=PYO3_PYTHON, so cryptography-cffi and
cryptography-rust recompiled on every CI job even with a fully warm
Swatinem/rust-cache (and on free-threaded builds the pyo3 crates
recompiled too, since the non-abi3 interpreter config also embeds the
ephemeral path). See PyO3/pyo3#6113

Install the build requirements into the session venv and pass
--no-build-isolation instead: the build backend then runs from the
stable .nox/<session> interpreter, making the cargo fingerprints stable
across CI runs. Verified locally: with isolation every reinstall
recompiles the crates (~30s); without it a warm-cache reinstall
compiles nothing.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Lj3BsMN8xmPQQ89d6nzDcZ
rust-cache skips saving on an exact key hit, so without a roll the
caches would keep the fingerprints recorded from isolated builds and
every job would keep rebuilding once per run.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Lj3BsMN8xmPQQ89d6nzDcZ
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Lj3BsMN8xmPQQ89d6nzDcZ
Compiler-level caching to recover the cases Swatinem/rust-cache can't:
Cargo.lock bumps (full rust-cache miss) and the workspace crates that
rust-cache deliberately prunes from every saved cache.

sccache runs with its local disk backend, persisted as a single
actions/cache entry per job (~30-40 MB measured for a cold build), so
it adds exactly one cache restore and at most one save per job -- no
per-object GHA cache API traffic, no rate-limit exposure. The entry key
includes the rustc host triple + version and the existing job key; a
restore-keys prefix lets an entry carry over across lockfile changes.

Jobs on architectures without prebuilt sccache binaries (and the
sccache-action failing for any reason) degrade to today's behavior:
the wrapper is only enabled if the binary is actually present.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WYvs2Ppi5y2moJF5uoWbvr
@reaperhulk reaperhulk force-pushed the claude/sccache-gha-caching-lfk8qj branch from 43106ef to ea91da8 Compare July 3, 2026 22:35
…84' into claude/sccache-gha-caching-lfk8qj

# Conflicts:
#	.github/actions/cache/action.yml
@reaperhulk reaperhulk force-pushed the claude/sccache-gha-caching-lfk8qj branch from 8ef1298 to d6036ab Compare July 4, 2026 00:49
llvm-cov emits warnings to stderr, which session.run(silent=True)
captures into the same string as stdout, so any warning ends up
written into the .lcov file and crashes merge_rust_coverage.py's
strict parser.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WYvs2Ppi5y2moJF5uoWbvr
@reaperhulk reaperhulk force-pushed the claude/sccache-gha-caching-lfk8qj branch from db5c413 to 67a29a7 Compare July 4, 2026 01:40
@reaperhulk reaperhulk closed this Jul 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants