Skip to content

Commit 5552ce8

Browse files
committed
Implement check::RustAnalyzer using the tool_check_step macro
1 parent 7dd066a commit 5552ce8

File tree

2 files changed

+25
-69
lines changed

2 files changed

+25
-69
lines changed

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

Lines changed: 23 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -358,69 +358,6 @@ impl Step for CodegenBackend {
358358
}
359359
}
360360

361-
/// Checks Rust analyzer that links to .rmetas from a checked rustc.
362-
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
363-
pub struct RustAnalyzer {
364-
pub build_compiler: Compiler,
365-
pub target: TargetSelection,
366-
}
367-
368-
impl Step for RustAnalyzer {
369-
type Output = ();
370-
const ONLY_HOSTS: bool = true;
371-
const DEFAULT: bool = true;
372-
373-
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
374-
let builder = run.builder;
375-
run.path("src/tools/rust-analyzer").default_condition(
376-
builder
377-
.config
378-
.tools
379-
.as_ref()
380-
.is_none_or(|tools| tools.iter().any(|tool| tool == "rust-analyzer")),
381-
)
382-
}
383-
384-
fn make_run(run: RunConfig<'_>) {
385-
let build_compiler = prepare_compiler_for_check(run.builder, run.target, Mode::ToolRustc);
386-
run.builder.ensure(RustAnalyzer { build_compiler, target: run.target });
387-
}
388-
389-
fn run(self, builder: &Builder<'_>) {
390-
let build_compiler = self.build_compiler;
391-
let target = self.target;
392-
393-
let mut cargo = prepare_tool_cargo(
394-
builder,
395-
build_compiler,
396-
Mode::ToolRustc,
397-
target,
398-
builder.kind,
399-
"src/tools/rust-analyzer",
400-
SourceType::InTree,
401-
&["in-rust-tree".to_owned()],
402-
);
403-
404-
cargo.allow_features(crate::core::build_steps::tool::RustAnalyzer::ALLOW_FEATURES);
405-
406-
cargo.arg("--bins");
407-
cargo.arg("--tests");
408-
cargo.arg("--benches");
409-
410-
// Cargo's output path in a given stage, compiled by a particular
411-
// compiler for the specified target.
412-
let stamp = BuildStamp::new(&builder.cargo_out(build_compiler, Mode::ToolRustc, target))
413-
.with_prefix("rust-analyzer-check");
414-
415-
let _guard = builder.msg_check("rust-analyzer artifacts", target, None);
416-
run_cargo(builder, cargo, builder.config.free_args.clone(), &stamp, vec![], true, false);
417-
}
418-
419-
fn metadata(&self) -> Option<StepMetadata> {
420-
Some(StepMetadata::check("rust-analyzer", self.target).built_by(self.build_compiler))
421-
}
422-
}
423-
424361
macro_rules! tool_check_step {
425362
(
426363
$name:ident {
@@ -429,7 +366,10 @@ macro_rules! tool_check_step {
429366
$(, alt_path: $alt_path:literal )*
430367
// Closure that returns `Mode` based on the passed `&Builder<'_>`
431368
, mode: $mode:expr
369+
// Subset of nightly features that are allowed to be used when checking
432370
$(, allow_features: $allow_features:expr )?
371+
// Features that should be enabled when checking
372+
$(, enable_features: [$($enable_features:expr),*] )?
433373
$(, default: $default:literal )?
434374
$( , )?
435375
}
@@ -473,8 +413,9 @@ macro_rules! tool_check_step {
473413
$( _value = $allow_features; )?
474414
_value
475415
};
416+
let extra_features: &[&str] = &[$($($enable_features),*)?];
476417
let mode = $mode(builder);
477-
run_tool_check_step(builder, build_compiler, target, $path, mode, allow_features);
418+
run_tool_check_step(builder, build_compiler, target, $path, mode, allow_features, extra_features);
478419
}
479420

480421
fn metadata(&self) -> Option<StepMetadata> {
@@ -492,9 +433,11 @@ fn run_tool_check_step(
492433
path: &str,
493434
mode: Mode,
494435
allow_features: &str,
436+
extra_features: &[&str],
495437
) {
496438
let display_name = path.rsplit('/').next().unwrap();
497439

440+
let extra_features = extra_features.iter().map(|f| f.to_string()).collect::<Vec<String>>();
498441
let mut cargo = prepare_tool_cargo(
499442
builder,
500443
build_compiler,
@@ -507,12 +450,19 @@ fn run_tool_check_step(
507450
// steps should probably be marked non-default so that the default
508451
// checks aren't affected by toolstate being broken.
509452
SourceType::InTree,
510-
&[],
453+
&extra_features,
511454
);
512455
cargo.allow_features(allow_features);
513456

514-
// FIXME: check bootstrap doesn't currently work with --all-targets
515-
cargo.arg("--all-targets");
457+
// FIXME: check bootstrap doesn't currently work when multiple targets are checked
458+
// FIXME: rust-analyzer does not work with --all-targets
459+
if display_name == "rust-analyzer" {
460+
cargo.arg("--bins");
461+
cargo.arg("--tests");
462+
cargo.arg("--benches");
463+
} else {
464+
cargo.arg("--all-targets");
465+
}
516466

517467
let stamp = BuildStamp::new(&builder.cargo_out(build_compiler, mode, target))
518468
.with_prefix(&format!("{display_name}-check"));
@@ -541,6 +491,12 @@ tool_check_step!(Clippy { path: "src/tools/clippy", mode: |_builder| Mode::ToolR
541491
tool_check_step!(Miri { path: "src/tools/miri", mode: |_builder| Mode::ToolRustc });
542492
tool_check_step!(CargoMiri { path: "src/tools/miri/cargo-miri", mode: |_builder| Mode::ToolRustc });
543493
tool_check_step!(Rustfmt { path: "src/tools/rustfmt", mode: |_builder| Mode::ToolRustc });
494+
tool_check_step!(RustAnalyzer {
495+
path: "src/tools/rust-analyzer",
496+
mode: |_builder| Mode::ToolRustc,
497+
allow_features: tool::RustAnalyzer::ALLOW_FEATURES,
498+
enable_features: ["in-rust-tree"],
499+
});
544500
tool_check_step!(MiroptTestTools {
545501
path: "src/tools/miropt-test-tools",
546502
mode: |_builder| Mode::ToolBootstrap

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,7 +1378,7 @@ mod snapshot {
13781378
[check] rustc 1 <host> -> Miri 2 <target1>
13791379
[check] rustc 1 <host> -> CargoMiri 2 <target1>
13801380
[check] rustc 1 <host> -> Rustfmt 2 <target1>
1381-
[check] rustc 1 <host> -> rust-analyzer 2 <target1>
1381+
[check] rustc 1 <host> -> RustAnalyzer 2 <target1>
13821382
[check] rustc 1 <host> -> TestFloatParse 2 <target1>
13831383
[check] rustc 1 <host> -> std 1 <target1>
13841384
");
@@ -1546,7 +1546,7 @@ mod snapshot {
15461546
.render_steps(), @r"
15471547
[build] llvm <host>
15481548
[check] rustc 0 <host> -> rustc 1 <host>
1549-
[check] rustc 0 <host> -> rust-analyzer 1 <host>
1549+
[check] rustc 0 <host> -> RustAnalyzer 1 <host>
15501550
");
15511551
}
15521552

0 commit comments

Comments
 (0)