Skip to content

Commit 95724a1

Browse files
committed
don't try to attach roots for non-config'd targets
1 parent b4d9a73 commit 95724a1

File tree

3 files changed

+87
-83
lines changed

3 files changed

+87
-83
lines changed

src/cargo/core/compiler/unit_dependencies.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -177,16 +177,19 @@ fn attach_std_deps(
177177
let mut found = false;
178178
for (unit, deps) in state.unit_dependencies.iter_mut() {
179179
if !unit.kind.is_host() && !unit.mode.is_run_custom_build() {
180-
deps.extend(std_roots[&unit.kind].iter().map(|unit| UnitDep {
181-
unit: unit.clone(),
182-
unit_for: UnitFor::new_normal(unit.kind),
183-
extern_crate_name: unit.pkg.name(),
184-
dep_name: None,
185-
// TODO: Does this `public` make sense?
186-
public: true,
187-
noprelude: true,
188-
}));
189-
found = true;
180+
// only attach roots for which the user has requested `build-std` for.
181+
if let Some(roots) = std_roots.get(&unit.kind) {
182+
deps.extend(roots.iter().map(|unit| UnitDep {
183+
unit: unit.clone(),
184+
unit_for: UnitFor::new_normal(unit.kind),
185+
extern_crate_name: unit.pkg.name(),
186+
dep_name: None,
187+
// TODO: Does this `public` make sense?
188+
public: true,
189+
noprelude: true,
190+
}));
191+
found = true;
192+
}
190193
}
191194
}
192195
// And also include the dependencies of the standard library itself. Don't

tests/build-std/main.rs

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#![allow(clippy::disallowed_methods)]
2222

2323
use cargo_test_support::prelude::*;
24-
use cargo_test_support::{basic_manifest, paths, project, rustc_host, str, Execs};
24+
use cargo_test_support::{basic_manifest, cross_compile, paths, project, rustc_host, str, Execs};
2525
use std::env;
2626
use std::path::Path;
2727

@@ -441,3 +441,76 @@ fn test_panic_abort() {
441441
.arg("-Zbuild-std-features=panic_immediate_abort")
442442
.run();
443443
}
444+
445+
446+
#[cargo_test(build_std_real)]
447+
fn bindeps() {
448+
if !cross_compile::requires_target_installed("aarch64-unknown-none") {
449+
return;
450+
}
451+
452+
let p = project()
453+
.file(
454+
"Cargo.toml",
455+
&r#"
456+
[package]
457+
name = "foo"
458+
version = "0.1.0"
459+
edition = "2021"
460+
authors = []
461+
resolver = "2"
462+
463+
[dependencies]
464+
bar = { path = "bar/", artifact = "staticlib", target = "aarch64-unknown-none" }
465+
"#,
466+
)
467+
.file("src/lib.rs", "")
468+
.file(
469+
"bar/Cargo.toml",
470+
r#"
471+
[package]
472+
name = "bar"
473+
version = "0.5.0"
474+
edition = "2021"
475+
476+
[lib]
477+
crate-type = ["staticlib"]
478+
"#,
479+
)
480+
.file(
481+
"bar/src/lib.rs",
482+
r#"
483+
#![no_std]
484+
pub fn bar() {}
485+
#[panic_handler]
486+
fn panic(info: &core::panic::PanicInfo) -> ! {
487+
loop {}
488+
}
489+
"#,
490+
)
491+
.file(
492+
".cargo/config.toml",
493+
&format!(
494+
r#"
495+
[target.aarch64-unknown-none]
496+
build-std = ['core']
497+
"#
498+
),
499+
)
500+
.build();
501+
let mut build = p.cargo("build -v --lib -Zunstable-options -Zbindeps");
502+
build
503+
.target_host()
504+
.masquerade_as_nightly_cargo(&["build-std"])
505+
.with_stderr_data(
506+
str![[r#"
507+
...
508+
[RUNNING] `rustc --crate-name bar [..]--target aarch64-unknown-none[..]
509+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
510+
511+
"#]]
512+
.unordered(),
513+
);
514+
515+
build.run();
516+
}

tests/testsuite/standard_lib.rs

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,75 +1037,3 @@ error[E0463]: can't find crate for `core`
10371037

10381038
build.run();
10391039
}
1040-
1041-
#[cargo_test(build_std_mock)]
1042-
fn bindeps() {
1043-
if !cross_compile::requires_target_installed("aarch64-unknown-none") {
1044-
return;
1045-
}
1046-
1047-
let p = project()
1048-
.file(
1049-
"Cargo.toml",
1050-
&r#"
1051-
[package]
1052-
name = "foo"
1053-
version = "0.1.0"
1054-
edition = "2021"
1055-
authors = []
1056-
resolver = "2"
1057-
1058-
[dependencies]
1059-
bar = { path = "bar/", artifact = "staticlib", target = "aarch64-unknown-none" }
1060-
"#,
1061-
)
1062-
.file("src/lib.rs", "")
1063-
.file(
1064-
"bar/Cargo.toml",
1065-
r#"
1066-
[package]
1067-
name = "bar"
1068-
version = "0.5.0"
1069-
edition = "2021"
1070-
1071-
[lib]
1072-
crate-type = ["staticlib"]
1073-
"#,
1074-
)
1075-
.file(
1076-
"bar/src/lib.rs",
1077-
r#"
1078-
#![no_std]
1079-
pub fn bar() {}
1080-
#[panic_handler]
1081-
fn panic(info: &core::panic::PanicInfo) -> ! {
1082-
loop {}
1083-
}
1084-
"#,
1085-
)
1086-
.file(
1087-
".cargo/config.toml",
1088-
&format!(
1089-
r#"
1090-
[target.aarch64-unknown-none]
1091-
build-std = ['core']
1092-
"#
1093-
),
1094-
)
1095-
.build();
1096-
let mut build = p.cargo("build -v --lib -Zunstable-options -Zbindeps");
1097-
build
1098-
.target_host()
1099-
.masquerade_as_nightly_cargo(&["build-std"])
1100-
.with_stderr_data(
1101-
str![[r#"
1102-
...
1103-
[RUNNING] `rustc --crate-name bar [..]--target aarch64-unknown-none[..]
1104-
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
1105-
1106-
"#]]
1107-
.unordered(),
1108-
);
1109-
1110-
build.run();
1111-
}

0 commit comments

Comments
 (0)