rust: normalize cache keys with SCCACHE_BASEDIRS - #2813
Draft
tcashel wants to merge 1 commit into
Draft
Conversation
tcashel
force-pushed
the
codex/rust-basedirs
branch
from
August 18, 2026 18:29
a07fe96 to
535a584
Compare
tcashel
force-pushed
the
codex/rust-basedirs
branch
from
August 18, 2026 20:17
535a584 to
9d3317f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi! I use
ccacheheavily for C and C++ projects, and I have been tryingsccachefor my Rust builds.Problem
I often have several coding agents build the same Rust commit from separate Git worktrees. Because each worktree has a different absolute path, sccache treats the builds as different, repeats the compilation, and creates duplicate cache entries.
Change
This PR makes Rust cache keys honor configured
SCCACHE_BASEDIRS. Matching paths are hashed relative to the longest configured root. Nonmatching paths keep their current behavior.For example, a daemon configured with
/work/projectand/tmp/project-worktreecan reuse a Rust artifact between those checkouts when their inputs match.The matcher checks each configured root without allocating. The change also bumps the Rust cache-key version from 6 to 7 so the new framing cannot collide with older keys.
Follow-up draft #2814 makes
SCCACHE_BASEDIRSrequest-scoped so one daemon can serve new worktrees without restarting. It is one commit on top of this branch; view the follow-up-only diff.Validation
The locked unit and integration suites, clippy, rustfmt, and Taplo pass on Apple silicon. The Cargo integration test builds the same crate under two roots, observes a cache hit, and verifies that a source change misses.
I ran the repository benchmark suite on Apple silicon.
cache_key_generationhad a 31.41 µs median on bothmainand this branch. The new matcher took 0.208 µs for 100 lookups with one configured root and 4.33 µs with 32 roots.Compatibility and limits
This behavior is opt-in. It changes cache keys, not paths embedded in artifacts. If code embeds
CARGO_MANIFEST_DIR, a cache hit can contain the path from the compilation that populated the cache. Use rustc path remapping when that embedded path must match the current checkout.On Windows, matching accounts for ASCII case and separator differences. Non-ASCII path values remain unchanged.
This draft is an alternative to PR #2678 and PR #2794, and relates to issue #2595.
I used OpenAI Codex (
gpt-5.6-sol, ultra reasoning) during implementation, testing, benchmarking, and review. I'll review the full diff and CI results myself before marking the PR ready.