Skip to content

Commit 0802d22

Browse files
committed
fix(build-std): remove std unsupported check
Will let `std:bool` to determine necessary deps for `-Zbuild-std`, instead of erroring out.
1 parent 2549ce4 commit 0802d22

File tree

4 files changed

+31
-24
lines changed

4 files changed

+31
-24
lines changed

src/cargo/core/compiler/standard_lib.rs

-14
Original file line numberDiff line numberDiff line change
@@ -51,27 +51,13 @@ pub fn resolve_std<'gctx>(
5151
ws: &Workspace<'gctx>,
5252
target_data: &mut RustcTargetData<'gctx>,
5353
build_config: &BuildConfig,
54-
crates: &[String],
5554
) -> CargoResult<(PackageSet<'gctx>, Resolve, ResolvedFeatures)> {
56-
let crates = std_crates(crates, None);
57-
5855
if build_config.build_plan {
5956
ws.gctx()
6057
.shell()
6158
.warn("-Zbuild-std does not currently fully support --build-plan")?;
6259
}
6360

64-
// check that targets support building std
65-
if crates.contains("std") {
66-
let unsupported_targets = target_data.get_unsupported_std_targets();
67-
if !unsupported_targets.is_empty() {
68-
anyhow::bail!(
69-
"building std is not supported on the following targets: {}",
70-
unsupported_targets.join(", ")
71-
)
72-
}
73-
}
74-
7561
let src_path = detect_sysroot_src_path(target_data)?;
7662
let std_ws_manifest_path = src_path.join("Cargo.toml");
7763
let gctx = ws.gctx();

src/cargo/ops/cargo_compile/mod.rs

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

292-
let std_resolve_features = if let Some(crates) = &gctx.cli_unstable().build_std {
292+
let std_resolve_features = if gctx.cli_unstable().build_std.is_some() {
293293
let (std_package_set, std_resolve, std_features) =
294-
standard_lib::resolve_std(ws, &mut target_data, &build_config, crates)?;
294+
standard_lib::resolve_std(ws, &mut target_data, &build_config)?;
295295
pkg_set.add_set(std_package_set);
296296
Some((std_resolve, std_features))
297297
} else {

src/cargo/ops/cargo_fetch.rs

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

6666
// If -Zbuild-std was passed, download dependencies for the standard library.
67-
if let Some(crates) = gctx.cli_unstable().build_std.as_ref() {
68-
let (std_package_set, _, _) =
69-
standard_lib::resolve_std(ws, &mut data, &build_config, &crates)?;
67+
if gctx.cli_unstable().build_std.is_some() {
68+
let (std_package_set, _, _) = standard_lib::resolve_std(ws, &mut data, &build_config)?;
7069
packages.add_set(std_package_set);
7170
}
7271

tests/testsuite/standard_lib.rs

+27-5
Original file line numberDiff line numberDiff line change
@@ -389,8 +389,29 @@ fn check_core() {
389389
.run();
390390
}
391391

392-
#[cargo_test(build_std_mock)]
393-
fn test_std_on_unsupported_target() {
392+
#[cargo_test(build_std_mock, requires = "rustup")]
393+
fn build_std_with_no_arg_for_core_only_target() {
394+
let has_rustup_aarch64_unknown_none = std::process::Command::new("rustup")
395+
.args(["target", "list", "--installed"])
396+
.output()
397+
.ok()
398+
.map(|output| {
399+
String::from_utf8(output.stdout)
400+
.map(|stdout| stdout.contains("aarch64-unknown-none"))
401+
.unwrap_or_default()
402+
})
403+
.unwrap_or_default();
404+
if !has_rustup_aarch64_unknown_none {
405+
let msg =
406+
"to run this test, run `rustup target add aarch64-unknown-none --toolchain nightly`";
407+
if cargo_util::is_ci() {
408+
panic!("{msg}");
409+
} else {
410+
eprintln!("{msg}");
411+
}
412+
return;
413+
}
414+
394415
let setup = setup();
395416

396417
let p = project()
@@ -405,13 +426,14 @@ fn test_std_on_unsupported_target() {
405426
)
406427
.build();
407428

408-
p.cargo("build")
429+
p.cargo("build -v")
409430
.arg("--target=aarch64-unknown-none")
410-
.arg("--target=x86_64-unknown-none")
411431
.build_std(&setup)
412432
.with_status(101)
413433
.with_stderr_data(str![[r#"
414-
[ERROR] building std is not supported on the following targets: [..]
434+
...
435+
error[E0463]: can't find crate for `std`
436+
...
415437
"#]])
416438
.run();
417439
}

0 commit comments

Comments
 (0)