Skip to content

Commit 9865dde

Browse files
committed
Auto merge of #11353 - weihanglo:issue/10527, r=epage
Propagate change of artifact bin dep to its parent fingerprint
2 parents ffb6ee9 + 347523e commit 9865dde

File tree

2 files changed

+84
-14
lines changed

2 files changed

+84
-14
lines changed

src/cargo/core/compiler/fingerprint.rs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,20 +1254,24 @@ fn calculate(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Arc<Fingerpri
12541254
/// Calculate a fingerprint for a "normal" unit, or anything that's not a build
12551255
/// script. This is an internal helper of `calculate`, don't call directly.
12561256
fn calculate_normal(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Fingerprint> {
1257-
// Recursively calculate the fingerprint for all of our dependencies.
1258-
//
1259-
// Skip fingerprints of binaries because they don't actually induce a
1260-
// recompile, they're just dependencies in the sense that they need to be
1261-
// built.
1262-
//
1263-
// Create Vec since mutable cx is needed in closure.
1264-
let deps = Vec::from(cx.unit_deps(unit));
1265-
let mut deps = deps
1266-
.into_iter()
1267-
.filter(|dep| !dep.unit.target.is_bin())
1268-
.map(|dep| DepFingerprint::new(cx, unit, &dep))
1269-
.collect::<CargoResult<Vec<_>>>()?;
1270-
deps.sort_by(|a, b| a.pkg_id.cmp(&b.pkg_id));
1257+
let deps = {
1258+
// Recursively calculate the fingerprint for all of our dependencies.
1259+
//
1260+
// Skip fingerprints of binaries because they don't actually induce a
1261+
// recompile, they're just dependencies in the sense that they need to be
1262+
// built. The only exception here are artifact dependencies,
1263+
// which is an actual dependency that needs a recompile.
1264+
//
1265+
// Create Vec since mutable cx is needed in closure.
1266+
let deps = Vec::from(cx.unit_deps(unit));
1267+
let mut deps = deps
1268+
.into_iter()
1269+
.filter(|dep| !dep.unit.target.is_bin() || dep.unit.artifact.is_true())
1270+
.map(|dep| DepFingerprint::new(cx, unit, &dep))
1271+
.collect::<CargoResult<Vec<_>>>()?;
1272+
deps.sort_by(|a, b| a.pkg_id.cmp(&b.pkg_id));
1273+
deps
1274+
};
12711275

12721276
// Afterwards calculate our own fingerprint information.
12731277
let target_root = target_root(cx);

tests/testsuite/artifact_dep.rs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2276,3 +2276,69 @@ fn build_script_features_for_shared_dependency() {
22762276
.masquerade_as_nightly_cargo(&["bindeps"])
22772277
.run();
22782278
}
2279+
2280+
#[cargo_test]
2281+
fn calc_bin_artifact_fingerprint() {
2282+
// See rust-lang/cargo#10527
2283+
let p = project()
2284+
.file(
2285+
"Cargo.toml",
2286+
r#"
2287+
[package]
2288+
name = "foo"
2289+
version = "0.1.0"
2290+
resolver = "2"
2291+
2292+
[dependencies]
2293+
bar = { path = "bar/", artifact = "bin" }
2294+
"#,
2295+
)
2296+
.file(
2297+
"src/main.rs",
2298+
r#"
2299+
fn main() {
2300+
let _b = include_bytes!(env!("CARGO_BIN_FILE_BAR"));
2301+
}
2302+
"#,
2303+
)
2304+
.file("bar/Cargo.toml", &basic_bin_manifest("bar"))
2305+
.file("bar/src/main.rs", r#"fn main() { println!("foo") }"#)
2306+
.build();
2307+
p.cargo("check -Z bindeps")
2308+
.masquerade_as_nightly_cargo(&["bindeps"])
2309+
.with_stderr(
2310+
"\
2311+
[COMPILING] bar v0.5.0 ([CWD]/bar)
2312+
[CHECKING] foo v0.1.0 ([CWD])
2313+
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
2314+
",
2315+
)
2316+
.run();
2317+
2318+
p.change_file("bar/src/main.rs", r#"fn main() { println!("bar") }"#);
2319+
// Change in artifact bin dep `bar` propagates to `foo`, triggering recompile.
2320+
p.cargo("check -v -Z bindeps")
2321+
.masquerade_as_nightly_cargo(&["bindeps"])
2322+
.with_stderr(
2323+
"\
2324+
[COMPILING] bar v0.5.0 ([CWD]/bar)
2325+
[RUNNING] `rustc --crate-name bar [..]`
2326+
[CHECKING] foo v0.1.0 ([CWD])
2327+
[RUNNING] `rustc --crate-name foo [..]`
2328+
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
2329+
",
2330+
)
2331+
.run();
2332+
2333+
// All units are fresh. No recompile.
2334+
p.cargo("check -v -Z bindeps")
2335+
.masquerade_as_nightly_cargo(&["bindeps"])
2336+
.with_stderr(
2337+
"\
2338+
[FRESH] bar v0.5.0 ([CWD]/bar)
2339+
[FRESH] foo v0.1.0 ([CWD])
2340+
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
2341+
",
2342+
)
2343+
.run();
2344+
}

0 commit comments

Comments
 (0)