104 lines
4.3 KiB
Diff
104 lines
4.3 KiB
Diff
From c41f254ad192a4ab402b40f8bdad169a8163140a Mon Sep 17 00:00:00 2001
|
|
From: onur-ozkan <work@onurozkan.dev>
|
|
Date: Thu, 25 Jul 2024 15:59:25 +0300
|
|
Subject: [PATCH] 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 <work@onurozkan.dev>
|
|
(cherry picked from commit 6e247195c644aa924a10c98cc8eb3a28e1a87929)
|
|
---
|
|
src/bootstrap/src/core/build_steps/check.rs | 4 ++--
|
|
src/bootstrap/src/core/build_steps/clippy.rs | 3 ++-
|
|
src/bootstrap/src/core/build_steps/compile.rs | 23 +++++++++++++++----
|
|
3 files changed, 22 insertions(+), 8 deletions(-)
|
|
|
|
diff --git a/src/bootstrap/src/core/build_steps/check.rs b/src/bootstrap/src/core/build_steps/check.rs
|
|
index 8235d4634b75..bbad3f179ac7 100644
|
|
--- a/src/bootstrap/src/core/build_steps/check.rs
|
|
+++ b/src/bootstrap/src/core/build_steps/check.rs
|
|
@@ -1,7 +1,7 @@
|
|
//! Implementation of compiling the compiler and standard library, in "check"-based modes.
|
|
|
|
use crate::core::build_steps::compile::{
|
|
- add_to_sysroot, run_cargo, rustc_cargo, rustc_cargo_env, std_cargo,
|
|
+ add_to_sysroot, run_cargo, rustc_cargo, rustc_cargo_env, std_cargo, std_crates_for_run_make,
|
|
};
|
|
use crate::core::build_steps::tool::{prepare_tool_cargo, SourceType};
|
|
use crate::core::builder::{
|
|
@@ -47,7 +47,7 @@ fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
|
|
}
|
|
|
|
fn make_run(run: RunConfig<'_>) {
|
|
- let crates = run.make_run_crates(Alias::Library);
|
|
+ let crates = std_crates_for_run_make(&run);
|
|
run.builder.ensure(Std { target: run.target, crates });
|
|
}
|
|
|
|
diff --git a/src/bootstrap/src/core/build_steps/clippy.rs b/src/bootstrap/src/core/build_steps/clippy.rs
|
|
index 40a2112b1925..a3ab094d799d 100644
|
|
--- a/src/bootstrap/src/core/build_steps/clippy.rs
|
|
+++ b/src/bootstrap/src/core/build_steps/clippy.rs
|
|
@@ -4,6 +4,7 @@
|
|
|
|
use crate::builder::Builder;
|
|
use crate::builder::ShouldRun;
|
|
+use crate::core::build_steps::compile::std_crates_for_run_make;
|
|
use crate::core::builder;
|
|
use crate::core::builder::crate_description;
|
|
use crate::core::builder::Alias;
|
|
@@ -122,7 +123,7 @@ fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
|
|
}
|
|
|
|
fn make_run(run: RunConfig<'_>) {
|
|
- let crates = run.make_run_crates(Alias::Library);
|
|
+ let crates = std_crates_for_run_make(&run);
|
|
run.builder.ensure(Std { target: run.target, crates });
|
|
}
|
|
|
|
diff --git a/src/bootstrap/src/core/build_steps/compile.rs b/src/bootstrap/src/core/build_steps/compile.rs
|
|
index 525b6e956405..19c8cbc54080 100644
|
|
--- a/src/bootstrap/src/core/build_steps/compile.rs
|
|
+++ b/src/bootstrap/src/core/build_steps/compile.rs
|
|
@@ -127,11 +127,7 @@ fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
|
|
}
|
|
|
|
fn make_run(run: RunConfig<'_>) {
|
|
- // If the paths include "library", build the entire standard library.
|
|
- let has_alias =
|
|
- run.paths.iter().any(|set| set.assert_single_path().path.ends_with("library"));
|
|
- let crates = if has_alias { Default::default() } else { run.cargo_crates_in_set() };
|
|
-
|
|
+ let crates = std_crates_for_run_make(&run);
|
|
run.builder.ensure(Std {
|
|
compiler: run.builder.compiler(run.builder.top_stage, run.build_triple()),
|
|
target: run.target,
|
|
@@ -428,6 +424,23 @@ fn copy_self_contained_objects(
|
|
target_deps
|
|
}
|
|
|
|
+/// Resolves standard library crates for `Std::run_make` for any build kind (like check, build, clippy, etc.).
|
|
+pub fn std_crates_for_run_make(run: &RunConfig<'_>) -> Vec<String> {
|
|
+ let has_alias = run.paths.iter().any(|set| set.assert_single_path().path.ends_with("library"));
|
|
+ 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()
|
|
+ }
|
|
+}
|
|
+
|
|
/// Configure cargo to compile the standard library, adding appropriate env vars
|
|
/// and such.
|
|
pub fn std_cargo(builder: &Builder<'_>, target: TargetSelection, stage: u32, cargo: &mut Cargo) {
|
|
--
|
|
2.46.0
|
|
|