Skip to content

Commit b6c2c47

Browse files
committed
Adopt std roots generations to use explicit_kinds method
1 parent 6f56670 commit b6c2c47

File tree

2 files changed

+39
-26
lines changed

2 files changed

+39
-26
lines changed

src/cargo/core/compiler/standard_lib.rs

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use crate::core::resolver::HasDevUnits;
88
use crate::core::{Dependency, PackageId, PackageSet, Resolve, SourceId, Workspace};
99
use crate::ops::{self, Packages};
1010
use crate::util::errors::CargoResult;
11+
use std::collections::hash_map::Entry;
1112
use std::collections::{HashMap, HashSet};
1213
use std::env;
1314
use std::path::PathBuf;
@@ -133,7 +134,8 @@ pub fn generate_std_roots(
133134
crates: &[String],
134135
std_resolve: &Resolve,
135136
std_features: &ResolvedFeatures,
136-
kinds: &[CompileKind],
137+
requested_kinds: &[CompileKind],
138+
explicit_host_kind: CompileKind,
137139
package_set: &PackageSet<'_>,
138140
interner: &UnitInterner,
139141
profiles: &Profiles,
@@ -147,41 +149,51 @@ pub fn generate_std_roots(
147149
let std_pkgs = package_set.get_many(std_ids)?;
148150
// Generate a map of Units for each kind requested.
149151
let mut ret = HashMap::new();
150-
for pkg in std_pkgs {
152+
153+
let std_pkg_infos: Vec<_> = std_pkgs.iter().map(|pkg| {
151154
let lib = pkg
152155
.targets()
153156
.iter()
154157
.find(|t| t.is_lib())
155158
.expect("std has a lib");
156159
let unit_for = UnitFor::new_normal();
157-
// I don't think we need to bother with Check here, the difference
158-
// in time is minimal, and the difference in caching is
159-
// significant.
160-
let mode = CompileMode::Build;
161160
let features = std_features.activated_features(pkg.package_id(), FeaturesFor::NormalOrDev);
161+
(pkg, lib, unit_for, features)
162+
}).collect();
162163

164+
for kinds in package_set.packages().map(|pkg| pkg.explicit_kinds(requested_kinds, explicit_host_kind)) {
163165
for kind in kinds {
164-
let list = ret.entry(*kind).or_insert_with(Vec::new);
165-
let profile = profiles.get_profile(
166-
pkg.package_id(),
167-
/*is_member*/ false,
168-
/*is_local*/ false,
169-
unit_for,
170-
mode,
171-
*kind,
172-
);
173-
list.push(interner.intern(
174-
pkg,
175-
lib,
176-
profile,
177-
*kind,
178-
mode,
179-
features.clone(),
180-
/*is_std*/ true,
181-
/*dep_hash*/ 0,
182-
));
166+
if let Entry::Vacant(e) = ret.entry(kind) {
167+
let units = std_pkg_infos.iter().map(|(pkg, lib, unit_for, features)| {
168+
// I don't think we need to bother with Check here, the difference
169+
// in time is minimal, and the difference in caching is
170+
// significant.
171+
let mode = CompileMode::Build;
172+
let profile = profiles.get_profile(
173+
pkg.package_id(),
174+
/*is_member*/ false,
175+
/*is_local*/ false,
176+
*unit_for,
177+
mode,
178+
kind,
179+
);
180+
interner.intern(
181+
pkg,
182+
lib,
183+
profile,
184+
kind,
185+
mode,
186+
features.clone(),
187+
/*is_std*/ true,
188+
/*dep_hash*/ 0,
189+
)
190+
});
191+
192+
e.insert(units.collect());
193+
}
183194
}
184195
}
196+
185197
Ok(ret)
186198
}
187199

src/cargo/ops/cargo_compile.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,8 @@ pub fn create_bcx<'a, 'cfg>(
562562
&crates,
563563
std_resolve,
564564
std_features,
565-
&explicit_host_kinds,
565+
&build_config.requested_kinds,
566+
explicit_host_kind,
566567
&pkg_set,
567568
interner,
568569
&profiles,

0 commit comments

Comments
 (0)