Skip to content

Commit b4da3bd

Browse files
ZalatharKobzol
authored andcommitted
Fixup check of rust-analyzer, codegen backends, compiletest and other tools
1 parent 9906de2 commit b4da3bd

File tree

3 files changed

+113
-64
lines changed

3 files changed

+113
-64
lines changed

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

Lines changed: 94 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ fn default_compiler_for_checking_rustc(builder: &Builder<'_>) -> Compiler {
144144
}
145145

146146
/// Checks rustc using `build_compiler` and copies the built
147-
/// .rmeta files into the sysroot of `build_copoiler`.
147+
/// .rmeta files into the sysroot of `build_compiler`.
148148
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
149149
pub struct Rustc {
150150
/// Compiler that will check this rustc.
@@ -249,8 +249,19 @@ impl Step for Rustc {
249249
}
250250
}
251251

252+
/// Prepares a build compiler sysroot that will check a `Mode::ToolRustc` tool.
253+
/// Also checks rustc using this compiler, to prepare .rmetas that the tool will link to.
254+
fn prepare_compiler_for_tool_rustc(builder: &Builder<'_>, target: TargetSelection) -> Compiler {
255+
// When we check tool stage N, we check it with compiler stage N-1
256+
let build_compiler = builder.compiler(builder.top_stage - 1, builder.config.host_target);
257+
builder.ensure(Rustc::new(builder, build_compiler, target));
258+
build_compiler
259+
}
260+
261+
/// Checks a single codegen backend.
252262
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
253263
pub struct CodegenBackend {
264+
pub build_compiler: Compiler,
254265
pub target: TargetSelection,
255266
pub backend: &'static str,
256267
}
@@ -265,8 +276,10 @@ impl Step for CodegenBackend {
265276
}
266277

267278
fn make_run(run: RunConfig<'_>) {
279+
// FIXME: only check the backend(s) that were actually selected in run.paths
280+
let build_compiler = prepare_compiler_for_tool_rustc(run.builder, run.target);
268281
for &backend in &["cranelift", "gcc"] {
269-
run.builder.ensure(CodegenBackend { target: run.target, backend });
282+
run.builder.ensure(CodegenBackend { build_compiler, target: run.target, backend });
270283
}
271284
}
272285

@@ -277,15 +290,13 @@ impl Step for CodegenBackend {
277290
return;
278291
}
279292

280-
let compiler = builder.compiler(builder.top_stage, builder.config.host_target);
293+
let build_compiler = self.build_compiler;
281294
let target = self.target;
282295
let backend = self.backend;
283296

284-
builder.ensure(Rustc::new(target, builder));
285-
286297
let mut cargo = builder::Cargo::new(
287298
builder,
288-
compiler,
299+
build_compiler,
289300
Mode::Codegen,
290301
SourceType::InTree,
291302
target,
@@ -295,23 +306,25 @@ impl Step for CodegenBackend {
295306
cargo
296307
.arg("--manifest-path")
297308
.arg(builder.src.join(format!("compiler/rustc_codegen_{backend}/Cargo.toml")));
298-
rustc_cargo_env(builder, &mut cargo, target, compiler.stage);
309+
rustc_cargo_env(builder, &mut cargo, target, build_compiler.stage);
299310

300-
let _guard = builder.msg_check(backend, target, None);
311+
let _guard = builder.msg_check(&format!("rustc_codegen_{backend}"), target, None);
301312

302-
let stamp = build_stamp::codegen_backend_stamp(builder, compiler, target, backend)
313+
let stamp = build_stamp::codegen_backend_stamp(builder, build_compiler, target, backend)
303314
.with_prefix("check");
304315

305316
run_cargo(builder, cargo, builder.config.free_args.clone(), &stamp, vec![], true, false);
306317
}
307318

308319
fn metadata(&self) -> Option<StepMetadata> {
309-
Some(StepMetadata::check(self.backend, self.target))
320+
Some(StepMetadata::check(self.backend, self.target).built_by(self.build_compiler))
310321
}
311322
}
312323

324+
/// Checks Rust analyzer that links to .rmetas from a checked rustc.
313325
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
314326
pub struct RustAnalyzer {
327+
pub build_compiler: Compiler,
315328
pub target: TargetSelection,
316329
}
317330

@@ -332,18 +345,17 @@ impl Step for RustAnalyzer {
332345
}
333346

334347
fn make_run(run: RunConfig<'_>) {
335-
run.builder.ensure(RustAnalyzer { target: run.target });
348+
let build_compiler = prepare_compiler_for_tool_rustc(run.builder, run.target);
349+
run.builder.ensure(RustAnalyzer { build_compiler, target: run.target });
336350
}
337351

338352
fn run(self, builder: &Builder<'_>) {
339-
let compiler = builder.compiler(builder.top_stage, builder.config.host_target);
353+
let build_compiler = self.build_compiler;
340354
let target = self.target;
341355

342-
builder.ensure(Rustc::new(target, builder));
343-
344356
let mut cargo = prepare_tool_cargo(
345357
builder,
346-
compiler,
358+
build_compiler,
347359
Mode::ToolRustc,
348360
target,
349361
builder.kind,
@@ -360,15 +372,15 @@ impl Step for RustAnalyzer {
360372

361373
// Cargo's output path in a given stage, compiled by a particular
362374
// compiler for the specified target.
363-
let stamp = BuildStamp::new(&builder.cargo_out(compiler, Mode::ToolRustc, target))
375+
let stamp = BuildStamp::new(&builder.cargo_out(build_compiler, Mode::ToolRustc, target))
364376
.with_prefix("rust-analyzer-check");
365377

366378
let _guard = builder.msg_check("rust-analyzer artifacts", target, None);
367379
run_cargo(builder, cargo, builder.config.free_args.clone(), &stamp, vec![], true, false);
368380
}
369381

370382
fn metadata(&self) -> Option<StepMetadata> {
371-
Some(StepMetadata::check("rust-analyzer", self.target))
383+
Some(StepMetadata::check("rust-analyzer", self.target).built_by(self.build_compiler))
372384
}
373385
}
374386

@@ -405,7 +417,7 @@ impl Step for Compiletest {
405417
);
406418

407419
if mode != Mode::ToolBootstrap {
408-
builder.ensure(Rustc::new(self.target, builder));
420+
builder.std(compiler, self.target);
409421
}
410422

411423
let mut cargo = prepare_tool_cargo(
@@ -441,12 +453,14 @@ macro_rules! tool_check_step {
441453
// The part of this path after the final '/' is also used as a display name.
442454
path: $path:literal
443455
$(, alt_path: $alt_path:literal )*
456+
, mode: $mode:path
444457
$(, default: $default:literal )?
445458
$( , )?
446459
}
447460
) => {
448461
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
449462
pub struct $name {
463+
pub build_compiler: Compiler,
450464
pub target: TargetSelection,
451465
}
452466

@@ -461,16 +475,33 @@ macro_rules! tool_check_step {
461475
}
462476

463477
fn make_run(run: RunConfig<'_>) {
464-
run.builder.ensure($name { target: run.target });
478+
let host = run.builder.config.host_target;
479+
let target = run.target;
480+
let build_compiler = match $mode {
481+
Mode::ToolBootstrap => run.builder.compiler(0, host),
482+
Mode::ToolStd => {
483+
// A small number of tools rely on in-tree standard
484+
// library crates (e.g. compiletest needs libtest).
485+
let build_compiler = run.builder.compiler(run.builder.top_stage, host);
486+
run.builder.std(build_compiler, host);
487+
run.builder.std(build_compiler, target);
488+
build_compiler
489+
}
490+
Mode::ToolRustc => {
491+
prepare_compiler_for_tool_rustc(run.builder, target)
492+
}
493+
_ => panic!("unexpected mode for tool check step: {:?}", $mode),
494+
};
495+
run.builder.ensure($name { target, build_compiler });
465496
}
466497

467498
fn run(self, builder: &Builder<'_>) {
468-
let Self { target } = self;
469-
run_tool_check_step(builder, target, stringify!($name), $path);
499+
let Self { target, build_compiler } = self;
500+
run_tool_check_step(builder, build_compiler, target, $path, $mode);
470501
}
471502

472503
fn metadata(&self) -> Option<StepMetadata> {
473-
Some(StepMetadata::check(stringify!($name), self.target))
504+
Some(StepMetadata::check(stringify!($name), self.target).built_by(self.build_compiler))
474505
}
475506
}
476507
}
@@ -479,19 +510,17 @@ macro_rules! tool_check_step {
479510
/// Used by the implementation of `Step::run` in `tool_check_step!`.
480511
fn run_tool_check_step(
481512
builder: &Builder<'_>,
513+
build_compiler: Compiler,
482514
target: TargetSelection,
483-
step_type_name: &str,
484515
path: &str,
516+
mode: Mode,
485517
) {
486518
let display_name = path.rsplit('/').next().unwrap();
487-
let compiler = builder.compiler(builder.top_stage, builder.config.host_target);
488-
489-
builder.ensure(Rustc::new(builder, compiler, target));
490519

491520
let mut cargo = prepare_tool_cargo(
492521
builder,
493-
compiler,
494-
Mode::ToolRustc,
522+
build_compiler,
523+
mode,
495524
target,
496525
builder.kind,
497526
path,
@@ -503,33 +532,56 @@ fn run_tool_check_step(
503532
&[],
504533
);
505534

535+
// FIXME: check bootstrap doesn't currently work with --all-targets
506536
cargo.arg("--all-targets");
507537

508-
let stamp = BuildStamp::new(&builder.cargo_out(compiler, Mode::ToolRustc, target))
509-
.with_prefix(&format!("{}-check", step_type_name.to_lowercase()));
538+
let stamp = BuildStamp::new(&builder.cargo_out(build_compiler, mode, target))
539+
.with_prefix(&format!("{display_name}-check"));
540+
541+
let stage = match mode {
542+
// Mode::ToolRustc is included here because of how msg_sysroot_tool prints stages
543+
Mode::Std | Mode::ToolRustc => build_compiler.stage,
544+
_ => build_compiler.stage + 1,
545+
};
510546

511-
let _guard = builder.msg_check(format!("{display_name} artifacts"), target, None);
547+
let _guard =
548+
builder.msg_tool(builder.kind, mode, display_name, stage, &build_compiler.host, &target);
512549
run_cargo(builder, cargo, builder.config.free_args.clone(), &stamp, vec![], true, false);
513550
}
514551

515-
tool_check_step!(Rustdoc { path: "src/tools/rustdoc", alt_path: "src/librustdoc" });
552+
tool_check_step!(Rustdoc {
553+
path: "src/tools/rustdoc",
554+
alt_path: "src/librustdoc",
555+
mode: Mode::ToolRustc
556+
});
516557
// Clippy, miri and Rustfmt are hybrids. They are external tools, but use a git subtree instead
517558
// of a submodule. Since the SourceType only drives the deny-warnings
518559
// behavior, treat it as in-tree so that any new warnings in clippy will be
519560
// rejected.
520-
tool_check_step!(Clippy { path: "src/tools/clippy" });
521-
tool_check_step!(Miri { path: "src/tools/miri" });
522-
tool_check_step!(CargoMiri { path: "src/tools/miri/cargo-miri" });
523-
tool_check_step!(Rustfmt { path: "src/tools/rustfmt" });
524-
tool_check_step!(MiroptTestTools { path: "src/tools/miropt-test-tools" });
525-
tool_check_step!(TestFloatParse { path: "src/tools/test-float-parse" });
526-
tool_check_step!(FeaturesStatusDump { path: "src/tools/features-status-dump" });
527-
528-
tool_check_step!(Bootstrap { path: "src/bootstrap", default: false });
561+
tool_check_step!(Clippy { path: "src/tools/clippy", mode: Mode::ToolRustc });
562+
tool_check_step!(Miri { path: "src/tools/miri", mode: Mode::ToolRustc });
563+
tool_check_step!(CargoMiri { path: "src/tools/miri/cargo-miri", mode: Mode::ToolRustc });
564+
tool_check_step!(Rustfmt { path: "src/tools/rustfmt", mode: Mode::ToolRustc });
565+
tool_check_step!(MiroptTestTools {
566+
path: "src/tools/miropt-test-tools",
567+
mode: Mode::ToolBootstrap
568+
});
569+
// We want to test the local std
570+
tool_check_step!(TestFloatParse { path: "src/tools/test-float-parse", mode: Mode::ToolStd });
571+
tool_check_step!(FeaturesStatusDump {
572+
path: "src/tools/features-status-dump",
573+
mode: Mode::ToolBootstrap
574+
});
575+
576+
tool_check_step!(Bootstrap { path: "src/bootstrap", mode: Mode::ToolBootstrap, default: false });
529577

530578
// `run-make-support` will be built as part of suitable run-make compiletest test steps, but support
531579
// check to make it easier to work on.
532-
tool_check_step!(RunMakeSupport { path: "src/tools/run-make-support", default: false });
580+
tool_check_step!(RunMakeSupport {
581+
path: "src/tools/run-make-support",
582+
mode: Mode::ToolBootstrap,
583+
default: false
584+
});
533585

534586
/// Check step for the `coverage-dump` bootstrap tool. The coverage-dump tool
535587
/// is used internally by coverage tests.

src/bootstrap/src/core/build_steps/tool.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl Builder<'_> {
7777
*target,
7878
),
7979
// doesn't depend on compiler, same as host compiler
80-
_ => self.msg(Kind::Build, build_stage, format_args!("tool {tool}"), *host, *target),
80+
_ => self.msg(kind, build_stage, format_args!("tool {tool}"), *host, *target),
8181
}
8282
}
8383
}

0 commit comments

Comments
 (0)