Skip to content

rust: exclude CARGO_TARGET_DIR and CARGO_BUILD_* from the hash key - #3050

Merged
sylvestre merged 1 commit into
mozilla:mainfrom
art-shen:cargo-settings-out-of-key
Nov 20, 2026
Merged

sylvestre merged 1 commit into
mozilla:mainfrom
art-shen:cargo-settings-out-of-key

Conversation

@art-shen

@art-shen art-shen commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Problem: when CARGO_TARGET_DIR differs between checkouts of a project, for example one target dir per git worktree, every crate misses the cache, even with basedirs covering all the checkouts. sccache puts every CARGO_* env var except a few into the key, and CARGO_TARGET_DIR is one of them. CARGO_BUILD_* vars, e.g. CARGO_BUILD_BUILD_DIR, have the same effect.

Change: leave CARGO_TARGET_DIR and CARGO_BUILD_* out of the key, like CARGO_BUILD_JOBS already is.

These vars configure Cargo. What they change for rustc reaches it as arguments (--target, -C incremental, rustflags), and arguments are hashed. A crate that reads one with env! still gets the value hashed through dep-info.

test_generate_hash_key now also sets CARGO_TARGET_DIR and CARGO_BUILD_BUILD_DIR.

Tests: cargo test --locked --lib --bins --tests. Locally, cache_hit_rate and two sccache_cargo tests (proc_macro_in_another_target_dir, incremental_allowed_deps_cached) fail on main too.

@art-shen art-shen changed the title rust: leave CARGO_TARGET_DIR and CARGO_BUILD_* out of the hash key rust: exclude CARGO_TARGET_DIR and CARGO_BUILD_* from the hash key Nov 19, 2026
They configure Cargo; what they change for rustc arrives as hashed arguments. Hashing them gave each target directory its own cache.
@art-shen
art-shen force-pushed the cargo-settings-out-of-key branch from 7eb9933 to 03eba07 Compare November 20, 2026 00:07
@codecov-commenter

codecov-commenter commented Nov 20, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.96%. Comparing base (033912e) to head (03eba07).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3050      +/-   ##
==========================================
- Coverage   78.97%   78.96%   -0.02%     
==========================================
  Files          75       75              
  Lines       46130    46159      +29     
==========================================
+ Hits        36433    36449      +16     
- Misses       9697     9710      +13     

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

@sylvestre
sylvestre merged commit 0337735 into mozilla:main Nov 20, 2026
51 checks passed
@sylvestre

Copy link
Copy Markdown
Collaborator

Thanks for your PR

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.

3 participants