Skip to content

Commit

Permalink
fix: -Cmetadata includes whether extra linker/rustflags is used
Browse files Browse the repository at this point in the history
While we don't hash RUSTFLAGS because it may contain absolute paths that
hurts reproducibility, we track whether a unit having RUSTFLAGS applied
so that units with and without RUSTFLAGS won't clobber with each other.
  • Loading branch information
weihanglo committed Aug 20, 2024
1 parent 960adae commit a15807e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
9 changes: 9 additions & 0 deletions src/cargo/core/compiler/build_runner/compilation_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,15 @@ fn compute_metadata(
// with user dependencies.
unit.is_std.hash(&mut hasher);

// While we don't hash RUSTFLAGS because it may contain absolute paths that
// hurts reproducibility, we track whether a unit having RUSTFLAGS applied
// so that units with and without RUSTFLAGS won't clobber with each other.
// This is essentially a hack for fixing rust-lang/cargo#14253.
let no_target_config_applied = unit.rustflags.is_empty()
&& unit.rustdocflags.is_empty()
&& unit.links_overrides.is_empty();
no_target_config_applied.hash(&mut hasher);

MetaInfo {
meta_hash: Metadata(hasher.finish()),
use_extra_filename: should_use_metadata(bcx, unit),
Expand Down
18 changes: 2 additions & 16 deletions tests/testsuite/rustflags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1674,29 +1674,15 @@ fn host_config_shared_build_dep() {
.arg("-Ztarget-applies-to-host")
.arg("--config=target-applies-to-host=false")
.env("RUSTFLAGS", "--cfg foo")
.with_status(101)
// Sometimes it compiles. Not deterministic...
.with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[LOCKING] 2 packages to latest compatible versions
[DOWNLOADING] crates ...
[DOWNLOADED] cc v1.0.0 (registry `dummy-registry`)
[WARNING] output filename collision.
The lib target `cc` in package `cc v1.0.0` has the same output filename as the lib target `cc` in package `cc v1.0.0`.
Colliding filename is: [ROOT]/foo/target/debug/deps/libcc-[HASH].rlib
The targets should have unique names.
Consider changing their names to be unique or compiling them separately.
This may become a hard error in the future; see <https://github.com/rust-lang/cargo/issues/6313>.
[WARNING] output filename collision.
The lib target `cc` in package `cc v1.0.0` has the same output filename as the lib target `cc` in package `cc v1.0.0`.
Colliding filename is: [ROOT]/foo/target/debug/deps/libcc-[HASH].rmeta
The targets should have unique names.
Consider changing their names to be unique or compiling them separately.
This may become a hard error in the future; see <https://github.com/rust-lang/cargo/issues/6313>.
[COMPILING] cc v1.0.0
[ERROR] failed to build archive: No such file or directory
[ERROR] could not compile `cc` (lib) due to 1 previous error
[COMPILING] bootstrap v0.0.0 ([ROOT]/foo)
[FINISHED] `dev` profile [unoptimized] target(s) in [ELAPSED]s
"#]])
.run();
Expand Down

0 comments on commit a15807e

Please sign in to comment.