Skip to content

Avoid absolute paths in fingerprints if they are relative to the workspace root - #17573

Merged
weihanglo merged 2 commits into
rust-lang:masterfrom
ranger-ross:workspace-relative-fingerprint-paths
Oct 9, 2026
Merged

weihanglo merged 2 commits into
rust-lang:masterfrom
ranger-ross:workspace-relative-fingerprint-paths

Conversation

@ranger-ross

Copy link
Copy Markdown
Member

What does this PR try to resolve?

This was inspired by the discussion in #17571.

Currently we use relative paths in the Cargo dep-info file if its in build-dir or the package dir.
Otherwise, we use absolute paths.

I felt that a relatively low hanging fruit to avoid absolute paths was to extend this to workspaces as well.
So that include_str!("../../foo.txt") from foo/src/lib.rs in a workspace can avoid absolute paths.
I feel this is not that uncommon of a usecase and could reduce rebuilds in some scenarios.

The change itself is quiet simple, add a new DepInfoPathType::WorkspaceRootRelative and serialize that with a new value 2 in our depinfo file.
The remainder of the changes is plumbing ws_root through the fingerprint functions to get it to translate_dep_info

How to test and review this PR?

  1. Create a workspace, with a single package in an inner dir with a include_str!("../../foo.txt") and a foo.txt in the workspace root
  2. cargo build
  3. mv the workspace
  4. cargo build (previously would rebuild, but now should avoid a rebuild)

r? @weihanglo

@rustbot rustbot added A-build-execution Area: anything dealing with executing the compiler A-dep-info Area: dep-info, .d files A-rebuild-detection Area: rebuild detection and fingerprinting S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 9, 2026

@weihanglo weihanglo 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.

/// or an absolute path /.../sysroot/...
BuildRootRelative,
/// Relative to the workspace root (but not in the package root)
WorkspaceRootRelative,

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.

I feel this is not that uncommon of a usecase and could reduce rebuilds in some scenarios.

I'd say include_bytes! outside package root is an anti pattern, though it is indeed not uncommon. This does help if the entire workspace is relocated.

@weihanglo
weihanglo enabled auto-merge October 9, 2026 18:17
@weihanglo
weihanglo added this pull request to the merge queue Oct 9, 2026
Merged via the queue into rust-lang:master with commit bf9c2a3 Oct 9, 2026
29 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 9, 2026
opensource-fork-sync Bot pushed a commit to cla7aye15I4nd/opensource-rust-lang__cargo that referenced this pull request Oct 10, 2026
…#17575)

### What does this PR try to resolve?

This is a follow up on rust-lang#17573 to
fix a bug that it introduced.

The gist is that if there is a shared `target-dir` between 2 workspaces
and both workspaces take a path dependency on an external crate that
uses `include!` to a file in one of the workspaces, the relative
workspace path is used in the fingerprint and leads to a stale build.

This is admittedly a mega edge case, but the fix is pretty straight
forward.

:robot: LLM Disclosure: An LLM found this bug and I used it to help me
create the test commit.

### How to test and review this PR?

See the test case

r? @weihanglo
rust-bors Bot pushed a commit to rust-lang/rust that referenced this pull request Oct 14, 2026
Update cargo submodule

14 commits in 29c5daa1afc262323364e039bb70c83372cc702c..3960fa69bb617e3d93c4ddc087c1b32bf12ad907
2026-10-07 22:13:48 +0000 to 2026-10-12 19:29:05 +0000
- refactor: modernize some API usages for 1.99 (rust-lang/cargo#17584)
- Removed some dead workspace tests (rust-lang/cargo#17582)
- Bypass rustup proxy when RUSTUP_TOOLCHAIN is an absolute path (rust-lang/cargo#17562)
- chore: Add an LLM disclosure to the PR template (rust-lang/cargo#17580)
- Restrict workspace-relative dep-info to workspace packages (rust-lang/cargo#17575)
- fix(layout): exclude a build-dir created as a parent from backups (rust-lang/cargo#17560)
- Avoid absolute paths in fingerprints if they are relative to the workspace root (rust-lang/cargo#17573)
- chore(deps): update msrv (3 versions) to v1.97 (rust-lang/cargo#17572)
- fix(job): Allow explicit child process breakaway on Windows (rust-lang/cargo#17527)
- fix(git): Add future-incompat warning in prep for removing auto-detection (rust-lang/cargo#17568)
- fix(config): Don't process includes for `credentials.toml` files (rust-lang/cargo#17569)
- doc(builtin-dep): Document the builtin package ID spec format (rust-lang/cargo#17564)
- test(mock-std): Set stable crate versions to 0.0.0 (rust-lang/cargo#17565)
- Fix: cargo installing from a directory source fails for binary packages with no dependencies. (rust-lang/cargo#17552)

r? ghost
rust-bors Bot pushed a commit to rust-lang/rust that referenced this pull request Oct 14, 2026
Update cargo submodule

14 commits in 29c5daa1afc262323364e039bb70c83372cc702c..3960fa69bb617e3d93c4ddc087c1b32bf12ad907
2026-10-07 22:13:48 +0000 to 2026-10-12 19:29:05 +0000
- refactor: modernize some API usages for 1.99 (rust-lang/cargo#17584)
- Removed some dead workspace tests (rust-lang/cargo#17582)
- Bypass rustup proxy when RUSTUP_TOOLCHAIN is an absolute path (rust-lang/cargo#17562)
- chore: Add an LLM disclosure to the PR template (rust-lang/cargo#17580)
- Restrict workspace-relative dep-info to workspace packages (rust-lang/cargo#17575)
- fix(layout): exclude a build-dir created as a parent from backups (rust-lang/cargo#17560)
- Avoid absolute paths in fingerprints if they are relative to the workspace root (rust-lang/cargo#17573)
- chore(deps): update msrv (3 versions) to v1.97 (rust-lang/cargo#17572)
- fix(job): Allow explicit child process breakaway on Windows (rust-lang/cargo#17527)
- fix(git): Add future-incompat warning in prep for removing auto-detection (rust-lang/cargo#17568)
- fix(config): Don't process includes for `credentials.toml` files (rust-lang/cargo#17569)
- doc(builtin-dep): Document the builtin package ID spec format (rust-lang/cargo#17564)
- test(mock-std): Set stable crate versions to 0.0.0 (rust-lang/cargo#17565)
- Fix: cargo installing from a directory source fails for binary packages with no dependencies. (rust-lang/cargo#17552)

r? ghost
@rustbot rustbot added this to the 1.101.0 milestone Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-build-execution Area: anything dealing with executing the compiler A-dep-info Area: dep-info, .d files A-rebuild-detection Area: rebuild detection and fingerprinting

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants