Skip to content

Commit

Permalink
use UnitFor::is_for_host to detect build deps
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lqd committed Nov 21, 2022
1 parent 9037d48 commit 4d51d20
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/cargo/ops/cargo_compile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand All @@ -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,
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 4d51d20

Please sign in to comment.