Skip to content

Commit 23460ab

Browse files
committed
handle no_std targets on std builds
This change unifies the `Step::run_make` logic and improves it by skipping std specific crates for no_std targets. Signed-off-by: onur-ozkan <[email protected]>
1 parent d53dc75 commit 23460ab

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Implementation of compiling the compiler and standard library, in "check"-based modes.
22
33
use crate::core::build_steps::compile::{
4-
add_to_sysroot, run_cargo, rustc_cargo, rustc_cargo_env, std_cargo,
4+
add_to_sysroot, run_cargo, rustc_cargo, rustc_cargo_env, std_cargo, std_crates_for_run_make,
55
};
66
use crate::core::build_steps::tool::{prepare_tool_cargo, SourceType};
77
use crate::core::builder::{
@@ -47,7 +47,7 @@ impl Step for Std {
4747
}
4848

4949
fn make_run(run: RunConfig<'_>) {
50-
let crates = run.make_run_crates(Alias::Library);
50+
let crates = std_crates_for_run_make(&run);
5151
run.builder.ensure(Std { target: run.target, crates });
5252
}
5353

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use super::compile::libstd_stamp;
2121
use super::compile::run_cargo;
2222
use super::compile::rustc_cargo;
2323
use super::compile::std_cargo;
24+
use super::compile::std_crates_for_run_make;
2425
use super::tool::prepare_tool_cargo;
2526
use super::tool::SourceType;
2627

@@ -122,7 +123,7 @@ impl Step for Std {
122123
}
123124

124125
fn make_run(run: RunConfig<'_>) {
125-
let crates = run.make_run_crates(Alias::Library);
126+
let crates = std_crates_for_run_make(&run);
126127
run.builder.ensure(Std { target: run.target, crates });
127128
}
128129

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

+18-5
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,7 @@ impl Step for Std {
127127
}
128128

129129
fn make_run(run: RunConfig<'_>) {
130-
// If the paths include "library", build the entire standard library.
131-
let has_alias =
132-
run.paths.iter().any(|set| set.assert_single_path().path.ends_with("library"));
133-
let crates = if has_alias { Default::default() } else { run.cargo_crates_in_set() };
134-
130+
let crates = std_crates_for_run_make(&run);
135131
run.builder.ensure(Std {
136132
compiler: run.builder.compiler(run.builder.top_stage, run.build_triple()),
137133
target: run.target,
@@ -424,6 +420,23 @@ fn copy_self_contained_objects(
424420
target_deps
425421
}
426422

423+
/// Resolves standard library crates for `Std::run_make` for any build kind (like check, build, clippy, etc.).
424+
pub fn std_crates_for_run_make(run: &RunConfig<'_>) -> Vec<String> {
425+
let has_alias = run.paths.iter().any(|set| set.assert_single_path().path.ends_with("library"));
426+
let target_is_no_std = run.builder.no_std(run.target).unwrap_or(false);
427+
428+
// For no_std targets, do not add any additional crates to the compilation other than what `compile::std_cargo` already adds for no_std targets.
429+
if target_is_no_std {
430+
vec![]
431+
}
432+
// If the paths include "library", build the entire standard library.
433+
else if has_alias {
434+
run.make_run_crates(builder::Alias::Library)
435+
} else {
436+
run.cargo_crates_in_set()
437+
}
438+
}
439+
427440
/// Configure cargo to compile the standard library, adding appropriate env vars
428441
/// and such.
429442
pub fn std_cargo(builder: &Builder<'_>, target: TargetSelection, stage: u32, cargo: &mut Cargo) {

0 commit comments

Comments
 (0)