Skip to content

Commit 7f02ff0

Browse files
committed
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.
1 parent 8e3482e commit 7f02ff0

File tree

1 file changed

+20
-4
lines changed
  • src/cargo/ops/cargo_compile

1 file changed

+20
-4
lines changed

src/cargo/ops/cargo_compile/mod.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,7 +1225,15 @@ fn rebuild_unit_graph_shared(
12251225
let new_roots = roots
12261226
.iter()
12271227
.map(|root| {
1228-
traverse_and_share(interner, &mut memo, &mut result, &unit_graph, root, to_host)
1228+
traverse_and_share(
1229+
interner,
1230+
&mut memo,
1231+
&mut result,
1232+
&unit_graph,
1233+
root,
1234+
false,
1235+
to_host,
1236+
)
12291237
})
12301238
.collect();
12311239
let new_scrape_units = scrape_units
@@ -1246,6 +1254,7 @@ fn traverse_and_share(
12461254
new_graph: &mut UnitGraph,
12471255
unit_graph: &UnitGraph,
12481256
unit: &Unit,
1257+
unit_is_for_host: bool,
12491258
to_host: CompileKind,
12501259
) -> Unit {
12511260
if let Some(new_unit) = memo.get(unit) {
@@ -1256,8 +1265,15 @@ fn traverse_and_share(
12561265
let new_deps: Vec<_> = unit_graph[unit]
12571266
.iter()
12581267
.map(|dep| {
1259-
let new_dep_unit =
1260-
traverse_and_share(interner, memo, new_graph, unit_graph, &dep.unit, to_host);
1268+
let new_dep_unit = traverse_and_share(
1269+
interner,
1270+
memo,
1271+
new_graph,
1272+
unit_graph,
1273+
&dep.unit,
1274+
dep.unit_for.is_for_host(),
1275+
to_host,
1276+
);
12611277
new_dep_unit.hash(&mut dep_hash);
12621278
UnitDep {
12631279
unit: new_dep_unit,
@@ -1286,7 +1302,7 @@ fn traverse_and_share(
12861302
// If this is a build dependency, and it's not shared with runtime dependencies, we can weaken
12871303
// its debuginfo level to optimize build times. We do nothing if it's an artifact dependency,
12881304
// as it and its debuginfo may end up embedded in the main program.
1289-
if unit.kind.is_host() && profile.debuginfo.is_deferred() && !unit.artifact.is_true() {
1305+
if unit_is_for_host && profile.debuginfo.is_deferred() && !unit.artifact.is_true() {
12901306
// We create a "probe" test to see if a unit with the same explicit debuginfo level exists
12911307
// in the graph. This is the level we'd expect if it was set manually or the default value
12921308
// set by a profile for a runtime dependency: its canonical value.

0 commit comments

Comments
 (0)