Skip to content

Commit 9d9ede8

Browse files
authored
Rollup merge of #147168 - jyn514:no-alloc, r=Mark-Simulacrum
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.
2 parents ff6dc92 + 3e26e2a commit 9d9ede8

File tree

5 files changed

+22
-30
lines changed

5 files changed

+22
-30
lines changed

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

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ impl Step for Std {
6161
return;
6262
}
6363

64+
// Explicitly pass -p for all dependencies crates -- this will force cargo
65+
// to also check the tests/benches/examples for these crates, rather
66+
// than just the leaf crate.
6467
let crates = std_crates_for_run_make(&run);
6568
run.builder.ensure(Std {
6669
build_compiler: prepare_compiler_for_check(run.builder, run.target, Mode::Std)
@@ -83,16 +86,12 @@ impl Step for Std {
8386
Kind::Check,
8487
);
8588

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

92-
for krate in &*self.crates {
93-
cargo.arg("-p").arg(krate);
94-
}
95-
9695
let _guard = builder.msg(
9796
Kind::Check,
9897
format_args!("library artifacts{}", crate_description(&self.crates)),
@@ -135,14 +134,7 @@ impl Step for Std {
135134
Kind::Check,
136135
);
137136

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-
}
137+
std_cargo(builder, target, &mut cargo, &self.crates);
146138

147139
let stamp =
148140
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: 14 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

@@ -507,7 +504,12 @@ fn compiler_rt_for_profiler(builder: &Builder<'_>) -> PathBuf {
507504

508505
/// Configure cargo to compile the standard library, adding appropriate env vars
509506
/// and such.
510-
pub fn std_cargo(builder: &Builder<'_>, target: TargetSelection, cargo: &mut Cargo) {
507+
pub fn std_cargo(
508+
builder: &Builder<'_>,
509+
target: TargetSelection,
510+
cargo: &mut Cargo,
511+
crates: &[String],
512+
) {
511513
// rustc already ensures that it builds with the minimum deployment
512514
// target, so ideally we shouldn't need to do anything here.
513515
//
@@ -620,6 +622,10 @@ pub fn std_cargo(builder: &Builder<'_>, target: TargetSelection, cargo: &mut Car
620622
cargo.env("CFG_DISABLE_UNSTABLE_FEATURES", "1");
621623
}
622624

625+
for krate in crates {
626+
cargo.args(["-p", krate]);
627+
}
628+
623629
let mut features = String::new();
624630

625631
if builder.no_std(target) == Some(true) {
@@ -629,8 +635,10 @@ pub fn std_cargo(builder: &Builder<'_>, target: TargetSelection, cargo: &mut Car
629635
}
630636

631637
// for no-std targets we only compile a few no_std crates
638+
if crates.is_empty() {
639+
cargo.args(["-p", "alloc"]);
640+
}
632641
cargo
633-
.args(["-p", "alloc"])
634642
.arg("--manifest-path")
635643
.arg(builder.src.join("library/alloc/Cargo.toml"))
636644
.arg("--features")

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ fn doc_std(
787787
Kind::Doc,
788788
);
789789

790-
compile::std_cargo(builder, target, &mut cargo);
790+
compile::std_cargo(builder, target, &mut cargo, requested_crates);
791791
cargo
792792
.arg("--no-deps")
793793
.arg("--target-dir")
@@ -807,10 +807,6 @@ fn doc_std(
807807
cargo.rustdocflag("--document-private-items").rustdocflag("--document-hidden-items");
808808
}
809809

810-
for krate in requested_crates {
811-
cargo.arg("-p").arg(krate);
812-
}
813-
814810
let description =
815811
format!("library{} in {} format", crate_description(requested_crates), format.as_str());
816812
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
@@ -2977,7 +2977,7 @@ impl Step for Crate {
29772977
.arg("--manifest-path")
29782978
.arg(builder.src.join("library/sysroot/Cargo.toml"));
29792979
} else {
2980-
compile::std_cargo(builder, target, &mut cargo);
2980+
compile::std_cargo(builder, target, &mut cargo, &[]);
29812981
}
29822982
}
29832983
Mode::Rustc => {

0 commit comments

Comments
 (0)