Skip to content

Commit 347523e

Browse files
committed
fix(fingerprint): include bin target if it is also an artifact dep
1 parent 58e86d4 commit 347523e

File tree

2 files changed

+24
-22
lines changed

2 files changed

+24
-22
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: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2279,7 +2279,7 @@ fn build_script_features_for_shared_dependency() {
22792279

22802280
#[cargo_test]
22812281
fn calc_bin_artifact_fingerprint() {
2282-
// This records the WRONG behaviour. See rust-lang/cargo#10527
2282+
// See rust-lang/cargo#10527
22832283
let p = project()
22842284
.file(
22852285
"Cargo.toml",
@@ -2316,29 +2316,27 @@ fn calc_bin_artifact_fingerprint() {
23162316
.run();
23172317

23182318
p.change_file("bar/src/main.rs", r#"fn main() { println!("bar") }"#);
2319-
// Change in bin artifact but not propagated to parent fingerprint.
2320-
// This is WRONG!
2319+
// Change in artifact bin dep `bar` propagates to `foo`, triggering recompile.
23212320
p.cargo("check -v -Z bindeps")
23222321
.masquerade_as_nightly_cargo(&["bindeps"])
23232322
.with_stderr(
23242323
"\
23252324
[COMPILING] bar v0.5.0 ([CWD]/bar)
23262325
[RUNNING] `rustc --crate-name bar [..]`
2327-
[FRESH] foo v0.1.0 ([CWD])
2326+
[CHECKING] foo v0.1.0 ([CWD])
2327+
[RUNNING] `rustc --crate-name foo [..]`
23282328
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
23292329
",
23302330
)
23312331
.run();
23322332

2333-
// Only run the second time can parent fingerpint perceive the change.
2334-
// This is WRONG!
2333+
// All units are fresh. No recompile.
23352334
p.cargo("check -v -Z bindeps")
23362335
.masquerade_as_nightly_cargo(&["bindeps"])
23372336
.with_stderr(
23382337
"\
23392338
[FRESH] bar v0.5.0 ([CWD]/bar)
2340-
[CHECKING] foo v0.1.0 ([CWD])
2341-
[RUNNING] `rustc --crate-name foo [..]`
2339+
[FRESH] foo v0.1.0 ([CWD])
23422340
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
23432341
",
23442342
)

0 commit comments

Comments
 (0)