Skip to content

Commit 5c88116

Browse files
authored
Unrolled build for rust-lang#128269
Rollup merge of rust-lang#128269 - onur-ozkan:improve-cargo-invocations, r=Mark-Simulacrum improve cargo invocations on bootstrap Fixes few of the `FIXME`s on cargo invocations and should be considered as blocker for rust-lang#128180.
2 parents 2e63026 + 92ca0a6 commit 5c88116

File tree

9 files changed

+151
-117
lines changed

9 files changed

+151
-117
lines changed

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

+37-21
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,6 @@ use crate::core::builder::{
1212
use crate::core::config::TargetSelection;
1313
use crate::{Compiler, Mode, Subcommand};
1414

15-
pub fn cargo_subcommand(kind: Kind) -> &'static str {
16-
match kind {
17-
Kind::Check
18-
// We ensure check steps for both std and rustc from build_steps/clippy, so handle `Kind::Clippy` as well.
19-
| Kind::Clippy => "check",
20-
Kind::Fix => "fix",
21-
_ => unreachable!(),
22-
}
23-
}
24-
2515
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2616
pub struct Std {
2717
pub target: TargetSelection,
@@ -31,11 +21,22 @@ pub struct Std {
3121
///
3222
/// [`compile::Rustc`]: crate::core::build_steps::compile::Rustc
3323
crates: Vec<String>,
24+
/// Override `Builder::kind` on cargo invocations.
25+
///
26+
/// By default, `Builder::kind` is propagated as the subcommand to the cargo invocations.
27+
/// However, there are cases when this is not desirable. For example, when running `x clippy $tool_name`,
28+
/// passing `Builder::kind` to cargo invocations would run clippy on the entire compiler and library,
29+
/// which is not useful if we only want to lint a few crates with specific rules.
30+
override_build_kind: Option<Kind>,
3431
}
3532

3633
impl Std {
3734
pub fn new(target: TargetSelection) -> Self {
38-
Self { target, crates: vec![] }
35+
Self::new_with_build_kind(target, None)
36+
}
37+
38+
pub fn new_with_build_kind(target: TargetSelection, kind: Option<Kind>) -> Self {
39+
Self { target, crates: vec![], override_build_kind: kind }
3940
}
4041
}
4142

@@ -49,7 +50,7 @@ impl Step for Std {
4950

5051
fn make_run(run: RunConfig<'_>) {
5152
let crates = run.make_run_crates(Alias::Library);
52-
run.builder.ensure(Std { target: run.target, crates });
53+
run.builder.ensure(Std { target: run.target, crates, override_build_kind: None });
5354
}
5455

5556
fn run(self, builder: &Builder<'_>) {
@@ -64,7 +65,7 @@ impl Step for Std {
6465
Mode::Std,
6566
SourceType::InTree,
6667
target,
67-
cargo_subcommand(builder.kind),
68+
self.override_build_kind.unwrap_or(builder.kind),
6869
);
6970

7071
std_cargo(builder, target, compiler.stage, &mut cargo);
@@ -118,7 +119,7 @@ impl Step for Std {
118119
Mode::Std,
119120
SourceType::InTree,
120121
target,
121-
cargo_subcommand(builder.kind),
122+
self.override_build_kind.unwrap_or(builder.kind),
122123
);
123124

124125
// If we're not in stage 0, tests and examples will fail to compile
@@ -159,16 +160,31 @@ pub struct Rustc {
159160
///
160161
/// [`compile::Rustc`]: crate::core::build_steps::compile::Rustc
161162
crates: Vec<String>,
163+
/// Override `Builder::kind` on cargo invocations.
164+
///
165+
/// By default, `Builder::kind` is propagated as the subcommand to the cargo invocations.
166+
/// However, there are cases when this is not desirable. For example, when running `x clippy $tool_name`,
167+
/// passing `Builder::kind` to cargo invocations would run clippy on the entire compiler and library,
168+
/// which is not useful if we only want to lint a few crates with specific rules.
169+
override_build_kind: Option<Kind>,
162170
}
163171

164172
impl Rustc {
165173
pub fn new(target: TargetSelection, builder: &Builder<'_>) -> Self {
174+
Self::new_with_build_kind(target, builder, None)
175+
}
176+
177+
pub fn new_with_build_kind(
178+
target: TargetSelection,
179+
builder: &Builder<'_>,
180+
kind: Option<Kind>,
181+
) -> Self {
166182
let crates = builder
167183
.in_tree_crates("rustc-main", Some(target))
168184
.into_iter()
169185
.map(|krate| krate.name.to_string())
170186
.collect();
171-
Self { target, crates }
187+
Self { target, crates, override_build_kind: kind }
172188
}
173189
}
174190

@@ -183,7 +199,7 @@ impl Step for Rustc {
183199

184200
fn make_run(run: RunConfig<'_>) {
185201
let crates = run.make_run_crates(Alias::Compiler);
186-
run.builder.ensure(Rustc { target: run.target, crates });
202+
run.builder.ensure(Rustc { target: run.target, crates, override_build_kind: None });
187203
}
188204

189205
/// Builds the compiler.
@@ -204,7 +220,7 @@ impl Step for Rustc {
204220
builder.ensure(crate::core::build_steps::compile::Std::new(compiler, compiler.host));
205221
builder.ensure(crate::core::build_steps::compile::Std::new(compiler, target));
206222
} else {
207-
builder.ensure(Std::new(target));
223+
builder.ensure(Std::new_with_build_kind(target, self.override_build_kind));
208224
}
209225

210226
let mut cargo = builder::Cargo::new(
@@ -213,7 +229,7 @@ impl Step for Rustc {
213229
Mode::Rustc,
214230
SourceType::InTree,
215231
target,
216-
cargo_subcommand(builder.kind),
232+
self.override_build_kind.unwrap_or(builder.kind),
217233
);
218234

219235
rustc_cargo(builder, &mut cargo, target, &compiler);
@@ -291,7 +307,7 @@ impl Step for CodegenBackend {
291307
Mode::Codegen,
292308
SourceType::InTree,
293309
target,
294-
cargo_subcommand(builder.kind),
310+
builder.kind,
295311
);
296312

297313
cargo
@@ -349,7 +365,7 @@ impl Step for RustAnalyzer {
349365
compiler,
350366
Mode::ToolRustc,
351367
target,
352-
cargo_subcommand(builder.kind),
368+
builder.kind,
353369
"src/tools/rust-analyzer",
354370
SourceType::InTree,
355371
&["in-rust-tree".to_owned()],
@@ -417,7 +433,7 @@ macro_rules! tool_check_step {
417433
compiler,
418434
Mode::ToolRustc,
419435
target,
420-
cargo_subcommand(builder.kind),
436+
builder.kind,
421437
$path,
422438
$source_type,
423439
&[],

src/bootstrap/src/core/build_steps/clean.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::path::Path;
1111

1212
use crate::core::builder::{crate_description, Builder, RunConfig, ShouldRun, Step};
1313
use crate::utils::helpers::t;
14-
use crate::{Build, Compiler, Mode, Subcommand};
14+
use crate::{Build, Compiler, Kind, Mode, Subcommand};
1515

1616
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1717
pub struct CleanAll {}
@@ -66,7 +66,7 @@ macro_rules! clean_crate_tree {
6666
fn run(self, builder: &Builder<'_>) -> Self::Output {
6767
let compiler = self.compiler;
6868
let target = compiler.host;
69-
let mut cargo = builder.bare_cargo(compiler, $mode, target, "clean");
69+
let mut cargo = builder.bare_cargo(compiler, $mode, target, Kind::Clean);
7070

7171
// Since https://github.com/rust-lang/rust/pull/111076 enables
7272
// unstable cargo feature (`public-dependency`), we need to ensure

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

+12-6
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,14 @@ impl Step for Std {
116116
let target = self.target;
117117
let compiler = builder.compiler(builder.top_stage, builder.config.build);
118118

119-
let mut cargo =
120-
builder::Cargo::new(builder, compiler, Mode::Std, SourceType::InTree, target, "clippy");
119+
let mut cargo = builder::Cargo::new(
120+
builder,
121+
compiler,
122+
Mode::Std,
123+
SourceType::InTree,
124+
target,
125+
Kind::Clippy,
126+
);
121127

122128
std_cargo(builder, target, compiler.stage, &mut cargo);
123129

@@ -178,7 +184,7 @@ impl Step for Rustc {
178184
builder.ensure(compile::Std::new(compiler, compiler.host));
179185
builder.ensure(compile::Std::new(compiler, target));
180186
} else {
181-
builder.ensure(check::Std::new(target));
187+
builder.ensure(check::Std::new_with_build_kind(target, Some(Kind::Check)));
182188
}
183189

184190
let mut cargo = builder::Cargo::new(
@@ -187,7 +193,7 @@ impl Step for Rustc {
187193
Mode::Rustc,
188194
SourceType::InTree,
189195
target,
190-
"clippy",
196+
Kind::Clippy,
191197
);
192198

193199
rustc_cargo(builder, &mut cargo, target, &compiler);
@@ -245,14 +251,14 @@ macro_rules! lint_any {
245251
let compiler = builder.compiler(builder.top_stage, builder.config.build);
246252
let target = self.target;
247253

248-
builder.ensure(check::Rustc::new(target, builder));
254+
builder.ensure(check::Rustc::new_with_build_kind(target, builder, Some(Kind::Check)));
249255

250256
let cargo = prepare_tool_cargo(
251257
builder,
252258
compiler,
253259
Mode::ToolRustc,
254260
target,
255-
"clippy",
261+
Kind::Clippy,
256262
$path,
257263
SourceType::InTree,
258264
&[],

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ impl Step for Std {
247247
Mode::Std,
248248
SourceType::InTree,
249249
target,
250-
"check",
250+
Kind::Check,
251251
);
252252
cargo.rustflag("-Zalways-encode-mir");
253253
cargo.arg("--manifest-path").arg(builder.src.join("library/sysroot/Cargo.toml"));
@@ -259,7 +259,7 @@ impl Step for Std {
259259
Mode::Std,
260260
SourceType::InTree,
261261
target,
262-
"build",
262+
Kind::Build,
263263
);
264264
std_cargo(builder, target, compiler.stage, &mut cargo);
265265
for krate in &*self.crates {
@@ -919,7 +919,7 @@ impl Step for Rustc {
919919
Mode::Rustc,
920920
SourceType::InTree,
921921
target,
922-
"build",
922+
Kind::Build,
923923
);
924924

925925
rustc_cargo(builder, &mut cargo, target, &compiler);
@@ -1359,7 +1359,7 @@ impl Step for CodegenBackend {
13591359
Mode::Codegen,
13601360
SourceType::InTree,
13611361
target,
1362-
"build",
1362+
Kind::Build,
13631363
);
13641364
cargo
13651365
.arg("--manifest-path")

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

+10-4
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ fn doc_std(
714714
let out_dir = target_dir.join(target.triple).join("doc");
715715

716716
let mut cargo =
717-
builder::Cargo::new(builder, compiler, Mode::Std, SourceType::InTree, target, "doc");
717+
builder::Cargo::new(builder, compiler, Mode::Std, SourceType::InTree, target, Kind::Doc);
718718

719719
compile::std_cargo(builder, target, compiler.stage, &mut cargo);
720720
cargo
@@ -816,8 +816,14 @@ impl Step for Rustc {
816816
);
817817

818818
// Build cargo command.
819-
let mut cargo =
820-
builder::Cargo::new(builder, compiler, Mode::Rustc, SourceType::InTree, target, "doc");
819+
let mut cargo = builder::Cargo::new(
820+
builder,
821+
compiler,
822+
Mode::Rustc,
823+
SourceType::InTree,
824+
target,
825+
Kind::Doc,
826+
);
821827

822828
cargo.rustdocflag("--document-private-items");
823829
// Since we always pass --document-private-items, there's no need to warn about linking to private items.
@@ -964,7 +970,7 @@ macro_rules! tool_doc {
964970
compiler,
965971
Mode::ToolRustc,
966972
target,
967-
"doc",
973+
Kind::Doc,
968974
$path,
969975
source_type,
970976
&[],

src/bootstrap/src/core/build_steps/run.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::path::PathBuf;
88
use crate::core::build_steps::dist::distdir;
99
use crate::core::build_steps::test;
1010
use crate::core::build_steps::tool::{self, SourceType, Tool};
11-
use crate::core::builder::{Builder, RunConfig, ShouldRun, Step};
11+
use crate::core::builder::{Builder, Kind, RunConfig, ShouldRun, Step};
1212
use crate::core::config::flags::get_completion;
1313
use crate::core::config::TargetSelection;
1414
use crate::utils::exec::command;
@@ -142,7 +142,7 @@ impl Step for Miri {
142142
host_compiler,
143143
Mode::ToolRustc,
144144
host,
145-
"run",
145+
Kind::Run,
146146
"src/tools/miri",
147147
SourceType::InTree,
148148
&[],

0 commit comments

Comments
 (0)