Skip to content

Commit 6e24719

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 a5ee5cb commit 6e24719

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
@@ -3,7 +3,7 @@
33
use std::path::PathBuf;
44

55
use crate::core::build_steps::compile::{
6-
add_to_sysroot, run_cargo, rustc_cargo, rustc_cargo_env, std_cargo,
6+
add_to_sysroot, run_cargo, rustc_cargo, rustc_cargo_env, std_cargo, std_crates_for_run_make,
77
};
88
use crate::core::build_steps::tool::{prepare_tool_cargo, SourceType};
99
use crate::core::builder::{
@@ -49,7 +49,7 @@ impl Step for Std {
4949
}
5050

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

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use super::compile::{librustc_stamp, libstd_stamp, run_cargo, rustc_cargo, std_c
44
use super::tool::{prepare_tool_cargo, SourceType};
55
use super::{check, compile};
66
use crate::builder::{Builder, ShouldRun};
7+
use crate::core::build_steps::compile::std_crates_for_run_make;
78
use crate::core::builder;
89
use crate::core::builder::{crate_description, Alias, Kind, RunConfig, Step};
910
use crate::{Mode, Subcommand, TargetSelection};
@@ -106,7 +107,7 @@ impl Step for Std {
106107
}
107108

108109
fn make_run(run: RunConfig<'_>) {
109-
let crates = run.make_run_crates(Alias::Library);
110+
let crates = std_crates_for_run_make(&run);
110111
run.builder.ensure(Std { target: run.target, crates });
111112
}
112113

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

+18-5
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,7 @@ impl Step for Std {
123123
}
124124

125125
fn make_run(run: RunConfig<'_>) {
126-
// If the paths include "library", build the entire standard library.
127-
let has_alias =
128-
run.paths.iter().any(|set| set.assert_single_path().path.ends_with("library"));
129-
let crates = if has_alias { Default::default() } else { run.cargo_crates_in_set() };
130-
126+
let crates = std_crates_for_run_make(&run);
131127
run.builder.ensure(Std {
132128
compiler: run.builder.compiler(run.builder.top_stage, run.build_triple()),
133129
target: run.target,
@@ -425,6 +421,23 @@ fn copy_self_contained_objects(
425421
target_deps
426422
}
427423

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

0 commit comments

Comments
 (0)