Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not hash absolute sysroot path into stdlib crates metadata. #14951

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/cargo/core/compiler/build_runner/compilation_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -604,11 +604,20 @@ fn compute_metadata(

METADATA_VERSION.hash(&mut shared_hasher);

let ws_root = if unit.is_std {
// SourceId for stdlib crates is an absolute path inside the sysroot.
// Pass the sysroot as workspace root so that we hash a relative path.
// This avoids the metadata hash changing depending on where the user installed rustc.
&bcx.target_data.get_info(unit.kind).unwrap().sysroot
Copy link
Member

Choose a reason for hiding this comment

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

Just a note for future self: sysroot is something like
/home/user/.rustup/toolchains/nightly-aarch64-apple-darwin

It is not the real workspace root path of the standard library.
While this seems a bit out of sync, the relative path inside sysroot should be fairly deterministic. It's fine now and I don't think we need any hardcoded path logic like this.

} else {
bcx.ws.root()
};

// Unique metadata per (name, source, version) triple. This'll allow us
// to pull crates from anywhere without worrying about conflicts.
unit.pkg
.package_id()
.stable_hash(bcx.ws.root())
.stable_hash(ws_root)
.hash(&mut shared_hasher);

// Also mix in enabled features to our metadata. This'll ensure that
Expand Down
Loading