diff --git a/src/cargo/core/compiler/fingerprint/mod.rs b/src/cargo/core/compiler/fingerprint/mod.rs index 69268bdc202..02d7360218e 100644 --- a/src/cargo/core/compiler/fingerprint/mod.rs +++ b/src/cargo/core/compiler/fingerprint/mod.rs @@ -1646,6 +1646,15 @@ fn calculate_normal( if let Some(allow_features) = &build_runner.bcx.gctx.cli_unstable().allow_features { allow_features.hash(&mut config); } + // -Zno-embed-metadata changes how all units are compiled, and it also changes how we tell + // rustc to link to deps using `--extern`. If it changes, we should rebuild everything. + build_runner + .bcx + .gctx + .cli_unstable() + .no_embed_metadata + .hash(&mut config); + let compile_kind = unit.kind.fingerprint_hash(); let mut declared_features = unit.pkg.summary().features().keys().collect::>(); declared_features.sort(); // to avoid useless rebuild if the user orders it's features diff --git a/tests/testsuite/build.rs b/tests/testsuite/build.rs index 5605f4736ec..eabe76ea77f 100644 --- a/tests/testsuite/build.rs +++ b/tests/testsuite/build.rs @@ -6338,8 +6338,8 @@ fn renamed_uplifted_artifact_remains_unmodified_after_rebuild() { assert!(not_the_same, "renamed uplifted artifact must be unmodified"); } -#[cargo_test(nightly, reason = "-Zembed-metadata is nightly only")] -fn embed_metadata() { +#[cargo_test(nightly, reason = "-Zno-embed-metadata is nightly only")] +fn no_embed_metadata() { let p = project() .file( "Cargo.toml", @@ -6378,8 +6378,8 @@ fn embed_metadata() { // Make sure that cargo passes --extern=.rmeta even if // is compiled as a dylib. -#[cargo_test(nightly, reason = "-Zembed-metadata is nightly only")] -fn embed_metadata_dylib_dep() { +#[cargo_test(nightly, reason = "-Zno-embed-metadata is nightly only")] +fn no_embed_metadata_dylib_dep() { let p = project() .file( "Cargo.toml", @@ -6425,3 +6425,53 @@ fn embed_metadata_dylib_dep() { ) .run(); } + +#[cargo_test(nightly, reason = "-Zno-embed-metadata is nightly only")] +fn no_embed_metadata_invalidate() { + // Invalidate all deps when -Zno-embed-metadata is toggled + let p = project() + .file( + "Cargo.toml", + r#" + [package] + + name = "foo" + version = "0.5.0" + edition = "2015" + + [dependencies.bar] + path = "bar" + "#, + ) + .file("src/main.rs", &main_file(r#""{}", bar::gimme()"#, &[])) + .file("bar/Cargo.toml", &basic_lib_manifest("bar")) + .file( + "bar/src/bar.rs", + r#" + pub fn gimme() -> &'static str { + "test passed" + } + "#, + ) + .build(); + + p.cargo("build -Z no-embed-metadata") + .masquerade_as_nightly_cargo(&["-Z no-embed-metadata"]) + .with_stderr_data(str![[r#" +[LOCKING] 1 package to latest compatible version +[COMPILING] bar v0.5.0 ([ROOT]/foo/bar) +[COMPILING] foo v0.5.0 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) + .run(); + p.cargo("build") + .masquerade_as_nightly_cargo(&["-Z no-embed-metadata"]) + .with_stderr_data(str![[r#" +[COMPILING] bar v0.5.0 ([ROOT]/foo/bar) +[COMPILING] foo v0.5.0 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) + .run(); +}