Skip to content

Commit 3f8d809

Browse files
committed
Don't unconditionally build alloc for no-std targets
It's possible for targets to only support `core` and not `alloc`. Instead of building alloc unconditionally, pass a list of crates to build into `std_cargo`, and only pass `-p alloc` if the list of crates wasn't already filtered to a subset. The original use case was to reuse `std_cargo` for a rustc_driver that doesn't emit metadata. But this seems like a reasonable change regardless.
1 parent dc2c356 commit 3f8d809

File tree

5 files changed

+17
-30
lines changed

5 files changed

+17
-30
lines changed

src/bootstrap/src/core/build_steps/check.rs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,12 @@ impl Step for Std {
8383
Kind::Check,
8484
);
8585

86-
std_cargo(builder, target, &mut cargo);
86+
std_cargo(builder, target, &mut cargo, &self.crates);
8787
if matches!(builder.config.cmd, Subcommand::Fix) {
8888
// By default, cargo tries to fix all targets. Tell it not to fix tests until we've added `test` to the sysroot.
8989
cargo.arg("--lib");
9090
}
9191

92-
for krate in &*self.crates {
93-
cargo.arg("-p").arg(krate);
94-
}
95-
9692
let _guard = builder.msg(
9793
Kind::Check,
9894
format_args!("library artifacts{}", crate_description(&self.crates)),
@@ -135,14 +131,7 @@ impl Step for Std {
135131
Kind::Check,
136132
);
137133

138-
std_cargo(builder, target, &mut cargo);
139-
140-
// Explicitly pass -p for all dependencies krates -- this will force cargo
141-
// to also check the tests/benches/examples for these crates, rather
142-
// than just the leaf crate.
143-
for krate in &*self.crates {
144-
cargo.arg("-p").arg(krate);
145-
}
134+
std_cargo(builder, target, &mut cargo, &self.crates);
146135

147136
let stamp =
148137
build_stamp::libstd_stamp(builder, build_compiler, target).with_prefix("check-test");

src/bootstrap/src/core/build_steps/clippy.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,7 @@ impl Step for Std {
195195
Kind::Clippy,
196196
);
197197

198-
std_cargo(builder, target, &mut cargo);
199-
200-
for krate in &*self.crates {
201-
cargo.arg("-p").arg(krate);
202-
}
198+
std_cargo(builder, target, &mut cargo, &self.crates);
203199

204200
let _guard = builder.msg(
205201
Kind::Clippy,

src/bootstrap/src/core/build_steps/compile.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -266,10 +266,7 @@ impl Step for Std {
266266
target,
267267
Kind::Build,
268268
);
269-
std_cargo(builder, target, &mut cargo);
270-
for krate in &*self.crates {
271-
cargo.arg("-p").arg(krate);
272-
}
269+
std_cargo(builder, target, &mut cargo, &self.crates);
273270
cargo
274271
};
275272

@@ -497,7 +494,7 @@ fn compiler_rt_for_profiler(builder: &Builder<'_>) -> PathBuf {
497494

498495
/// Configure cargo to compile the standard library, adding appropriate env vars
499496
/// and such.
500-
pub fn std_cargo(builder: &Builder<'_>, target: TargetSelection, cargo: &mut Cargo) {
497+
pub fn std_cargo(builder: &Builder<'_>, target: TargetSelection, cargo: &mut Cargo, crates: &[String]) {
501498
// rustc already ensures that it builds with the minimum deployment
502499
// target, so ideally we shouldn't need to do anything here.
503500
//
@@ -605,6 +602,13 @@ pub fn std_cargo(builder: &Builder<'_>, target: TargetSelection, cargo: &mut Car
605602
cargo.env("CFG_DISABLE_UNSTABLE_FEATURES", "1");
606603
}
607604

605+
// Explicitly pass -p for all dependencies crates -- this will force cargo
606+
// to also check the tests/benches/examples for these crates, rather
607+
// than just the leaf crate.
608+
for krate in crates {
609+
cargo.args(["-p", krate]);
610+
}
611+
608612
let mut features = String::new();
609613

610614
if builder.no_std(target) == Some(true) {
@@ -614,8 +618,10 @@ pub fn std_cargo(builder: &Builder<'_>, target: TargetSelection, cargo: &mut Car
614618
}
615619

616620
// for no-std targets we only compile a few no_std crates
621+
if crates.is_empty() {
622+
cargo.args(["-p", "alloc"]);
623+
}
617624
cargo
618-
.args(["-p", "alloc"])
619625
.arg("--manifest-path")
620626
.arg(builder.src.join("library/alloc/Cargo.toml"))
621627
.arg("--features")

src/bootstrap/src/core/build_steps/doc.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,7 @@ fn doc_std(
783783
Kind::Doc,
784784
);
785785

786-
compile::std_cargo(builder, target, &mut cargo);
786+
compile::std_cargo(builder, target, &mut cargo, &requested_crates);
787787
cargo
788788
.arg("--no-deps")
789789
.arg("--target-dir")
@@ -803,10 +803,6 @@ fn doc_std(
803803
cargo.rustdocflag("--document-private-items").rustdocflag("--document-hidden-items");
804804
}
805805

806-
for krate in requested_crates {
807-
cargo.arg("-p").arg(krate);
808-
}
809-
810806
let description =
811807
format!("library{} in {} format", crate_description(requested_crates), format.as_str());
812808
let _guard = builder.msg(Kind::Doc, description, Mode::Std, build_compiler, target);

src/bootstrap/src/core/build_steps/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2963,7 +2963,7 @@ impl Step for Crate {
29632963
.arg("--manifest-path")
29642964
.arg(builder.src.join("library/sysroot/Cargo.toml"));
29652965
} else {
2966-
compile::std_cargo(builder, target, &mut cargo);
2966+
compile::std_cargo(builder, target, &mut cargo, &[]);
29672967
}
29682968
}
29692969
Mode::Rustc => {

0 commit comments

Comments
 (0)