From 4d51d203b3ee97e6b32870aa14f3fc05ea0344c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Mon, 21 Nov 2022 23:23:41 +0000 Subject: [PATCH] use `UnitFor::is_for_host` to detect build deps Although `CompileKind::is_host` is currently used for build dependencies prior to unit graph sharing, it's not a guarantee. So we use `UnitFor::is_for_host` to make detection more future-proof. --- src/cargo/ops/cargo_compile/mod.rs | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/cargo/ops/cargo_compile/mod.rs b/src/cargo/ops/cargo_compile/mod.rs index 5f3112a1855e..dc7efb1ca1e8 100644 --- a/src/cargo/ops/cargo_compile/mod.rs +++ b/src/cargo/ops/cargo_compile/mod.rs @@ -1225,7 +1225,15 @@ fn rebuild_unit_graph_shared( let new_roots = roots .iter() .map(|root| { - traverse_and_share(interner, &mut memo, &mut result, &unit_graph, root, to_host) + traverse_and_share( + interner, + &mut memo, + &mut result, + &unit_graph, + root, + false, + to_host, + ) }) .collect(); let new_scrape_units = scrape_units @@ -1246,6 +1254,7 @@ fn traverse_and_share( new_graph: &mut UnitGraph, unit_graph: &UnitGraph, unit: &Unit, + unit_is_for_host: bool, to_host: CompileKind, ) -> Unit { if let Some(new_unit) = memo.get(unit) { @@ -1256,8 +1265,15 @@ fn traverse_and_share( let new_deps: Vec<_> = unit_graph[unit] .iter() .map(|dep| { - let new_dep_unit = - traverse_and_share(interner, memo, new_graph, unit_graph, &dep.unit, to_host); + let new_dep_unit = traverse_and_share( + interner, + memo, + new_graph, + unit_graph, + &dep.unit, + dep.unit_for.is_for_host(), + to_host, + ); new_dep_unit.hash(&mut dep_hash); UnitDep { unit: new_dep_unit, @@ -1286,7 +1302,7 @@ fn traverse_and_share( // If this is a build dependency, and it's not shared with runtime dependencies, we can weaken // its debuginfo level to optimize build times. We do nothing if it's an artifact dependency, // as it and its debuginfo may end up embedded in the main program. - if unit.kind.is_host() && profile.debuginfo.is_deferred() && !unit.artifact.is_true() { + if unit_is_for_host && profile.debuginfo.is_deferred() && !unit.artifact.is_true() { // We create a "probe" test to see if a unit with the same explicit debuginfo level exists // in the graph. This is the level we'd expect if it was set manually or the default value // set by a profile for a runtime dependency: its canonical value.