Skip to content

Commit e99c0bb

Browse files
committed
fix: deduplicate dependencies by artifact target
Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
1 parent 6d43fa6 commit e99c0bb

File tree

5 files changed

+27
-2
lines changed

5 files changed

+27
-2
lines changed

src/cargo/core/compiler/standard_lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ pub fn generate_std_roots(
214214
/*is_std*/ true,
215215
/*dep_hash*/ 0,
216216
IsArtifact::No,
217+
None,
217218
));
218219
}
219220
}

src/cargo/core/compiler/unit.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
use crate::core::compiler::{unit_dependencies::IsArtifact, CompileKind, CompileMode, CrateType};
1+
use crate::core::compiler::unit_dependencies::IsArtifact;
2+
use crate::core::compiler::{CompileKind, CompileMode, CompileTarget, CrateType};
23
use crate::core::manifest::{Target, TargetKind};
3-
use crate::core::{profiles::Profile, Package};
4+
use crate::core::profiles::Profile;
5+
use crate::core::Package;
46
use crate::util::hex::short_hash;
57
use crate::util::interning::InternedString;
68
use crate::util::Config;
@@ -72,6 +74,12 @@ pub struct UnitInner {
7274
/// This value initially starts as 0, and then is filled in via a
7375
/// second-pass after all the unit dependencies have been computed.
7476
pub dep_hash: u64,
77+
78+
/// This is used for target-dependent feature resolution and is copied from
79+
/// [`FeaturesFor::ArtifactDep`], if the enum matches the variant.
80+
///
81+
/// [`FeaturesFor::ArtifactDep`]: crate::core::resolver::features::FeaturesFor::ArtifactDep
82+
pub artifact_target_for_features: Option<CompileTarget>,
7583
}
7684

7785
impl UnitInner {
@@ -139,6 +147,10 @@ impl fmt::Debug for Unit {
139147
.field("mode", &self.mode)
140148
.field("features", &self.features)
141149
.field("artifact", &self.artifact.is_true())
150+
.field(
151+
"artifact_target_for_features",
152+
&self.artifact_target_for_features,
153+
)
142154
.field("is_std", &self.is_std)
143155
.field("dep_hash", &self.dep_hash)
144156
.finish()
@@ -184,6 +196,7 @@ impl UnitInterner {
184196
is_std: bool,
185197
dep_hash: u64,
186198
artifact: IsArtifact,
199+
artifact_target_for_features: Option<CompileTarget>,
187200
) -> Unit {
188201
let target = match (is_std, target.kind()) {
189202
// This is a horrible hack to support build-std. `libstd` declares
@@ -216,6 +229,7 @@ impl UnitInterner {
216229
is_std,
217230
dep_hash,
218231
artifact,
232+
artifact_target_for_features,
219233
});
220234
Unit { inner }
221235
}

src/cargo/core/compiler/unit_dependencies.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,10 @@ fn new_unit_dep_with_profile(
885885
.resolve()
886886
.is_public_dep(parent.pkg.package_id(), pkg.package_id());
887887
let features_for = unit_for.map_to_features_for(artifact);
888+
let artifact_target = match features_for {
889+
FeaturesFor::ArtifactDep(target) => Some(target),
890+
_ => None,
891+
};
888892
let features = state.activated_features(pkg.package_id(), features_for);
889893
let unit = state.interner.intern(
890894
pkg,
@@ -896,6 +900,7 @@ fn new_unit_dep_with_profile(
896900
state.is_std,
897901
/*dep_hash*/ 0,
898902
artifact.map_or(IsArtifact::No, |_| IsArtifact::Yes),
903+
artifact_target,
899904
);
900905
Ok(UnitDep {
901906
unit,

src/cargo/ops/cargo_compile/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,9 @@ fn traverse_and_share(
630630
unit.is_std,
631631
new_dep_hash,
632632
unit.artifact,
633+
// Since `dep_hash` is now filled in, there's no need to specify the artifact target
634+
// for target-dependent feature resolution
635+
None,
633636
);
634637
assert!(memo.insert(unit.clone(), new_unit.clone()).is_none());
635638
new_graph.entry(new_unit.clone()).or_insert(new_deps);
@@ -788,6 +791,7 @@ fn override_rustc_crate_types(
788791
unit.is_std,
789792
unit.dep_hash,
790793
unit.artifact,
794+
unit.artifact_target_for_features,
791795
)
792796
};
793797
units[0] = match unit.target.kind() {

src/cargo/ops/cargo_compile/unit_generator.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ impl<'a> UnitGenerator<'a, '_> {
171171
/*is_std*/ false,
172172
/*dep_hash*/ 0,
173173
IsArtifact::No,
174+
None,
174175
)
175176
})
176177
.collect()

0 commit comments

Comments
 (0)