Skip to content

Fix handling of no_std targets in doc::Std step #143615

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 14 additions & 16 deletions src/bootstrap/src/core/build_steps/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,26 +449,24 @@ fn copy_self_contained_objects(
target_deps
}

/// Resolves standard library crates for `Std::run_make` for any build kind (like check, build, clippy, etc.).
/// Resolves standard library crates for `Std::run_make` for any build kind (like check, doc,
/// build, clippy, etc.).
pub fn std_crates_for_run_make(run: &RunConfig<'_>) -> Vec<String> {
// FIXME: Extend builder tests to cover the `crates` field of `Std` instances.
if cfg!(test) {
return vec![];
}

let has_alias = run.paths.iter().any(|set| set.assert_single_path().path.ends_with("library"));
let mut crates = run.make_run_crates(builder::Alias::Library);

// For no_std targets, we only want to check core and alloc
// Regardless of core/alloc being selected explicitly or via the "library" default alias,
// we only want to keep these two crates.
// The set of no_std crates should be kept in sync with what `Builder::std_cargo` does.
// Note: an alternative design would be to return an enum from this function (Default vs Subset)
// of crates. However, several steps currently pass `-p <package>` even if all crates are
// selected, because Cargo behaves differently in that case. To keep that behavior without
// making further changes, we pre-filter the no-std crates here.
let target_is_no_std = run.builder.no_std(run.target).unwrap_or(false);

// 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.
if target_is_no_std {
vec![]
}
// If the paths include "library", build the entire standard library.
else if has_alias {
run.make_run_crates(builder::Alias::Library)
} else {
run.cargo_crates_in_set()
crates.retain(|c| c == "core" || c == "alloc");
}
crates
}

/// Tries to find LLVM's `compiler-rt` source directory, for building `library/profiler_builtins`.
Expand Down
6 changes: 5 additions & 1 deletion src/bootstrap/src/core/build_steps/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,11 @@ impl Step for Std {
}

fn metadata(&self) -> Option<StepMetadata> {
Some(StepMetadata::doc("std", self.target).stage(self.stage))
Some(
StepMetadata::doc("std", self.target)
.stage(self.stage)
.with_metadata(format!("crates=[{}]", self.crates.join(","))),
)
}
}

Expand Down
9 changes: 8 additions & 1 deletion src/bootstrap/src/core/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ pub struct StepMetadata {
target: TargetSelection,
built_by: Option<Compiler>,
stage: Option<u32>,
/// Additional opaque string printed in the metadata
metadata: Option<String>,
Comment on lines +149 to +150
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remark: I'm not so fussed about this, but maybe crates more specifically? Though of course I suppose for many Steps crates doesn't make sense anyway. We'll see if more specific use cases warrant changing this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metadata is a bit silly name here, but I just wanted this to be an opaque string that steps could just use as additional snapshot data.

}

impl StepMetadata {
Expand All @@ -170,7 +172,7 @@ impl StepMetadata {
}

fn new(name: &'static str, target: TargetSelection, kind: Kind) -> Self {
Self { name, kind, target, built_by: None, stage: None }
Self { name, kind, target, built_by: None, stage: None, metadata: None }
}

pub fn built_by(mut self, compiler: Compiler) -> Self {
Expand All @@ -183,6 +185,11 @@ impl StepMetadata {
self
}

pub fn with_metadata(mut self, metadata: String) -> Self {
self.metadata = Some(metadata);
self
}

pub fn get_stage(&self) -> Option<u32> {
self.stage.or(self
.built_by
Expand Down
Loading
Loading