cargo::ops::cargo_compile

Function rebuild_unit_graph_shared

source
fn rebuild_unit_graph_shared(
    interner: &UnitInterner,
    unit_graph: UnitGraph,
    roots: &[Unit],
    scrape_units: &[Unit],
    to_host: Option<CompileKind>,
) -> (Vec<Unit>, Vec<Unit>, UnitGraph)
Expand description

This is used to rebuild the unit graph, sharing host dependencies if possible, and applying other unit adjustments based on the whole graph.

This will translate any unit’s CompileKind::Target(host) to CompileKind::Host if to_host is not None and the kind is equal to to_host. This also handles generating the unit dep_hash, and merging shared units if possible.

This is necessary because if normal dependencies used CompileKind::Host, there would be no way to distinguish those units from build-dependency units or artifact dependency units. This can cause a problem if a shared normal/build/artifact dependency needs to link to another dependency whose features differ based on whether or not it is a normal, build or artifact dependency. If all units used CompileKind::Host, then they would end up being identical, causing a collision in the UnitGraph, and Cargo would end up randomly choosing one value or the other.

The solution is to keep normal, build and artifact dependencies separate when building the unit graph, and then run this second pass which will try to combine shared dependencies safely. By adding a hash of the dependencies to the Unit, this allows the CompileKind to be changed back to Host and artifact_target_for_features to be removed without fear of an unwanted collision for build or artifact dependencies.

This is also responsible for adjusting the strip profile option to opportunistically strip if debug is 0 for all dependencies. This helps remove debuginfo added by the standard library.

This is also responsible for adjusting the debug setting for host dependencies, turning off debug if the user has not explicitly enabled it, and the unit is not shared with a target unit.