Skip to content

Commit 9d10ede

Browse files
committed
fix(build-std): revert 125e873
This is kinda a revert of 125e873 in terms of the behavior. After this, now `std_resolve` is always resolved by the same set of packages that Cargo will use to generate the unit graph, (technically the same set of crates + `sysroot`), by sharing the same set of primary packages via `std_crates` functions.
1 parent e3d7ee8 commit 9d10ede

File tree

4 files changed

+33
-14
lines changed

4 files changed

+33
-14
lines changed

src/cargo/core/compiler/standard_lib.rs

+17-4
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,14 @@ fn std_crates<'a>(crates: &'a [String], default: &'static str, units: &[Unit]) -
4444
}
4545

4646
/// Resolve the standard library dependencies.
47+
///
48+
/// * `crates` is the arg value from `-Zbuild-std`.
4749
pub fn resolve_std<'gctx>(
4850
ws: &Workspace<'gctx>,
4951
target_data: &mut RustcTargetData<'gctx>,
5052
build_config: &BuildConfig,
53+
crates: &[String],
54+
kinds: &[CompileKind],
5155
) -> CargoResult<(PackageSet<'gctx>, Resolve, ResolvedFeatures)> {
5256
if build_config.build_plan {
5357
ws.gctx()
@@ -65,10 +69,19 @@ pub fn resolve_std<'gctx>(
6569
// `[dev-dependencies]`. No need for us to generate a `Resolve` which has
6670
// those included because we'll never use them anyway.
6771
std_ws.set_require_optional_deps(false);
68-
// `sysroot` + the default feature set below should give us a good default
69-
// Resolve, which includes `libtest` as well.
70-
let specs = Packages::Packages(vec!["sysroot".into()]);
71-
let specs = specs.to_package_id_specs(&std_ws)?;
72+
let specs = {
73+
// If there is any need std, resolve with it.
74+
// This may need a UI overhaul if `build-std` wants to fully support multi-targets.
75+
let core_only = kinds
76+
.iter()
77+
.all(|kind| target_data.info(*kind).support_core_only());
78+
let mut crates = std_crates(crates, if core_only { "core" } else { "std" }, &[]);
79+
// `sysroot` is not in the default set because it is optional, but it needs
80+
// to be part of the resolve in case we do need it or `libtest`.
81+
crates.insert("sysroot");
82+
let specs = Packages::Packages(crates.into_iter().map(Into::into).collect());
83+
specs.to_package_id_specs(&std_ws)?
84+
};
7285
let features = match &gctx.cli_unstable().build_std_features {
7386
Some(list) => list.clone(),
7487
None => vec![

src/cargo/ops/cargo_compile/mod.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -289,9 +289,14 @@ pub fn create_bcx<'a, 'gctx>(
289289
resolved_features,
290290
} = resolve;
291291

292-
let std_resolve_features = if gctx.cli_unstable().build_std.is_some() {
293-
let (std_package_set, std_resolve, std_features) =
294-
standard_lib::resolve_std(ws, &mut target_data, &build_config)?;
292+
let std_resolve_features = if let Some(crates) = &gctx.cli_unstable().build_std {
293+
let (std_package_set, std_resolve, std_features) = standard_lib::resolve_std(
294+
ws,
295+
&mut target_data,
296+
&build_config,
297+
crates,
298+
&build_config.requested_kinds,
299+
)?;
295300
pkg_set.add_set(std_package_set);
296301
Some((std_resolve, std_features))
297302
} else {

src/cargo/ops/cargo_fetch.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,14 @@ pub fn fetch<'a>(
6464
}
6565

6666
// If -Zbuild-std was passed, download dependencies for the standard library.
67-
if gctx.cli_unstable().build_std.is_some() {
68-
let (std_package_set, _, _) = standard_lib::resolve_std(ws, &mut data, &build_config)?;
67+
if let Some(crates) = &gctx.cli_unstable().build_std {
68+
let (std_package_set, _, _) = standard_lib::resolve_std(
69+
ws,
70+
&mut data,
71+
&build_config,
72+
crates,
73+
&build_config.requested_kinds,
74+
)?;
6975
packages.add_set(std_package_set);
7076
}
7177

tests/build-std/main.rs

-5
Original file line numberDiff line numberDiff line change
@@ -422,10 +422,5 @@ fn test_panic_abort() {
422422
.build_std_arg("std,panic_abort")
423423
.env("RUSTFLAGS", "-C panic=abort")
424424
.arg("-Zbuild-std-features=panic_immediate_abort")
425-
.with_status(101)
426-
.with_stderr_data(str![[r#"
427-
[ERROR] package ID specification `panic_unwind` did not match any packages
428-
429-
"#]])
430425
.run();
431426
}

0 commit comments

Comments
 (0)