Skip to content

fix(trim-paths): sanitize absolute source paths in fingerprint - #17556

Merged
Muscraft merged 3 commits into
rust-lang:masterfrom
weihanglo:trim-paths-fingerprint-remap
Nov 13, 2026
Merged

Muscraft merged 3 commits into
rust-lang:masterfrom
weihanglo:trim-paths-fingerprint-remap

Conversation

@weihanglo

Copy link
Copy Markdown
Member

What does this PR try to resolve?

With trim-paths,
rustc only sees remapped source paths.
There is no reason that fingerprint still tracks original paths.

This sanitizes absolute paths in Cargo fingerprint
by applying the same remap rules with trim-paths.

Without this,
moving CARGO_HOME would cause rebuilds,
even the compiled artifacts are byte-identical.

Fixes #10915

How to test and review this PR?

One caveat is that because the "object" scope doesn't remap diagonstics,
if diagnostics were also cached,
a replay may show the "wrong" cached paths.
The "all" scope doesn't have this issue btw.

The cargo_home_moved_trim_paths_object_with_diagnostics test show the caveat.

Also, we might not want this if fingerprint will be obsolete soon in some future blob store design.

🤖 LLM disclosure: I used LLM to update snapshots during the development.

@rustbot rustbot added the A-rebuild-detection Area: rebuild detection and fingerprinting label Oct 7, 2026
@weihanglo
weihanglo force-pushed the trim-paths-fingerprint-remap branch from 92836db to 45b355e Compare October 7, 2026 13:34
@weihanglo

Copy link
Copy Markdown
Member Author

@ranger-ross what do you think about this special case? Fingerprint may be obsolete in some of the blob store proposals, but if it is still relevant we might want this.

@ranger-ross

ranger-ross commented Oct 7, 2026 •

Copy link
Copy Markdown
Member

The changes here seem reasonable to me.

I probably need to give more thought how fingerprinting will be handled in the blob storage and cache.
Thus far, I've completely kept fingerprint (mostly) unchanged and just let cargo write the fingerprint when a cache entry is loaded as if it were just built. (Mtimed just happen to work out since cached deps mtimes are older and ordered by the previous build, but that isn't going to work for remote cache. There is a TODO in the design doc about this)

I think it would be quite difficult to remove fingerprinting until all build units are fully immutable. Part of my wonders if we should make ImmutableUnits a first class citizen in Cargo so we can remove fingerprinting from those while keeping it for the units that still need it. (And ideally make more things immutable overtime)

@weihanglo
weihanglo marked this pull request as ready for review October 14, 2026 04:05
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 14, 2026
@rustbot

rustbot commented Oct 14, 2026

Copy link
Copy Markdown
Collaborator

r? @epage

rustbot has assigned @epage.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @Muscraft, @epage, @weihanglo
  • @Muscraft, @epage, @weihanglo expanded to Muscraft, epage, weihanglo
  • Random selection from Muscraft, epage

@weihanglo weihanglo left a comment •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made it ready, though I am open to just make this under all scope.

View changes since this review

Comment on lines +2296 to +2299
[FRESH] bar v0.0.1
[WARNING] unused variable: `unused`
--> [ROOT]/home/.cargo/registry/src/-[..]/bar-0.0.1/src/lib.rs:1:18
...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Raise the awareness of this:

One caveat is that because the "object" scope doesn't remap diagonstics,
if diagnostics were also cached,
a replay may show the "wrong" cached paths.
The "all" scope doesn't have this issue btw.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth adding a comment pointing out that .cargo is cached and should actually be .cargo-moved but its a trade off we accepted.

Since its not obvious outside of the context of this PR.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated. Thanks.

@weihanglo

Copy link
Copy Markdown
Member Author

r? ranger-ross

Do you want to review this? SHould we go with an FCP? We could also start small only doing this when scope is "all", which doesn't have the cached diagnostic issue.

@rustbot rustbot assigned ranger-ross and unassigned epage Oct 20, 2026

@ranger-ross ranger-ross left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation looks good to me.
Given that fingerprints are meant to be Cargo internal, I am completely fine with changing this. If it wasn't for the stale diagnostics, I'd actual even be in favor of not requiring trim paths for this. (I still might be, I am on the fence)

IMO, trim-paths=object feels like a reasonable starting point and can be later adjusted to all or trim-paths=none based on more feedback.

Happy to wait for feedback from others or start an FCP if you feel it is warranted here.


as a sidenote, the way the caching design appears to be going it seems that fingerprints are likely not going to be stored in the cache, making removing absolute paths from fingerprints non-loadbearing for remote caching.

View changes since this review

Comment on lines +2296 to +2299
[FRESH] bar v0.0.1
[WARNING] unused variable: `unused`
--> [ROOT]/home/.cargo/registry/src/-[..]/bar-0.0.1/src/lib.rs:1:18
...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth adding a comment pointing out that .cargo is cached and should actually be .cargo-moved but its a trade off we accepted.

Since its not obvious outside of the context of this PR.

@weihanglo
weihanglo force-pushed the trim-paths-fingerprint-remap branch from 45b355e to c54cd1c Compare October 21, 2026 13:10
@rustbot

This comment has been minimized.

@weihanglo weihanglo added the T-cargo Team: Cargo label Oct 21, 2026
@weihanglo

Copy link
Copy Markdown
Member Author

@rfcbot fcp merge T-cargo

See the PR description.

The user-facing change is that after moving CARGO_HOME user might get stale diagnostics.

@rust-lang rust-lang deleted a comment from rust-rfcbot Oct 21, 2026
@rust-rfcbot

rust-rfcbot commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator

@weihanglo has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@rust-rfcbot rust-rfcbot added proposed-final-comment-period An FCP proposal has started, but not yet signed off. disposition-merge FCP with intent to merge labels Oct 21, 2026
@epage

epage commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Seems fine.

Moving CARGO_HOME seems like a rare enough thing to be much of an issue. We already have other cases, like short vs full diagnostics.

@weihanglo
weihanglo force-pushed the trim-paths-fingerprint-remap branch from c54cd1c to 877dd8d Compare October 24, 2026 12:17
@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@weihanglo
weihanglo force-pushed the trim-paths-fingerprint-remap branch from 877dd8d to 527cffa Compare October 24, 2026 15:26
@rustbot

This comment has been minimized.

@weihanglo
weihanglo force-pushed the trim-paths-fingerprint-remap branch from 527cffa to f8cbc31 Compare October 28, 2026 20:52
@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

With `trim-paths`,
rustc only sees remapped source paths.
There is no reason that fingerprint still tracks original paths.

This sanitizes absolute paths in Cargo fingerprint
by applying the same remap rules with trim-paths.

Without this,
moving `CARGO_HOME` would cause rebuilds,
even the compiled artifacts are byte-identical.

One caveat is that because the "object" scope doesn't remap diagonstics,
if diagnostics were also cached,
a replay may show the "wrong" cached paths.
The "all" scope doesn't have this issue btw.
@weihanglo
weihanglo force-pushed the trim-paths-fingerprint-remap branch from 31151e0 to d1d8394 Compare November 2, 2026 00:33
@rustbot

rustbot commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@weihanglo weihanglo moved this to FCP merge in Cargo status tracker Nov 3, 2026
@rust-rfcbot rust-rfcbot added final-comment-period FCP — a period for last comments before action is taken and removed proposed-final-comment-period An FCP proposal has started, but not yet signed off. labels Nov 3, 2026
@rust-rfcbot

Copy link
Copy Markdown
Collaborator

🔔 This is now entering its final comment period, as per the review above. 🔔

@rust-rfcbot rust-rfcbot added finished-final-comment-period FCP complete to-announce and removed final-comment-period FCP — a period for last comments before action is taken labels Nov 13, 2026
@rust-rfcbot

Copy link
Copy Markdown
Collaborator

The final comment period, with a disposition to merge, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

@Muscraft
Muscraft added this pull request to the merge queue Nov 13, 2026
Merged via the queue into rust-lang:master with commit 2710fad Nov 13, 2026
30 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 13, 2026
@weihanglo
weihanglo deleted the trim-paths-fingerprint-remap branch November 13, 2026 23:56
rust-bors Bot pushed a commit to rust-lang/rust that referenced this pull request Nov 16, 2026
Update cargo submodule

22 commits in ede6cefea9731cb595942338824c2f9a610b8189..f93c676e3e7ab1aee08dc95d869700f6b99a1a20
2026-11-11 12:33:16 +0000 to 2026-11-15 17:27:10 +0000
- fix(config)!: Clean up ConfigRelativePath (rust-lang/cargo#17742)
- Add support for `annotate-snippets`'s `no-graphics` output format (rust-lang/cargo#17735)
- fix(config)!: Polish the API (rust-lang/cargo#17736)
- chore(deps): update rust crate rusqlite to 0.42.0 (rust-lang/cargo#17723)
- perf(compile)!: Switch dev profile to debug=lines-and-tables-only (rust-lang/cargo#17518)
- test: Add unordered to pub_priv::verify_mix_cargo_feature_z (rust-lang/cargo#17737)
- Reworked output mtime tracking (rust-lang/cargo#17732)
- fix(trim-paths): sanitize absolute source paths in fingerprint (rust-lang/cargo#17556)
- reference: remove implied meaning (rust-lang/cargo#17731)
- chore(deps): update rust crate opener to 0.9.0 (rust-lang/cargo#17722)
- chore(deps): update taiki-e/install-action action to v2.90.3 (rust-lang/cargo#17724)
- chore(deps): update actions/checkout action to v7 (rust-lang/cargo#17725)
- feat(config): Iterate on config.toml's schema (rust-lang/cargo#17714)
- chore(deps): update msrv to v1.100 (rust-lang/cargo#17721)
- chore(deps): update actions/upload-artifact action to v7 (rust-lang/cargo#17726)
- chore(deps): update crate-ci/typos action to v1.52.1 (rust-lang/cargo#17720)
- chore: fix CI errors due to 1.100 (rust-lang/cargo#17719)
- Unified invoked.timestamp location for compilation and build script units (rust-lang/cargo#17718)
- refactor: Misc cleanup while playing with config (rust-lang/cargo#17713)
- feat: OSC 8 link for package name in cargo info (rust-lang/cargo#17710)
- chore: Update annotate-snippets to 0.12.18 (rust-lang/cargo#17712)
- feat(config): Add a generated schema file (rust-lang/cargo#17708)
rust-bors Bot pushed a commit to rust-lang/rust that referenced this pull request Nov 17, 2026
Update cargo submodule

22 commits in ede6cefea9731cb595942338824c2f9a610b8189..f93c676e3e7ab1aee08dc95d869700f6b99a1a20
2026-11-11 12:33:16 +0000 to 2026-11-15 17:27:10 +0000
- fix(config)!: Clean up ConfigRelativePath (rust-lang/cargo#17742)
- Add support for `annotate-snippets`'s `no-graphics` output format (rust-lang/cargo#17735)
- fix(config)!: Polish the API (rust-lang/cargo#17736)
- chore(deps): update rust crate rusqlite to 0.42.0 (rust-lang/cargo#17723)
- perf(compile)!: Switch dev profile to debug=lines-and-tables-only (rust-lang/cargo#17518)
- test: Add unordered to pub_priv::verify_mix_cargo_feature_z (rust-lang/cargo#17737)
- Reworked output mtime tracking (rust-lang/cargo#17732)
- fix(trim-paths): sanitize absolute source paths in fingerprint (rust-lang/cargo#17556)
- reference: remove implied meaning (rust-lang/cargo#17731)
- chore(deps): update rust crate opener to 0.9.0 (rust-lang/cargo#17722)
- chore(deps): update taiki-e/install-action action to v2.90.3 (rust-lang/cargo#17724)
- chore(deps): update actions/checkout action to v7 (rust-lang/cargo#17725)
- feat(config): Iterate on config.toml's schema (rust-lang/cargo#17714)
- chore(deps): update msrv to v1.100 (rust-lang/cargo#17721)
- chore(deps): update actions/upload-artifact action to v7 (rust-lang/cargo#17726)
- chore(deps): update crate-ci/typos action to v1.52.1 (rust-lang/cargo#17720)
- chore: fix CI errors due to 1.100 (rust-lang/cargo#17719)
- Unified invoked.timestamp location for compilation and build script units (rust-lang/cargo#17718)
- refactor: Misc cleanup while playing with config (rust-lang/cargo#17713)
- feat: OSC 8 link for package name in cargo info (rust-lang/cargo#17710)
- chore: Update annotate-snippets to 0.12.18 (rust-lang/cargo#17712)
- feat(config): Add a generated schema file (rust-lang/cargo#17708)
@rustbot rustbot added this to the 1.102.0 milestone Nov 17, 2026
github-actions Bot pushed a commit to rust-lang/stdarch that referenced this pull request Nov 19, 2026
Update cargo submodule

22 commits in ede6cefea9731cb595942338824c2f9a610b8189..f93c676e3e7ab1aee08dc95d869700f6b99a1a20
2026-11-11 12:33:16 +0000 to 2026-11-15 17:27:10 +0000
- fix(config)!: Clean up ConfigRelativePath (rust-lang/cargo#17742)
- Add support for `annotate-snippets`'s `no-graphics` output format (rust-lang/cargo#17735)
- fix(config)!: Polish the API (rust-lang/cargo#17736)
- chore(deps): update rust crate rusqlite to 0.42.0 (rust-lang/cargo#17723)
- perf(compile)!: Switch dev profile to debug=lines-and-tables-only (rust-lang/cargo#17518)
- test: Add unordered to pub_priv::verify_mix_cargo_feature_z (rust-lang/cargo#17737)
- Reworked output mtime tracking (rust-lang/cargo#17732)
- fix(trim-paths): sanitize absolute source paths in fingerprint (rust-lang/cargo#17556)
- reference: remove implied meaning (rust-lang/cargo#17731)
- chore(deps): update rust crate opener to 0.9.0 (rust-lang/cargo#17722)
- chore(deps): update taiki-e/install-action action to v2.90.3 (rust-lang/cargo#17724)
- chore(deps): update actions/checkout action to v7 (rust-lang/cargo#17725)
- feat(config): Iterate on config.toml's schema (rust-lang/cargo#17714)
- chore(deps): update msrv to v1.100 (rust-lang/cargo#17721)
- chore(deps): update actions/upload-artifact action to v7 (rust-lang/cargo#17726)
- chore(deps): update crate-ci/typos action to v1.52.1 (rust-lang/cargo#17720)
- chore: fix CI errors due to 1.100 (rust-lang/cargo#17719)
- Unified invoked.timestamp location for compilation and build script units (rust-lang/cargo#17718)
- refactor: Misc cleanup while playing with config (rust-lang/cargo#17713)
- feat: OSC 8 link for package name in cargo info (rust-lang/cargo#17710)
- chore: Update annotate-snippets to 0.12.18 (rust-lang/cargo#17712)
- feat(config): Add a generated schema file (rust-lang/cargo#17708)
ubiratansoares pushed a commit to ubiratansoares/rust-analyzer that referenced this pull request Nov 19, 2026
Update cargo submodule

22 commits in ede6cefea9731cb595942338824c2f9a610b8189..f93c676e3e7ab1aee08dc95d869700f6b99a1a20
2026-11-11 12:33:16 +0000 to 2026-11-15 17:27:10 +0000
- fix(config)!: Clean up ConfigRelativePath (rust-lang/cargo#17742)
- Add support for `annotate-snippets`'s `no-graphics` output format (rust-lang/cargo#17735)
- fix(config)!: Polish the API (rust-lang/cargo#17736)
- chore(deps): update rust crate rusqlite to 0.42.0 (rust-lang/cargo#17723)
- perf(compile)!: Switch dev profile to debug=lines-and-tables-only (rust-lang/cargo#17518)
- test: Add unordered to pub_priv::verify_mix_cargo_feature_z (rust-lang/cargo#17737)
- Reworked output mtime tracking (rust-lang/cargo#17732)
- fix(trim-paths): sanitize absolute source paths in fingerprint (rust-lang/cargo#17556)
- reference: remove implied meaning (rust-lang/cargo#17731)
- chore(deps): update rust crate opener to 0.9.0 (rust-lang/cargo#17722)
- chore(deps): update taiki-e/install-action action to v2.90.3 (rust-lang/cargo#17724)
- chore(deps): update actions/checkout action to v7 (rust-lang/cargo#17725)
- feat(config): Iterate on config.toml's schema (rust-lang/cargo#17714)
- chore(deps): update msrv to v1.100 (rust-lang/cargo#17721)
- chore(deps): update actions/upload-artifact action to v7 (rust-lang/cargo#17726)
- chore(deps): update crate-ci/typos action to v1.52.1 (rust-lang/cargo#17720)
- chore: fix CI errors due to 1.100 (rust-lang/cargo#17719)
- Unified invoked.timestamp location for compilation and build script units (rust-lang/cargo#17718)
- refactor: Misc cleanup while playing with config (rust-lang/cargo#17713)
- feat: OSC 8 link for package name in cargo info (rust-lang/cargo#17710)
- chore: Update annotate-snippets to 0.12.18 (rust-lang/cargo#17712)
- feat(config): Add a generated schema file (rust-lang/cargo#17708)
github-actions Bot pushed a commit to rust-lang/rustc-dev-guide that referenced this pull request Nov 23, 2026
Update cargo submodule

22 commits in ede6cefea9731cb595942338824c2f9a610b8189..f93c676e3e7ab1aee08dc95d869700f6b99a1a20
2026-11-11 12:33:16 +0000 to 2026-11-15 17:27:10 +0000
- fix(config)!: Clean up ConfigRelativePath (rust-lang/cargo#17742)
- Add support for `annotate-snippets`'s `no-graphics` output format (rust-lang/cargo#17735)
- fix(config)!: Polish the API (rust-lang/cargo#17736)
- chore(deps): update rust crate rusqlite to 0.42.0 (rust-lang/cargo#17723)
- perf(compile)!: Switch dev profile to debug=lines-and-tables-only (rust-lang/cargo#17518)
- test: Add unordered to pub_priv::verify_mix_cargo_feature_z (rust-lang/cargo#17737)
- Reworked output mtime tracking (rust-lang/cargo#17732)
- fix(trim-paths): sanitize absolute source paths in fingerprint (rust-lang/cargo#17556)
- reference: remove implied meaning (rust-lang/cargo#17731)
- chore(deps): update rust crate opener to 0.9.0 (rust-lang/cargo#17722)
- chore(deps): update taiki-e/install-action action to v2.90.3 (rust-lang/cargo#17724)
- chore(deps): update actions/checkout action to v7 (rust-lang/cargo#17725)
- feat(config): Iterate on config.toml's schema (rust-lang/cargo#17714)
- chore(deps): update msrv to v1.100 (rust-lang/cargo#17721)
- chore(deps): update actions/upload-artifact action to v7 (rust-lang/cargo#17726)
- chore(deps): update crate-ci/typos action to v1.52.1 (rust-lang/cargo#17720)
- chore: fix CI errors due to 1.100 (rust-lang/cargo#17719)
- Unified invoked.timestamp location for compilation and build script units (rust-lang/cargo#17718)
- refactor: Misc cleanup while playing with config (rust-lang/cargo#17713)
- feat: OSC 8 link for package name in cargo info (rust-lang/cargo#17710)
- chore: Update annotate-snippets to 0.12.18 (rust-lang/cargo#17712)
- feat(config): Add a generated schema file (rust-lang/cargo#17708)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-rebuild-detection Area: rebuild detection and fingerprinting disposition-merge FCP with intent to merge finished-final-comment-period FCP complete T-cargo Team: Cargo to-announce

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Moving CARGO_HOME invalidates target caches

6 participants