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

Make -Cmetadata consistent across platforms #14107

Merged
merged 1 commit into from
Jun 20, 2024

Conversation

alexcrichton
Copy link
Member

This commit updates how -Cmetadata is calculated for each unit to optionally exclude the host: ... line that rustc prints for cross-compiled builds. Previously the full verbose_version was hashed for stable builds and the host was explicitly hashed for non-stable builds. For a build using --target, however, that means that the -Cmetadata will be different when producing the same target on different hosts (e.g. producing the binary once on Linux and once on macOS).

This can hinder reproduction of a binary across different platforms even when the --target flag is used. For example in rust-lang/rust#117597 it was seen that a WebAssembly binary produced on different platforms was slightly different and this appears due to the differing -Cmetadata flags. After this commit the -Cmetadata flag is the same for two different platforms meaning that different platforms produce the same binary.

I've tested locally and a simple project produces a different binary before this change but produces the same binary on two platforms after this change. Unfortunately automated testing of this change will be difficult since it requires two different host compilers, though.

This commit updates how `-Cmetadata` is calculated for each unit to
optionally exclude the `host: ...` line that rustc prints for
cross-compiled builds. Previously the full `verbose_version` was hashed
for stable builds and the `host` was explicitly hashed for non-stable
builds. For a build using `--target`, however, that means that the
`-Cmetadata` will be different when producing the same target on
different hosts (e.g. producing the binary once on Linux and once on
macOS).

This can hinder reproduction of a binary across different platforms even
when the `--target` flag is used. For example in rust-lang/rust#117597
it was seen that a WebAssembly binary produced on different platforms
was slightly different and this appears due to the differing
`-Cmetadata` flags. After this commit the `-Cmetadata` flag is the same
for two different platforms meaning that different platforms produce the
same binary.

I've tested locally and a simple project produces a different binary
before this change but produces the same binary on two platforms after
this change. Unfortunately automated testing of this change will be
difficult since it requires two different host compilers, though.
@rustbot
Copy link
Collaborator

rustbot commented Jun 19, 2024

r? @ehuss

rustbot has assigned @ehuss.
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

@rustbot rustbot added A-layout Area: target output directory layout, naming, and organization S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 19, 2024
@weihanglo
Copy link
Member

Does this fix the same issues in #8140 and #13922?

@alexcrichton
Copy link
Member Author

Ah good catch! I suspect this fixes #13922 but I think there's more concerns brought up in #8140 so while this may fix some of the issues there I don't think it would fix all of them

@ehuss
Copy link
Contributor

ehuss commented Jun 20, 2024

Thanks! I'm not 100% certain that different host compilers will always produce the exact same output, but I imagine that should be considered a bug in rustc if it does not.

@bors r+

@bors
Copy link
Collaborator

bors commented Jun 20, 2024

📌 Commit 2db0bab has been approved by ehuss

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 20, 2024
@bors
Copy link
Collaborator

bors commented Jun 20, 2024

⌛ Testing commit 2db0bab with merge 361a488...

@bors
Copy link
Collaborator

bors commented Jun 20, 2024

☀️ Test successful - checks-actions
Approved by: ehuss
Pushing 361a488 to master...

@bors bors merged commit 361a488 into rust-lang:master Jun 20, 2024
22 checks passed
@BlackAsLight
Copy link

A bit off topic, but how does one know when this merge will show up in the stable or nightly release?

@bjorn3
Copy link
Member

bjorn3 commented Jun 20, 2024

I believe cargo gets updated on nightly once a week or so. And from there it will ride the release train to stable, which can take anywhere from 6-12 weeks depending on where in the release cycle a change gets merged.

@alexcrichton alexcrichton deleted the no-hash-rustc-host branch June 20, 2024 15:07
@alexcrichton
Copy link
Member Author

Thanks! I'm not 100% certain that different host compilers will always produce the exact same output, but I imagine that should be considered a bug in rustc if it does not.

I definitely agree yeah. Getting deterministic output across different host platforms for the same target to me is basically a big game of whack-a-mole. This PR is probably one piece of the puzzle but I also have the same hunch that there are many other pieces for completely full fidelity.

bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 22, 2024
Update cargo

17 commits in 3ed207e416fb2f678a40cc79c02dcf4f936a21ce..bc89bffa5987d4af8f71011c7557119b39e44a65
2024-06-18 19:18:22 +0000 to 2024-06-22 00:36:36 +0000
- test: migrate weak_dep_features, workspaces and yank to snapbox (rust-lang/cargo#14111)
- test: migrate features and features(2|_namespaced) to snapbox (rust-lang/cargo#14100)
- test: Add auto-redaction for not found error (rust-lang/cargo#14124)
- test: migrate build to snapbox (rust-lang/cargo#14068)
- test: migrate unit_graph, update and vendor to snapbox (rust-lang/cargo#14119)
- fix(test): Un-redact Packaged files (rust-lang/cargo#14123)
- test: Auto-redact file number (rust-lang/cargo#14121)
- test: migrate lints_table and lints/(mod|unknown_lints) to snapbox (rust-lang/cargo#14104)
- Simplify checking feature syntax (rust-lang/cargo#14106)
- test: migrate testsuites to snapbox (rust-lang/cargo#14091)
- Make `-Cmetadata` consistent across platforms (rust-lang/cargo#14107)
- fix(toml): Warn when edition is unuset, even when MSRV is unset (rust-lang/cargo#14110)
- Add `CodeFix::apply_solution` and impl `Clone` (rust-lang/cargo#14092)
- test: migrate `cargo_alias_config&cargo_config/mod` to snapbox (rust-lang/cargo#14093)
- Simplify checking for dependency cycles (rust-lang/cargo#14089)
- test: Migrate `pub_priv.rs` to snapshot (rust-lang/cargo#14103)
- test: migrate rustdoc and rustdocflags to snapbox (rust-lang/cargo#14098)

<!--
r? ghost
-->
@rustbot rustbot added this to the 1.81.0 milestone Jun 22, 2024
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Jun 23, 2024
Update cargo

17 commits in 3ed207e416fb2f678a40cc79c02dcf4f936a21ce..bc89bffa5987d4af8f71011c7557119b39e44a65
2024-06-18 19:18:22 +0000 to 2024-06-22 00:36:36 +0000
- test: migrate weak_dep_features, workspaces and yank to snapbox (rust-lang/cargo#14111)
- test: migrate features and features(2|_namespaced) to snapbox (rust-lang/cargo#14100)
- test: Add auto-redaction for not found error (rust-lang/cargo#14124)
- test: migrate build to snapbox (rust-lang/cargo#14068)
- test: migrate unit_graph, update and vendor to snapbox (rust-lang/cargo#14119)
- fix(test): Un-redact Packaged files (rust-lang/cargo#14123)
- test: Auto-redact file number (rust-lang/cargo#14121)
- test: migrate lints_table and lints/(mod|unknown_lints) to snapbox (rust-lang/cargo#14104)
- Simplify checking feature syntax (rust-lang/cargo#14106)
- test: migrate testsuites to snapbox (rust-lang/cargo#14091)
- Make `-Cmetadata` consistent across platforms (rust-lang/cargo#14107)
- fix(toml): Warn when edition is unuset, even when MSRV is unset (rust-lang/cargo#14110)
- Add `CodeFix::apply_solution` and impl `Clone` (rust-lang/cargo#14092)
- test: migrate `cargo_alias_config&cargo_config/mod` to snapbox (rust-lang/cargo#14093)
- Simplify checking for dependency cycles (rust-lang/cargo#14089)
- test: Migrate `pub_priv.rs` to snapshot (rust-lang/cargo#14103)
- test: migrate rustdoc and rustdocflags to snapbox (rust-lang/cargo#14098)

<!--
r? ghost
-->
@joshtriplett joshtriplett added the relnotes Release-note worthy label Aug 20, 2024
@joshtriplett
Copy link
Member

Adding the relnotes label here. Sketch of release notes:

The Rust compiler now uses the same metadata for symbol ABI compatibility regardless of the host the Rust compiler was compiled for. This makes it possible for cross-compiles to the same target from different hosts to produce identical binaries. (There may still be other issues with doing so, which we hope to resolve over time.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-layout Area: target output directory layout, naming, and organization relnotes Release-note worthy S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants