Skip to content

Commit 1b16a5b

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 4e05b01 commit 1b16a5b

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
@@ -574,7 +574,15 @@ fn rebuild_unit_graph_shared(
574574
let new_roots = roots
575575
.iter()
576576
.map(|root| {
577-
traverse_and_share(interner, &mut memo, &mut result, &unit_graph, root, to_host)
577+
traverse_and_share(
578+
interner,
579+
&mut memo,
580+
&mut result,
581+
&unit_graph,
582+
root,
583+
false,
584+
to_host,
585+
)
578586
})
579587
.collect();
580588
// If no unit in the unit graph ended up having scrape units attached as dependencies,
@@ -598,6 +606,7 @@ fn traverse_and_share(
598606
new_graph: &mut UnitGraph,
599607
unit_graph: &UnitGraph,
600608
unit: &Unit,
609+
unit_is_for_host: bool,
601610
to_host: Option<CompileKind>,
602611
) -> Unit {
603612
if let Some(new_unit) = memo.get(unit) {
@@ -608,8 +617,15 @@ fn traverse_and_share(
608617
let new_deps: Vec<_> = unit_graph[unit]
609618
.iter()
610619
.map(|dep| {
611-
let new_dep_unit =
612-
traverse_and_share(interner, memo, new_graph, unit_graph, &dep.unit, to_host);
620+
let new_dep_unit = traverse_and_share(
621+
interner,
622+
memo,
623+
new_graph,
624+
unit_graph,
625+
&dep.unit,
626+
dep.unit_for.is_for_host(),
627+
to_host,
628+
);
613629
new_dep_unit.hash(&mut dep_hash);
614630
UnitDep {
615631
unit: new_dep_unit,
@@ -637,7 +653,7 @@ fn traverse_and_share(
637653
// If this is a build dependency, and it's not shared with runtime dependencies, we can weaken
638654
// its debuginfo level to optimize build times. We do nothing if it's an artifact dependency,
639655
// as it and its debuginfo may end up embedded in the main program.
640-
if unit.kind.is_host()
656+
if unit_is_for_host
641657
&& to_host.is_some()
642658
&& profile.debuginfo.is_deferred()
643659
&& !unit.artifact.is_true()

0 commit comments

Comments
 (0)