Skip to content

Commit 0149bca

Browse files
committed
fix(build-std): behavior revert of 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 f004691 commit 0149bca

File tree

4 files changed

+35
-14
lines changed

4 files changed

+35
-14
lines changed

src/cargo/core/compiler/standard_lib.rs

+19-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,21 @@ 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 anything looks like needing std, resolve with it.
74+
// If not, we assume only `core` maye be needed, as `core the most fundamental crate.
75+
//
76+
// This may need a UI overhaul if `build-std` wants to fully support multi-targets.
77+
let maybe_std = kinds
78+
.iter()
79+
.any(|kind| target_data.info(*kind).maybe_support_std());
80+
let mut crates = std_crates(crates, if maybe_std { "std" } else { "core" }, &[]);
81+
// `sysroot` is not in the default set because it is optional, but it needs
82+
// to be part of the resolve in case we do need it or `libtest`.
83+
crates.insert("sysroot");
84+
let specs = Packages::Packages(crates.into_iter().map(Into::into).collect());
85+
specs.to_package_id_specs(&std_ws)?
86+
};
7287
let features = match &gctx.cli_unstable().build_std_features {
7388
Some(list) => list.clone(),
7489
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
@@ -438,10 +438,5 @@ fn test_panic_abort() {
438438
.build_std_arg("std,panic_abort")
439439
.env("RUSTFLAGS", "-C panic=abort")
440440
.arg("-Zbuild-std-features=panic_immediate_abort")
441-
.with_status(101)
442-
.with_stderr_data(str![[r#"
443-
[ERROR] package ID specification `panic_unwind` did not match any packages
444-
445-
"#]])
446441
.run();
447442
}

0 commit comments

Comments
 (0)