Skip to content

Commit 1cd370c

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 125e873 commit 1cd370c

File tree

4 files changed

+38
-33
lines changed

4 files changed

+38
-33
lines changed

src/cargo/core/compiler/standard_lib.rs

+7-23
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use std::path::PathBuf;
1515

1616
use super::BuildConfig;
1717

18-
fn std_crates<'a>(crates: &'a [String], units: Option<&[Unit]>) -> HashSet<&'a str> {
18+
fn std_crates<'a>(crates: &'a [String], units: &[Unit]) -> HashSet<&'a str> {
1919
let mut crates = HashSet::from_iter(crates.iter().map(|s| s.as_str()));
2020
// This is a temporary hack until there is a more principled way to
2121
// declare dependencies in Cargo.toml.
@@ -30,13 +30,11 @@ fn std_crates<'a>(crates: &'a [String], units: Option<&[Unit]>) -> HashSet<&'a s
3030
crates.insert("compiler_builtins");
3131
// Only build libtest if it looks like it is needed (libtest depends on libstd)
3232
// If we know what units we're building, we can filter for libtest depending on the jobs.
33-
if let Some(units) = units {
34-
if units
35-
.iter()
36-
.any(|unit| unit.mode.is_rustc_test() && unit.target.harness())
37-
{
38-
crates.insert("test");
39-
}
33+
if units
34+
.iter()
35+
.any(|unit| unit.mode.is_rustc_test() && unit.target.harness())
36+
{
37+
crates.insert("test");
4038
}
4139
} else if crates.contains("core") {
4240
crates.insert("compiler_builtins");
@@ -50,27 +48,13 @@ pub fn resolve_std<'gctx>(
5048
ws: &Workspace<'gctx>,
5149
target_data: &mut RustcTargetData<'gctx>,
5250
build_config: &BuildConfig,
53-
crates: &[String],
5451
) -> CargoResult<(PackageSet<'gctx>, Resolve, ResolvedFeatures)> {
55-
let crates = std_crates(crates, None);
56-
5752
if build_config.build_plan {
5853
ws.gctx()
5954
.shell()
6055
.warn("-Zbuild-std does not currently fully support --build-plan")?;
6156
}
6257

63-
// check that targets support building std
64-
if crates.contains("std") {
65-
let unsupported_targets = target_data.get_unsupported_std_targets();
66-
if !unsupported_targets.is_empty() {
67-
anyhow::bail!(
68-
"building std is not supported on the following targets: {}",
69-
unsupported_targets.join(", ")
70-
)
71-
}
72-
}
73-
7458
let src_path = detect_sysroot_src_path(target_data)?;
7559
let std_ws_manifest_path = src_path.join("Cargo.toml");
7660
let gctx = ws.gctx();
@@ -129,7 +113,7 @@ pub fn generate_std_roots(
129113
profiles: &Profiles,
130114
target_data: &RustcTargetData<'_>,
131115
) -> CargoResult<HashMap<CompileKind, Vec<Unit>>> {
132-
let std_ids = std_crates(crates, Some(units))
116+
let std_ids = std_crates(crates, units)
133117
.iter()
134118
.map(|crate_name| std_resolve.query(crate_name))
135119
.collect::<CargoResult<Vec<PackageId>>>()?;

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)