Skip to content

Commit 4fd5e84

Browse files
authored
Rollup merge of rust-lang#128182 - onur-ozkan:fix-no-std-crates, r=Mark-Simulacrum
handle no_std targets on std builds This PR unifies the `Step::run_make` logic and improves it by skipping std specific crates for no_std targets. In addition, since we now handle library crates properly, bootstrap is capable of running `x doc library` even for no_std targets as it is able to generate documentation for `alloc` crate from the standard library. Resolves rust-lang#128027 cc `@ChrisDenton`
2 parents 63f1692 + 47122e3 commit 4fd5e84

File tree

7 files changed

+31
-34
lines changed

7 files changed

+31
-34
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
@@ -19,6 +19,7 @@ use super::compile::libstd_stamp;
1919
use super::compile::run_cargo;
2020
use super::compile::rustc_cargo;
2121
use super::compile::std_cargo;
22+
use super::compile::std_crates_for_run_make;
2223
use super::tool::prepare_tool_cargo;
2324
use super::tool::SourceType;
2425

@@ -120,7 +121,7 @@ impl Step for Std {
120121
}
121122

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

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

+23-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,
@@ -429,6 +425,28 @@ fn copy_self_contained_objects(
429425
target_deps
430426
}
431427

428+
/// Resolves standard library crates for `Std::run_make` for any build kind (like check, build, clippy, etc.).
429+
pub fn std_crates_for_run_make(run: &RunConfig<'_>) -> Vec<String> {
430+
// FIXME: Extend builder tests to cover the `crates` field of `Std` instances.
431+
if cfg!(feature = "bootstrap-self-test") {
432+
return vec![];
433+
}
434+
435+
let has_alias = run.paths.iter().any(|set| set.assert_single_path().path.ends_with("library"));
436+
let target_is_no_std = run.builder.no_std(run.target).unwrap_or(false);
437+
438+
// 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.
439+
if target_is_no_std {
440+
vec![]
441+
}
442+
// If the paths include "library", build the entire standard library.
443+
else if has_alias {
444+
run.make_run_crates(builder::Alias::Library)
445+
} else {
446+
run.cargo_crates_in_set()
447+
}
448+
}
449+
432450
/// Configure cargo to compile the standard library, adding appropriate env vars
433451
/// and such.
434452
pub fn std_cargo(builder: &Builder<'_>, target: TargetSelection, stage: u32, cargo: &mut Cargo) {

src/bootstrap/src/core/build_steps/dist.rs

-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ impl Step for JsonDocs {
108108
builder.ensure(crate::core::build_steps::doc::Std::new(
109109
builder.top_stage,
110110
host,
111-
builder,
112111
DocumentationFormat::Json,
113112
));
114113

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

+4-20
Original file line numberDiff line numberDiff line change
@@ -563,18 +563,8 @@ pub struct Std {
563563
}
564564

565565
impl Std {
566-
pub(crate) fn new(
567-
stage: u32,
568-
target: TargetSelection,
569-
builder: &Builder<'_>,
570-
format: DocumentationFormat,
571-
) -> Self {
572-
let crates = builder
573-
.in_tree_crates("sysroot", Some(target))
574-
.into_iter()
575-
.map(|krate| krate.name.to_string())
576-
.collect();
577-
Std { stage, target, format, crates }
566+
pub(crate) fn new(stage: u32, target: TargetSelection, format: DocumentationFormat) -> Self {
567+
Std { stage, target, format, crates: vec![] }
578568
}
579569
}
580570

@@ -588,6 +578,7 @@ impl Step for Std {
588578
}
589579

590580
fn make_run(run: RunConfig<'_>) {
581+
let crates = compile::std_crates_for_run_make(&run);
591582
run.builder.ensure(Std {
592583
stage: run.builder.top_stage,
593584
target: run.target,
@@ -596,7 +587,7 @@ impl Step for Std {
596587
} else {
597588
DocumentationFormat::Html
598589
},
599-
crates: run.make_run_crates(Alias::Library),
590+
crates,
600591
});
601592
}
602593

@@ -694,13 +685,6 @@ fn doc_std(
694685
extra_args: &[&str],
695686
requested_crates: &[String],
696687
) {
697-
if builder.no_std(target) == Some(true) {
698-
panic!(
699-
"building std documentation for no_std target {target} is not supported\n\
700-
Set `docs = false` in the config to disable documentation, or pass `--skip library`."
701-
);
702-
}
703-
704688
let compiler = builder.compiler(stage, builder.config.build);
705689

706690
let target_doc_dir_name = if format == DocumentationFormat::Json { "json-doc" } else { "doc" };

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

-1
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,6 @@ impl Step for RustdocJSStd {
852852
builder.ensure(crate::core::build_steps::doc::Std::new(
853853
builder.top_stage,
854854
self.target,
855-
builder,
856855
DocumentationFormat::Html,
857856
));
858857
let _guard = builder.msg(

src/bootstrap/src/core/builder/tests.rs

-4
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,9 @@ macro_rules! std {
7878

7979
macro_rules! doc_std {
8080
($host:ident => $target:ident, stage = $stage:literal) => {{
81-
let config = configure("doc", &["A-A"], &["A-A"]);
82-
let build = Build::new(config);
83-
let builder = Builder::new(&build);
8481
doc::Std::new(
8582
$stage,
8683
TargetSelection::from_user(concat!(stringify!($target), "-", stringify!($target))),
87-
&builder,
8884
DocumentationFormat::Html,
8985
)
9086
}};

0 commit comments

Comments
 (0)