Skip to content

Commit 564e3ad

Browse files
committed
Allow checking individual crates
This is useful for profiling metadata generation. This comes very close to removing all_krates, but doesn't quite - there's one last usage left in `doc`.
1 parent c571558 commit 564e3ad

File tree

1 file changed

+60
-17
lines changed

1 file changed

+60
-17
lines changed

src/bootstrap/check.rs

Lines changed: 60 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Implementation of compiling the compiler and standard library, in "check"-based modes.
22
3-
use crate::builder::{Builder, Kind, RunConfig, ShouldRun, Step};
3+
use crate::builder::{crate_description, Builder, Kind, RunConfig, ShouldRun, Step};
44
use crate::cache::Interned;
55
use crate::compile::{add_to_sysroot, run_cargo, rustc_cargo, rustc_cargo_env, std_cargo};
66
use crate::config::TargetSelection;
@@ -12,6 +12,12 @@ use std::path::{Path, PathBuf};
1212
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1313
pub struct Std {
1414
pub target: TargetSelection,
15+
/// Whether to build only a subset of crates.
16+
///
17+
/// This shouldn't be used from other steps; see the comment on [`compile::Rustc`].
18+
///
19+
/// [`compile::Rustc`]: crate::compile::Rustc
20+
crates: Interned<Vec<String>>,
1521
}
1622

1723
/// Returns args for the subcommand itself (not for cargo)
@@ -66,16 +72,24 @@ fn cargo_subcommand(kind: Kind) -> &'static str {
6672
}
6773
}
6874

75+
impl Std {
76+
pub fn new(target: TargetSelection) -> Self {
77+
Self { target, crates: INTERNER.intern_list(vec![]) }
78+
}
79+
}
80+
6981
impl Step for Std {
7082
type Output = ();
7183
const DEFAULT: bool = true;
7284

7385
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
74-
run.all_krates("sysroot").path("library")
86+
let crates = run.builder.in_tree_crates("sysroot", None);
87+
run.crates(crates).path("library")
7588
}
7689

7790
fn make_run(run: RunConfig<'_>) {
78-
run.builder.ensure(Std { target: run.target });
91+
let crates = run.cargo_crates_in_set();
92+
run.builder.ensure(Std { target: run.target, crates });
7993
}
8094

8195
fn run(self, builder: &Builder<'_>) {
@@ -97,7 +111,14 @@ impl Step for Std {
97111
cargo.arg("--lib");
98112
}
99113

100-
let _guard = builder.msg_check("library artifacts", target);
114+
for krate in &*self.crates {
115+
cargo.arg("-p").arg(krate);
116+
}
117+
118+
let _guard = builder.msg_check(
119+
format_args!("library artifacts{}", crate_description(&self.crates)),
120+
target,
121+
);
101122
run_cargo(
102123
builder,
103124
cargo,
@@ -117,7 +138,8 @@ impl Step for Std {
117138
}
118139

119140
// don't run on std twice with x.py clippy
120-
if builder.kind == Kind::Clippy {
141+
// don't check test dependencies if we haven't built libtest
142+
if builder.kind == Kind::Clippy || !self.crates.is_empty() {
121143
return;
122144
}
123145

@@ -147,8 +169,8 @@ impl Step for Std {
147169
// Explicitly pass -p for all dependencies krates -- this will force cargo
148170
// to also check the tests/benches/examples for these crates, rather
149171
// than just the leaf crate.
150-
for krate in builder.in_tree_crates("test", Some(target)) {
151-
cargo.arg("-p").arg(krate.name);
172+
for krate in &*self.crates {
173+
cargo.arg("-p").arg(krate);
152174
}
153175

154176
let _guard = builder.msg_check("library test/bench/example targets", target);
@@ -167,6 +189,22 @@ impl Step for Std {
167189
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
168190
pub struct Rustc {
169191
pub target: TargetSelection,
192+
/// Whether to build only a subset of crates.
193+
///
194+
/// This shouldn't be used from other steps; see the comment on [`compile::Rustc`].
195+
///
196+
/// [`compile::Rustc`]: crate::compile::Rustc
197+
crates: Interned<Vec<String>>,
198+
}
199+
200+
impl Rustc {
201+
pub fn new(target: TargetSelection, builder: &Builder<'_>) -> Self {
202+
let mut crates = vec![];
203+
for krate in builder.in_tree_crates("rustc-main", None) {
204+
crates.push(krate.name.to_string());
205+
}
206+
Self { target, crates: INTERNER.intern_list(crates) }
207+
}
170208
}
171209

172210
impl Step for Rustc {
@@ -175,11 +213,13 @@ impl Step for Rustc {
175213
const DEFAULT: bool = true;
176214

177215
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
178-
run.all_krates("rustc-main").path("compiler")
216+
let crates = run.builder.in_tree_crates("rustc-main", None);
217+
run.crates(crates).path("compiler")
179218
}
180219

181220
fn make_run(run: RunConfig<'_>) {
182-
run.builder.ensure(Rustc { target: run.target });
221+
let crates = run.cargo_crates_in_set();
222+
run.builder.ensure(Rustc { target: run.target, crates });
183223
}
184224

185225
/// Builds the compiler.
@@ -200,7 +240,7 @@ impl Step for Rustc {
200240
builder.ensure(crate::compile::Std::new(compiler, compiler.host));
201241
builder.ensure(crate::compile::Std::new(compiler, target));
202242
} else {
203-
builder.ensure(Std { target });
243+
builder.ensure(Std::new(target));
204244
}
205245

206246
let mut cargo = builder.cargo(
@@ -218,14 +258,17 @@ impl Step for Rustc {
218258
cargo.arg("--all-targets");
219259
}
220260

221-
// Explicitly pass -p for all compiler krates -- this will force cargo
261+
// Explicitly pass -p for all compiler crates -- this will force cargo
222262
// to also check the tests/benches/examples for these crates, rather
223263
// than just the leaf crate.
224-
for krate in builder.in_tree_crates("rustc-main", Some(target)) {
225-
cargo.arg("-p").arg(krate.name);
264+
for krate in &*self.crates {
265+
cargo.arg("-p").arg(krate);
226266
}
227267

228-
let _guard = builder.msg_check("compiler artifacts", target);
268+
let _guard = builder.msg_check(
269+
format_args!("compiler artifacts{}", crate_description(&self.crates)),
270+
target,
271+
);
229272
run_cargo(
230273
builder,
231274
cargo,
@@ -268,7 +311,7 @@ impl Step for CodegenBackend {
268311
let target = self.target;
269312
let backend = self.backend;
270313

271-
builder.ensure(Rustc { target });
314+
builder.ensure(Rustc::new(target, builder));
272315

273316
let mut cargo = builder.cargo(
274317
compiler,
@@ -318,7 +361,7 @@ impl Step for RustAnalyzer {
318361
let compiler = builder.compiler(builder.top_stage, builder.config.build);
319362
let target = self.target;
320363

321-
builder.ensure(Std { target });
364+
builder.ensure(Std::new(target));
322365

323366
let mut cargo = prepare_tool_cargo(
324367
builder,
@@ -386,7 +429,7 @@ macro_rules! tool_check_step {
386429
let compiler = builder.compiler(builder.top_stage, builder.config.build);
387430
let target = self.target;
388431

389-
builder.ensure(Rustc { target });
432+
builder.ensure(Rustc::new(target, builder));
390433

391434
let mut cargo = prepare_tool_cargo(
392435
builder,

0 commit comments

Comments
 (0)