Skip to content

Commit 42d1140

Browse files
ZalatharKobzol
authored andcommitted
Fixup tool checking
1 parent 15fd8d6 commit 42d1140

File tree

3 files changed

+77
-31
lines changed

3 files changed

+77
-31
lines changed

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

Lines changed: 64 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -455,12 +455,14 @@ macro_rules! tool_check_step {
455455
// The part of this path after the final '/' is also used as a display name.
456456
path: $path:literal
457457
$(, alt_path: $alt_path:literal )*
458+
, mode: $mode:path
458459
$(, default: $default:literal )?
459460
$( , )?
460461
}
461462
) => {
462463
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
463464
pub struct $name {
465+
pub build_compiler: Compiler,
464466
pub target: TargetSelection,
465467
}
466468

@@ -475,16 +477,33 @@ macro_rules! tool_check_step {
475477
}
476478

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

481500
fn run(self, builder: &Builder<'_>) {
482-
let Self { target } = self;
483-
run_tool_check_step(builder, target, stringify!($name), $path);
501+
let Self { target, build_compiler } = self;
502+
run_tool_check_step(builder, build_compiler, target, $path, $mode);
484503
}
485504

486505
fn metadata(&self) -> Option<StepMetadata> {
487-
Some(StepMetadata::check(stringify!($name), self.target))
506+
Some(StepMetadata::check(stringify!($name), self.target).built_by(self.build_compiler))
488507
}
489508
}
490509
}
@@ -493,19 +512,17 @@ macro_rules! tool_check_step {
493512
/// Used by the implementation of `Step::run` in `tool_check_step!`.
494513
fn run_tool_check_step(
495514
builder: &Builder<'_>,
515+
build_compiler: Compiler,
496516
target: TargetSelection,
497-
step_type_name: &str,
498517
path: &str,
518+
mode: Mode,
499519
) {
500520
let display_name = path.rsplit('/').next().unwrap();
501-
let compiler = builder.compiler(builder.top_stage, builder.config.host_target);
502-
503-
builder.ensure(Rustc::new(builder, compiler, target));
504521

505522
let mut cargo = prepare_tool_cargo(
506523
builder,
507-
compiler,
508-
Mode::ToolRustc,
524+
build_compiler,
525+
mode,
509526
target,
510527
builder.kind,
511528
path,
@@ -517,33 +534,56 @@ fn run_tool_check_step(
517534
&[],
518535
);
519536

537+
// FIXME: check bootstrap doesn't currently work with --all-targets
520538
cargo.arg("--all-targets");
521539

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

525-
let _guard = builder.msg_check(format!("{display_name} artifacts"), target, None);
549+
let _guard =
550+
builder.msg_tool(builder.kind, mode, display_name, stage, &build_compiler.host, &target);
526551
run_cargo(builder, cargo, builder.config.free_args.clone(), &stamp, vec![], true, false);
527552
}
528553

529-
tool_check_step!(Rustdoc { path: "src/tools/rustdoc", alt_path: "src/librustdoc" });
554+
tool_check_step!(Rustdoc {
555+
path: "src/tools/rustdoc",
556+
alt_path: "src/librustdoc",
557+
mode: Mode::ToolRustc
558+
});
530559
// Clippy, miri and Rustfmt are hybrids. They are external tools, but use a git subtree instead
531560
// of a submodule. Since the SourceType only drives the deny-warnings
532561
// behavior, treat it as in-tree so that any new warnings in clippy will be
533562
// rejected.
534-
tool_check_step!(Clippy { path: "src/tools/clippy" });
535-
tool_check_step!(Miri { path: "src/tools/miri" });
536-
tool_check_step!(CargoMiri { path: "src/tools/miri/cargo-miri" });
537-
tool_check_step!(Rustfmt { path: "src/tools/rustfmt" });
538-
tool_check_step!(MiroptTestTools { path: "src/tools/miropt-test-tools" });
539-
tool_check_step!(TestFloatParse { path: "src/tools/test-float-parse" });
540-
tool_check_step!(FeaturesStatusDump { path: "src/tools/features-status-dump" });
541-
542-
tool_check_step!(Bootstrap { path: "src/bootstrap", default: false });
563+
tool_check_step!(Clippy { path: "src/tools/clippy", mode: Mode::ToolRustc });
564+
tool_check_step!(Miri { path: "src/tools/miri", mode: Mode::ToolRustc });
565+
tool_check_step!(CargoMiri { path: "src/tools/miri/cargo-miri", mode: Mode::ToolRustc });
566+
tool_check_step!(Rustfmt { path: "src/tools/rustfmt", mode: Mode::ToolRustc });
567+
tool_check_step!(MiroptTestTools {
568+
path: "src/tools/miropt-test-tools",
569+
mode: Mode::ToolBootstrap
570+
});
571+
// We want to test the local std
572+
tool_check_step!(TestFloatParse { path: "src/tools/test-float-parse", mode: Mode::ToolStd });
573+
tool_check_step!(FeaturesStatusDump {
574+
path: "src/tools/features-status-dump",
575+
mode: Mode::ToolBootstrap
576+
});
577+
578+
tool_check_step!(Bootstrap { path: "src/bootstrap", mode: Mode::ToolBootstrap, default: false });
543579

544580
// `run-make-support` will be built as part of suitable run-make compiletest test steps, but support
545581
// check to make it easier to work on.
546-
tool_check_step!(RunMakeSupport { path: "src/tools/run-make-support", default: false });
582+
tool_check_step!(RunMakeSupport {
583+
path: "src/tools/run-make-support",
584+
mode: Mode::ToolBootstrap,
585+
default: false
586+
});
547587

548588
/// Check step for the `coverage-dump` bootstrap tool. The coverage-dump tool
549589
/// 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
}

src/bootstrap/src/core/builder/tests.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,9 +1352,8 @@ mod snapshot {
13521352
.path("miri")
13531353
.render_steps(), @r"
13541354
[build] llvm <host>
1355-
[build] rustc 0 <host> -> rustc 1 <host>
13561355
[check] rustc 0 <host> -> rustc 1 <host>
1357-
[check] Miri <host>
1356+
[check] rustc 0 <host> -> Miri 1 <host>
13581357
");
13591358
}
13601359

@@ -1374,9 +1373,8 @@ mod snapshot {
13741373
.stage(1)
13751374
.render_steps(), @r"
13761375
[build] llvm <host>
1377-
[build] rustc 0 <host> -> rustc 1 <host>
13781376
[check] rustc 0 <host> -> rustc 1 <host>
1379-
[check] Miri <host>
1377+
[check] rustc 0 <host> -> Miri 1 <host>
13801378
");
13811379
}
13821380

@@ -1391,9 +1389,8 @@ mod snapshot {
13911389
[build] llvm <host>
13921390
[build] rustc 0 <host> -> rustc 1 <host>
13931391
[build] rustc 1 <host> -> std 1 <host>
1394-
[build] rustc 1 <host> -> rustc 2 <host>
13951392
[check] rustc 1 <host> -> rustc 2 <host>
1396-
[check] Miri <host>
1393+
[check] rustc 1 <host> -> Miri 2 <host>
13971394
");
13981395
}
13991396

@@ -1448,6 +1445,15 @@ mod snapshot {
14481445
");
14491446
}
14501447

1448+
#[test]
1449+
fn check_bootstrap_tool() {
1450+
let ctx = TestCtx::new();
1451+
insta::assert_snapshot!(
1452+
ctx.config("check")
1453+
.path("run-make-support")
1454+
.render_steps(), @"[check] rustc 0 <host> -> RunMakeSupport 1 <host>");
1455+
}
1456+
14511457
#[test]
14521458
fn test_exclude() {
14531459
let ctx = TestCtx::new();

0 commit comments

Comments
 (0)