Skip to content

Commit

Permalink
fix(build-std): remove std unsupported check
Browse files Browse the repository at this point in the history
Will let `std:bool` to determine necessary deps for `-Zbuild-std`,
instead of erroring out.
  • Loading branch information
weihanglo committed Dec 5, 2024
1 parent 2549ce4 commit 65572aa
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 23 deletions.
14 changes: 0 additions & 14 deletions src/cargo/core/compiler/standard_lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,27 +51,13 @@ pub fn resolve_std<'gctx>(
ws: &Workspace<'gctx>,
target_data: &mut RustcTargetData<'gctx>,
build_config: &BuildConfig,
crates: &[String],
) -> CargoResult<(PackageSet<'gctx>, Resolve, ResolvedFeatures)> {
let crates = std_crates(crates, None);

if build_config.build_plan {
ws.gctx()
.shell()
.warn("-Zbuild-std does not currently fully support --build-plan")?;
}

// check that targets support building std
if crates.contains("std") {
let unsupported_targets = target_data.get_unsupported_std_targets();
if !unsupported_targets.is_empty() {
anyhow::bail!(
"building std is not supported on the following targets: {}",
unsupported_targets.join(", ")
)
}
}

let src_path = detect_sysroot_src_path(target_data)?;
let std_ws_manifest_path = src_path.join("Cargo.toml");
let gctx = ws.gctx();
Expand Down
4 changes: 2 additions & 2 deletions src/cargo/ops/cargo_compile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,9 @@ pub fn create_bcx<'a, 'gctx>(
resolved_features,
} = resolve;

let std_resolve_features = if let Some(crates) = &gctx.cli_unstable().build_std {
let std_resolve_features = if gctx.cli_unstable().build_std.is_some() {
let (std_package_set, std_resolve, std_features) =
standard_lib::resolve_std(ws, &mut target_data, &build_config, crates)?;
standard_lib::resolve_std(ws, &mut target_data, &build_config)?;
pkg_set.add_set(std_package_set);
Some((std_resolve, std_features))
} else {
Expand Down
5 changes: 2 additions & 3 deletions src/cargo/ops/cargo_fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,8 @@ pub fn fetch<'a>(
}

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

Expand Down
22 changes: 18 additions & 4 deletions tests/testsuite/standard_lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,20 @@ fn check_core() {
}

#[cargo_test(build_std_mock)]
fn test_std_on_unsupported_target() {
fn build_std_with_no_arg_for_core_only_target() {
let output = std::process::Command::new("rustup")
.args(["target", "list", "--installed"])
.output()
.expect("failed to run `rustup target list --installed`");
if !String::from_utf8(output.stdout)
.map(|stdout| stdout.contains("aarch64-unknown-none"))
.unwrap_or_default()
{
panic!(
"to run this test, run `rustup target add aarch64-unknown-none --toolchain nightly`"
);
}

let setup = setup();

let p = project()
Expand All @@ -405,13 +418,14 @@ fn test_std_on_unsupported_target() {
)
.build();

p.cargo("build")
p.cargo("build -v")
.arg("--target=aarch64-unknown-none")
.arg("--target=x86_64-unknown-none")
.build_std(&setup)
.with_status(101)
.with_stderr_data(str![[r#"
[ERROR] building std is not supported on the following targets: [..]
...
error[E0463]: can't find crate for `std`
...
"#]])
.run();
}
Expand Down

0 comments on commit 65572aa

Please sign in to comment.