Skip to content

Commit 93da892

Browse files
committed
Move build-std to Cargo.toml
1 parent 95bb3c9 commit 93da892

File tree

11 files changed

+570
-308
lines changed

11 files changed

+570
-308
lines changed

src/cargo/core/compiler/build_context/target_info.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,10 @@ impl<'cfg> RustcTargetData<'cfg> {
823823
}
824824
}
825825

826+
pub fn requested_kinds(&self) -> &[CompileKind] {
827+
&self.requested_kinds
828+
}
829+
826830
/// If a build script is overridden, this returns the `BuildOutput` to use.
827831
///
828832
/// `lib_name` is the `links` library name and `kind` is whether it is for

src/cargo/core/compiler/compilation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ impl<'cfg> Compilation<'cfg> {
277277
// libs from the sysroot that ships with rustc. This may not be
278278
// required (at least I cannot craft a situation where it
279279
// matters), but is here to be safe.
280-
if self.config.cli_unstable().build_std.is_none() {
280+
if pkg.manifest().build_std().is_none() {
281281
search_path.push(self.sysroot_target_libdir[&kind].clone());
282282
}
283283
}

src/cargo/core/compiler/standard_lib.rs

Lines changed: 72 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,12 @@ pub fn resolve_std<'cfg>(
3535
ws: &Workspace<'cfg>,
3636
target_data: &RustcTargetData<'cfg>,
3737
requested_targets: &[CompileKind],
38-
crates: &[String],
39-
) -> CargoResult<(PackageSet<'cfg>, Resolve, ResolvedFeatures)> {
38+
crates_and_features: HashMap<CompileKind, (HashSet<&str>, HashSet<&str>)>,
39+
) -> CargoResult<(
40+
PackageSet<'cfg>,
41+
HashMap<CompileKind, (Resolve, ResolvedFeatures)>,
42+
)> {
43+
let mut pkg_set: Option<PackageSet<'cfg>> = None;
4044
let src_path = detect_sysroot_src_path(target_data)?;
4145
let to_patch = [
4246
"rustc-std-workspace-core",
@@ -93,60 +97,68 @@ pub fn resolve_std<'cfg>(
9397
// `[dev-dependencies]`. No need for us to generate a `Resolve` which has
9498
// those included because we'll never use them anyway.
9599
std_ws.set_require_optional_deps(false);
96-
// `test` is not in the default set because it is optional, but it needs
97-
// to be part of the resolve in case we do need it.
98-
let mut spec_pkgs = Vec::from(crates);
99-
spec_pkgs.push("test".to_string());
100-
let spec = Packages::Packages(spec_pkgs);
101-
let specs = spec.to_package_id_specs(&std_ws)?;
102-
let features = match &config.cli_unstable().build_std_features {
103-
Some(list) => list.clone(),
104-
None => vec![
105-
"panic-unwind".to_string(),
106-
"backtrace".to_string(),
107-
"default".to_string(),
108-
],
109-
};
110-
let cli_features = CliFeatures::from_command_line(
111-
&features, /*all_features*/ false, /*uses_default_features*/ false,
112-
)?;
113-
let resolve = ops::resolve_ws_with_opts(
114-
&std_ws,
115-
target_data,
116-
requested_targets,
117-
&cli_features,
118-
&specs,
119-
HasDevUnits::No,
120-
crate::core::resolver::features::ForceAllTargets::No,
121-
)?;
122-
Ok((
123-
resolve.pkg_set,
124-
resolve.targeted_resolve,
125-
resolve.resolved_features,
126-
))
100+
101+
let ret: CargoResult<_> = crates_and_features
102+
.into_iter()
103+
.map(|(kind, (crates, features))| {
104+
// `test` is not in the default set because it is optional, but it needs
105+
// to be part of the resolve in case we do need it.
106+
let spec_pkgs: Vec<_> = crates
107+
.into_iter()
108+
.chain(Some("test"))
109+
.map(ToOwned::to_owned)
110+
.collect();
111+
let spec = Packages::Packages(spec_pkgs);
112+
let specs = spec.to_package_id_specs(&std_ws)?;
113+
let features: Vec<_> = features.into_iter().map(ToOwned::to_owned).collect();
114+
let cli_features = CliFeatures::from_command_line(
115+
&features, /*all_features*/ false, /*uses_default_features*/ false,
116+
)?;
117+
let resolve = ops::resolve_ws_with_opts(
118+
&std_ws,
119+
target_data,
120+
requested_targets,
121+
&cli_features,
122+
&specs,
123+
HasDevUnits::No,
124+
crate::core::resolver::features::ForceAllTargets::No,
125+
)?;
126+
127+
match &mut pkg_set {
128+
Some(pkg_set) => pkg_set.add_set(resolve.pkg_set),
129+
pkg_set => *pkg_set = Some(resolve.pkg_set),
130+
}
131+
132+
Ok((kind, (resolve.targeted_resolve, resolve.resolved_features)))
133+
})
134+
.collect();
135+
136+
Ok((pkg_set.unwrap(), ret?))
127137
}
128138

129139
/// Generate a list of root `Unit`s for the standard library.
130140
///
131141
/// The given slice of crate names is the root set.
132-
pub fn generate_std_roots(
142+
pub fn generate_std_units(
133143
crates: &[String],
134-
std_resolve: &Resolve,
135-
std_features: &ResolvedFeatures,
136-
kinds: &[CompileKind],
144+
std_resolve: &HashMap<CompileKind, (Resolve, ResolvedFeatures)>,
145+
kind: CompileKind,
137146
package_set: &PackageSet<'_>,
138147
interner: &UnitInterner,
139148
profiles: &Profiles,
140-
) -> CargoResult<HashMap<CompileKind, Vec<Unit>>> {
149+
) -> CargoResult<Vec<Unit>> {
150+
let (std_resolve, std_features) = &std_resolve[&kind];
141151
// Generate the root Units for the standard library.
142152
let std_ids = crates
143153
.iter()
144154
.map(|crate_name| std_resolve.query(crate_name))
145155
.collect::<CargoResult<Vec<PackageId>>>()?;
156+
146157
// Convert PackageId to Package.
147158
let std_pkgs = package_set.get_many(std_ids)?;
148-
// Generate a map of Units for each kind requested.
149-
let mut ret = HashMap::new();
159+
160+
let mut list = Vec::new();
161+
150162
for pkg in std_pkgs {
151163
let lib = pkg
152164
.targets()
@@ -160,29 +172,27 @@ pub fn generate_std_roots(
160172
let mode = CompileMode::Build;
161173
let features = std_features.activated_features(pkg.package_id(), FeaturesFor::NormalOrDev);
162174

163-
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-
));
183-
}
175+
let profile = profiles.get_profile(
176+
pkg.package_id(),
177+
/*is_member*/ false,
178+
/*is_local*/ false,
179+
unit_for,
180+
mode,
181+
kind,
182+
);
183+
list.push(interner.intern(
184+
pkg,
185+
lib,
186+
profile,
187+
kind,
188+
mode,
189+
features.clone(),
190+
/*is_std*/ true,
191+
/*dep_hash*/ 0,
192+
));
184193
}
185-
Ok(ret)
194+
195+
Ok(list)
186196
}
187197

188198
fn detect_sysroot_src_path(target_data: &RustcTargetData<'_>) -> CargoResult<PathBuf> {

0 commit comments

Comments
 (0)