mirror of
https://github.com/rust-lang/cargo.git
synced 2025-10-01 11:30:39 +00:00
Go back to not hashing RUSTFLAGS
in -Cmetadata
This is a moral revert of #6503 but not a literal code revert. This switches Cargo's behavior to avoid hashing compiler flags into `-Cmetadata` since we've now had multiple requests of excluding flags from the `-Cmetadata` hash: usage of `--remap-path-prefix` and PGO options. These options should only affect how the compiler is invoked/compiled and not radical changes such as symbol names, but symbol names are changed based on `-Cmetadata`. Instead Cargo will still track these flags internally, but only for reinvoking rustc, and not for caching separately based on rustc flags. Closes #7416
This commit is contained in:
parent
d8e62ee121
commit
f3c92ed52e
@ -541,36 +541,6 @@ fn compute_metadata<'a, 'cfg>(
|
|||||||
unit.profile.hash(&mut hasher);
|
unit.profile.hash(&mut hasher);
|
||||||
unit.mode.hash(&mut hasher);
|
unit.mode.hash(&mut hasher);
|
||||||
|
|
||||||
// Throw in the rustflags we're compiling with.
|
|
||||||
// This helps when the target directory is a shared cache for projects with different cargo configs,
|
|
||||||
// or if the user is experimenting with different rustflags manually.
|
|
||||||
let mut hash_flags = |flags: &[String]| {
|
|
||||||
// Ignore some flags. These may affect reproducible builds if they affect
|
|
||||||
// the path. The fingerprint will handle recompilation if these change.
|
|
||||||
let mut iter = flags.iter();
|
|
||||||
while let Some(flag) = iter.next() {
|
|
||||||
if flag.starts_with("--remap-path-prefix=") {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if flag == "--remap-path-prefix" {
|
|
||||||
iter.next();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
flag.hash(&mut hasher);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
if let Some(args) = bcx.extra_args_for(unit) {
|
|
||||||
// Arguments passed to `cargo rustc`.
|
|
||||||
hash_flags(args);
|
|
||||||
}
|
|
||||||
// Arguments passed in via RUSTFLAGS env var.
|
|
||||||
let flags = if unit.mode.is_doc() {
|
|
||||||
bcx.rustdocflags_args(unit)
|
|
||||||
} else {
|
|
||||||
bcx.rustflags_args(unit)
|
|
||||||
};
|
|
||||||
hash_flags(flags);
|
|
||||||
|
|
||||||
// Artifacts compiled for the host should have a different metadata
|
// Artifacts compiled for the host should have a different metadata
|
||||||
// piece than those compiled for the target, so make sure we throw in
|
// piece than those compiled for the target, so make sure we throw in
|
||||||
// the unit's `kind` as well
|
// the unit's `kind` as well
|
||||||
|
@ -59,7 +59,7 @@
|
|||||||
//! Target flags (test/bench/for_host/edition) | ✓ |
|
//! Target flags (test/bench/for_host/edition) | ✓ |
|
||||||
//! -C incremental=… flag | ✓ |
|
//! -C incremental=… flag | ✓ |
|
||||||
//! mtime of sources | ✓[^3] |
|
//! mtime of sources | ✓[^3] |
|
||||||
//! RUSTFLAGS/RUSTDOCFLAGS | ✓ | ✓
|
//! RUSTFLAGS/RUSTDOCFLAGS | ✓ |
|
||||||
//!
|
//!
|
||||||
//! [^1]: Build script and bin dependencies are not included.
|
//! [^1]: Build script and bin dependencies are not included.
|
||||||
//!
|
//!
|
||||||
|
@ -1151,7 +1151,15 @@ fn reuse_shared_build_dep() {
|
|||||||
fn changing_rustflags_is_cached() {
|
fn changing_rustflags_is_cached() {
|
||||||
let p = project().file("src/lib.rs", "").build();
|
let p = project().file("src/lib.rs", "").build();
|
||||||
|
|
||||||
p.cargo("build").run();
|
// This isn't ever cached, we always have to recompile
|
||||||
|
for _ in 0..2 {
|
||||||
|
p.cargo("build")
|
||||||
|
.with_stderr(
|
||||||
|
"\
|
||||||
|
[COMPILING] foo v0.0.1 ([..])
|
||||||
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]",
|
||||||
|
)
|
||||||
|
.run();
|
||||||
p.cargo("build")
|
p.cargo("build")
|
||||||
.env("RUSTFLAGS", "-C linker=cc")
|
.env("RUSTFLAGS", "-C linker=cc")
|
||||||
.with_stderr(
|
.with_stderr(
|
||||||
@ -1160,14 +1168,7 @@ fn changing_rustflags_is_cached() {
|
|||||||
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]",
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]",
|
||||||
)
|
)
|
||||||
.run();
|
.run();
|
||||||
// This should not recompile!
|
}
|
||||||
p.cargo("build")
|
|
||||||
.with_stderr("[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]")
|
|
||||||
.run();
|
|
||||||
p.cargo("build")
|
|
||||||
.env("RUSTFLAGS", "-C linker=cc")
|
|
||||||
.with_stderr("[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]")
|
|
||||||
.run();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cargo_test]
|
#[cargo_test]
|
||||||
@ -1257,6 +1258,9 @@ fn fingerprint_cleaner_does_not_rebuild() {
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bar = { path = "bar" }
|
bar = { path = "bar" }
|
||||||
|
|
||||||
|
[features]
|
||||||
|
a = []
|
||||||
"#,
|
"#,
|
||||||
)
|
)
|
||||||
.file("src/lib.rs", "")
|
.file("src/lib.rs", "")
|
||||||
@ -1267,12 +1271,10 @@ fn fingerprint_cleaner_does_not_rebuild() {
|
|||||||
p.cargo("build -Z mtime-on-use")
|
p.cargo("build -Z mtime-on-use")
|
||||||
.masquerade_as_nightly_cargo()
|
.masquerade_as_nightly_cargo()
|
||||||
.run();
|
.run();
|
||||||
p.cargo("build -Z mtime-on-use")
|
p.cargo("build -Z mtime-on-use --features a")
|
||||||
.masquerade_as_nightly_cargo()
|
.masquerade_as_nightly_cargo()
|
||||||
.env("RUSTFLAGS", "-C linker=cc")
|
|
||||||
.with_stderr(
|
.with_stderr(
|
||||||
"\
|
"\
|
||||||
[COMPILING] bar v0.0.1 ([..])
|
|
||||||
[COMPILING] foo v0.0.1 ([..])
|
[COMPILING] foo v0.0.1 ([..])
|
||||||
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]",
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]",
|
||||||
)
|
)
|
||||||
@ -1285,16 +1287,14 @@ fn fingerprint_cleaner_does_not_rebuild() {
|
|||||||
sleep_ms(1000);
|
sleep_ms(1000);
|
||||||
}
|
}
|
||||||
// This does not make new files, but it does update the mtime.
|
// This does not make new files, but it does update the mtime.
|
||||||
p.cargo("build -Z mtime-on-use")
|
p.cargo("build -Z mtime-on-use --features a")
|
||||||
.masquerade_as_nightly_cargo()
|
.masquerade_as_nightly_cargo()
|
||||||
.env("RUSTFLAGS", "-C linker=cc")
|
|
||||||
.with_stderr("[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]")
|
.with_stderr("[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]")
|
||||||
.run();
|
.run();
|
||||||
fingerprint_cleaner(p.target_debug_dir(), timestamp);
|
fingerprint_cleaner(p.target_debug_dir(), timestamp);
|
||||||
// This should not recompile!
|
// This should not recompile!
|
||||||
p.cargo("build -Z mtime-on-use")
|
p.cargo("build -Z mtime-on-use --features a")
|
||||||
.masquerade_as_nightly_cargo()
|
.masquerade_as_nightly_cargo()
|
||||||
.env("RUSTFLAGS", "-C linker=cc")
|
|
||||||
.with_stderr("[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]")
|
.with_stderr("[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]")
|
||||||
.run();
|
.run();
|
||||||
// But this should be cleaned and so need a rebuild
|
// But this should be cleaned and so need a rebuild
|
||||||
@ -1302,7 +1302,6 @@ fn fingerprint_cleaner_does_not_rebuild() {
|
|||||||
.masquerade_as_nightly_cargo()
|
.masquerade_as_nightly_cargo()
|
||||||
.with_stderr(
|
.with_stderr(
|
||||||
"\
|
"\
|
||||||
[COMPILING] bar v0.0.1 ([..])
|
|
||||||
[COMPILING] foo v0.0.1 ([..])
|
[COMPILING] foo v0.0.1 ([..])
|
||||||
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]",
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]",
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user