Skip to content

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

Open
mmastrac wants to merge 1 commit intomozilla: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 intomozilla:mainfrom
vercel:upstream-pr/rust-basedirs

Conversation

@mmastrac
Copy link
Copy Markdown

@mmastrac mmastrac commented Apr 17, 2026

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
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

1 participant