Skip to content

[3/9] feat: strip basedirs from Rust hash key for cross-machine cache hits#10

Open
mmastrac wants to merge 1 commit intovercel/crate-type-allow-hashfrom
vercel/rust-basedirs
Open

[3/9] feat: strip basedirs from Rust hash key for cross-machine cache hits#10
mmastrac wants to merge 1 commit intovercel/crate-type-allow-hashfrom
vercel/rust-basedirs

Conversation

@mmastrac
Copy link
Copy Markdown
Collaborator

@mmastrac mmastrac commented Apr 2, 2026

Summary

  • Adds SCCACHE_BASEDIRS support to the Rust compiler hash key, matching the existing C compiler behavior
  • Strips basedir prefixes from cwd, CARGO_MANIFEST_DIR, CARGO_MANIFEST_PATH, CARGO_WORKSPACE_DIR, CARGO_TARGET_TMPDIR, CARGO_BIN_EXE_*, dep-info env var values, and the concatenated argument string (catches --remap-path-prefix, -Clinker=, etc.)
  • Enables cache hits when the same crate is compiled from different absolute paths on different machines
  • Addresses mozilla/sccache#2652

Test plan

  • test_basedirs_strips_cwd_and_cargo_manifest_dir — verifies basedirs changes the hash
  • test_basedirs_deterministic — verifies same basedir produces same hash
  • test_generate_hash_key — existing test updated for new hash format
  • All 37 Rust compiler tests pass
  • cargo clippy clean

🤖 Generated with Claude Code

@mmastrac mmastrac force-pushed the vercel/rust-basedirs branch 2 times, most recently from 3f6f57a to b1f2c15 Compare April 7, 2026 18:24
Comment thread src/compiler/rust.rs Outdated
Comment thread src/compiler/rust.rs Outdated
@sylvestre
Copy link
Copy Markdown

it also needs an integration / high level test, thanks

@mmastrac
Copy link
Copy Markdown
Collaborator Author

@sylvestre I hadn't considered this one ready to land yet but I can definitely turn this into a proper patch (it's currently a very sloppy AI patch as-is, just good enough for what we needed).

@mmastrac mmastrac force-pushed the vercel/rust-basedirs branch from b1f2c15 to 3031523 Compare April 16, 2026 21:35
@mmastrac mmastrac force-pushed the vercel/crate-type-allow-hash branch from a1ea5d5 to 9c26759 Compare April 16, 2026 21:35
@mmastrac mmastrac force-pushed the vercel/rust-basedirs branch from 3031523 to 9bd1db6 Compare April 17, 2026 14:44
@mmastrac mmastrac force-pushed the vercel/crate-type-allow-hash branch from 9c26759 to 6026566 Compare April 17, 2026 14:44
@mmastrac mmastrac force-pushed the vercel/rust-basedirs branch from 9bd1db6 to 2049b88 Compare April 17, 2026 15:08
@mmastrac mmastrac force-pushed the vercel/crate-type-allow-hash branch from 6026566 to 0ba527a Compare April 17, 2026 15:09
@mmastrac mmastrac force-pushed the vercel/rust-basedirs branch 7 times, most recently from 36ef3bf to 97e9f34 Compare April 17, 2026 20:18
@mmastrac
Copy link
Copy Markdown
Collaborator Author

@sylvestre I've upstreamed this as mozilla#2678 with your suggestions and a lot of cleanup

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 vercel/rust-basedirs branch from 97e9f34 to 8c030d5 Compare April 17, 2026 20:51
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.

2 participants