Skip to content

feat: strip basedirs from Rust hash key for cross-machine cache hits - #2678

Open
mmastrac wants to merge 1 commit into
mozilla:mainfrom
vercel:upstream-pr/rust-basedirs
Open

feat: strip basedirs from Rust hash key for cross-machine cache hits#2678
mmastrac wants to merge 1 commit into
mozilla:mainfrom
vercel:upstream-pr/rust-basedirs

Conversation

@mmastrac

@mmastrac mmastrac commented Apr 17, 2026

Copy link
Copy Markdown
Contributor

SCCACHE_BASEDIRS now normalizes cwd, CARGO_MANIFEST_DIR, CARGO_WORKSPACE_DIR, CARGO_TARGET_TMPDIR, CARGO_MANIFEST_PATH, CARGO_BIN_EXE_*, dep-info env var values, and the concatenated argument string in the Rust compiler's hash key computation. This enables cache hits when the same crate is compiled from different absolute paths on different machines (e.g., CI runners with different checkout roots).

This handles arguments that contain absolute paths at non-terminal positions, such as -Clink-arg=blah,/path/to/something or (the nightly-only?) --remap-path-prefix=/full/path=/new.

Added a number of unit tests around the functionality, as well as an integration test where we compile a crate from two different directories.

This fixes #2652

SCCACHE_BASEDIRS now normalizes cwd, CARGO_MANIFEST_DIR,
CARGO_WORKSPACE_DIR, CARGO_TARGET_TMPDIR, CARGO_MANIFEST_PATH,
CARGO_BIN_EXE_*, dep-info env var values, and the concatenated
argument string in the Rust compiler's hash key computation. This
enables cache hits when the same crate is compiled from different
absolute paths on different machines (e.g., CI runners with
different checkout roots).

strip_basedir_prefix now also matches when the value equals the
basedir minus its trailing '/', so `cwd == basedir` strips to the
empty string rather than passing through. Without this, two
machines with different checkout paths produced different hashes
even with matching basedirs -- the feature's central claim.
@mmastrac
mmastrac force-pushed the upstream-pr/rust-basedirs branch from a937ddb to 3845d98 Compare April 17, 2026 20:52
@codecov-commenter

codecov-commenter commented Apr 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.39450% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.57%. Comparing base (d11e2e0) to head (3845d98).
⚠️ Report is 64 commits behind head on main.

Files with missing lines Patch % Lines
src/compiler/rust.rs 99.10% 3 Missing ⚠️
tests/helpers/mod.rs 70.00% 3 Missing ⚠️
tests/sccache_cargo.rs 98.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2678      +/-   ##
==========================================
+ Coverage   74.17%   74.57%   +0.39%     
==========================================
  Files          70       65       -5     
  Lines       39207    36425    -2782     
==========================================
- Hits        29083    27163    -1920     
+ Misses      10124     9262     -862     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cdbattags

Copy link
Copy Markdown

Hi folks, any reason this can't go in yet? Needing the same myself!

@sylvestre

Copy link
Copy Markdown
Collaborator

because most of the jobs fails

@cdbattags

Copy link
Copy Markdown

@sylvestre - Oops, roger that, I'll start on a fork and try to clean up the PR!

@mmastrac - Any more updates to the Vercel fork since April that should ride along?

cdbattags added a commit to anneal-it/sccache that referenced this pull request Aug 6, 2026
…w (sccache#2595)

PR mozilla#2678 wired basedirs into the Rust hash key, but only from the daemon's
startup config (storage.basedirs()). A long-lived server cannot know about git
worktrees created after it started, so cross-checkout Rust hits required
restarting the server whenever the worktree set changed — the exact pain
sccache#2595 describes.

Read SCCACHE_BASEDIRS from THIS compile's environment (each worktree sets its
own root via cargo `[env]`) when present, falling back to the server's config
basedirs. Each build now strips its own root per-request: no server-startup
staleness, no restarts, parallel-safe across worktrees. Works in both the
default and client-side compile paths (the daemon hashes either way and reads
the per-request env).

- config.rs: extract split_basedirs + normalize_basedirs (shared, so config
  parsing and the hasher produce byte-identical basedirs).
- compiler/rust.rs: generate_hash_key prefers per-compile env basedirs.
- tests/sccache_cargo.rs: add test_rust_cargo_basedirs_per_compile_env_cross_dir_cache_hit
  — the sccache server is started with NO basedirs; the per-compile env alone
  drives the cross-directory cache hit (fails before this change).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wire SCCACHE_BASEDIRS into Rust hash key

4 participants