Skip to content

Fix build/doc/test of error index generator #145007

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions src/bootstrap/src/core/build_steps/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ use std::path::{Path, PathBuf};
use std::{env, fs, mem};

use crate::core::build_steps::compile;
use crate::core::build_steps::tool::{self, SourceType, Tool, prepare_tool_cargo};
use crate::core::build_steps::tool::{
self, RustcPrivateCompilers, SourceType, Tool, prepare_tool_cargo,
};
use crate::core::builder::{
self, Alias, Builder, Compiler, Kind, RunConfig, ShouldRun, Step, StepMetadata,
crate_description,
Expand Down Expand Up @@ -1082,9 +1084,9 @@ tool_doc!(
crates = ["compiletest"]
);

#[derive(Ord, PartialOrd, Debug, Clone, Hash, PartialEq, Eq)]
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
pub struct ErrorIndex {
pub target: TargetSelection,
compilers: RustcPrivateCompilers,
}

impl Step for ErrorIndex {
Expand All @@ -1098,17 +1100,29 @@ impl Step for ErrorIndex {
}

fn make_run(run: RunConfig<'_>) {
let target = run.target;
run.builder.ensure(ErrorIndex { target });
run.builder.ensure(ErrorIndex {
compilers: RustcPrivateCompilers::new(run.builder, run.builder.top_stage, run.target),
});
}

/// Generates the HTML rendered error-index by running the
/// `error_index_generator` tool.
fn run(self, builder: &Builder<'_>) {
builder.info(&format!("Documenting error index ({})", self.target));
let out = builder.doc_out(self.target);
builder.info(&format!("Documenting error index ({})", self.compilers.target()));
let out = builder.doc_out(self.compilers.target());
t!(fs::create_dir_all(&out));
tool::ErrorIndex::command(builder).arg("html").arg(out).arg(&builder.version).run(builder);
tool::ErrorIndex::command(builder, self.compilers)
.arg("html")
.arg(out)
.arg(&builder.version)
.run(builder);
}

fn metadata(&self) -> Option<StepMetadata> {
Some(
StepMetadata::doc("error-index", self.compilers.target())
.built_by(self.compilers.build_compiler()),
)
}
}

Expand Down
30 changes: 20 additions & 10 deletions src/bootstrap/src/core/build_steps/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2514,7 +2514,7 @@ test_book!(

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct ErrorIndex {
compiler: Compiler,
compilers: RustcPrivateCompilers,
}

impl Step for ErrorIndex {
Expand All @@ -2532,8 +2532,12 @@ impl Step for ErrorIndex {
// error_index_generator depends on librustdoc. Use the compiler that
// is normally used to build rustdoc for other tests (like compiletest
// tests in tests/rustdoc) so that it shares the same artifacts.
let compiler = run.builder.compiler(run.builder.top_stage, run.builder.config.host_target);
run.builder.ensure(ErrorIndex { compiler });
let compilers = RustcPrivateCompilers::new(
run.builder,
run.builder.top_stage,
run.builder.config.host_target,
);
run.builder.ensure(ErrorIndex { compilers });
}

/// Runs the error index generator tool to execute the tests located in the error
Expand All @@ -2543,24 +2547,30 @@ impl Step for ErrorIndex {
/// generate a markdown file from the error indexes of the code base which is
/// then passed to `rustdoc --test`.
fn run(self, builder: &Builder<'_>) {
let compiler = self.compiler;
// The compiler that we are testing
let target_compiler = self.compilers.target_compiler();

let dir = testdir(builder, compiler.host);
let dir = testdir(builder, target_compiler.host);
t!(fs::create_dir_all(&dir));
let output = dir.join("error-index.md");

let mut tool = tool::ErrorIndex::command(builder);
let mut tool = tool::ErrorIndex::command(builder, self.compilers);
tool.arg("markdown").arg(&output);

let guard =
builder.msg(Kind::Test, compiler.stage, "error-index", compiler.host, compiler.host);
let guard = builder.msg(
Kind::Test,
target_compiler.stage,
"error-index",
target_compiler.host,
target_compiler.host,
);
let _time = helpers::timeit(builder);
tool.run_capture(builder);
drop(guard);
// The tests themselves need to link to std, so make sure it is
// available.
builder.std(compiler, compiler.host);
markdown_test(builder, compiler, &output);
builder.std(target_compiler, target_compiler.host);
markdown_test(builder, target_compiler, &output);
}
}

Expand Down
36 changes: 24 additions & 12 deletions src/bootstrap/src/core/build_steps/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -588,20 +588,20 @@ impl Step for RustcPerf {
}
}

#[derive(Debug, Clone, Hash, PartialEq, Eq, Ord, PartialOrd)]
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
pub struct ErrorIndex {
pub compiler: Compiler,
compilers: RustcPrivateCompilers,
}

impl ErrorIndex {
pub fn command(builder: &Builder<'_>) -> BootstrapCommand {
pub fn command(builder: &Builder<'_>, compilers: RustcPrivateCompilers) -> BootstrapCommand {
// Error-index-generator links with the rustdoc library, so we need to add `rustc_lib_paths`
// for rustc_private and libLLVM.so, and `sysroot_lib` for libstd, etc.
let host = builder.config.host_target;
let compiler = builder.compiler_for(builder.top_stage, host, host);
let mut cmd = command(builder.ensure(ErrorIndex { compiler }).tool_path);
let mut dylib_paths = builder.rustc_lib_paths(compiler);
dylib_paths.push(builder.sysroot_target_libdir(compiler, compiler.host));
let mut cmd = command(builder.ensure(ErrorIndex { compilers }).tool_path);

let target_compiler = compilers.target_compiler();
let mut dylib_paths = builder.rustc_lib_paths(target_compiler);
dylib_paths.push(builder.sysroot_target_libdir(target_compiler, target_compiler.host));
add_dylib_path(dylib_paths, &mut cmd);
cmd
}
Expand All @@ -620,14 +620,19 @@ impl Step for ErrorIndex {
// src/tools/error-index-generator` which almost nobody does.
// Normally, `x.py test` or `x.py doc` will use the
// `ErrorIndex::command` function instead.
let compiler = run.builder.compiler(run.builder.top_stage, run.builder.config.host_target);
run.builder.ensure(ErrorIndex { compiler });
run.builder.ensure(ErrorIndex {
compilers: RustcPrivateCompilers::new(
run.builder,
run.builder.top_stage,
run.builder.host_target,
),
});
}

fn run(self, builder: &Builder<'_>) -> ToolBuildResult {
builder.ensure(ToolBuild {
build_compiler: self.compiler,
target: self.compiler.host,
build_compiler: self.compilers.build_compiler,
target: self.compilers.target(),
tool: "error_index_generator",
mode: Mode::ToolRustc,
path: "src/tools/error_index_generator",
Expand All @@ -638,6 +643,13 @@ impl Step for ErrorIndex {
artifact_kind: ToolArtifactKind::Binary,
})
}

fn metadata(&self) -> Option<StepMetadata> {
Some(
StepMetadata::build("error-index", self.compilers.target())
.built_by(self.compilers.build_compiler),
)
}
}

#[derive(Debug, Clone, Hash, PartialEq, Eq)]
Expand Down
115 changes: 58 additions & 57 deletions src/bootstrap/src/core/builder/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,31 +257,6 @@ fn parse_config_download_rustc_at(path: &Path, download_rustc: &str, ci: bool) -
)
}

mod defaults {
use pretty_assertions::assert_eq;

use super::{TEST_TRIPLE_1, TEST_TRIPLE_2, configure, first, run_build};
use crate::Config;
use crate::core::builder::*;

#[test]
fn doc_default() {
let mut config = configure("doc", &[TEST_TRIPLE_1], &[TEST_TRIPLE_1]);
config.compiler_docs = true;
config.cmd = Subcommand::Doc { open: false, json: false };
let mut cache = run_build(&[], config);
let a = TargetSelection::from_user(TEST_TRIPLE_1);

// error_index_generator uses stage 0 to share rustdoc artifacts with the
// rustdoc tool.
assert_eq!(first(cache.all::<doc::ErrorIndex>()), &[doc::ErrorIndex { target: a },]);
assert_eq!(
first(cache.all::<tool::ErrorIndex>()),
&[tool::ErrorIndex { compiler: Compiler::new(1, a) }]
);
}
}

mod dist {
use pretty_assertions::assert_eq;

Expand Down Expand Up @@ -309,28 +284,6 @@ mod dist {
let target = TargetSelection::from_user(TEST_TRIPLE_1);
assert!(build.llvm_out(target).ends_with("llvm"));
}

#[test]
fn doc_ci() {
let mut config = configure(&[TEST_TRIPLE_1], &[TEST_TRIPLE_1]);
config.compiler_docs = true;
config.cmd = Subcommand::Doc { open: false, json: false };
let build = Build::new(config);
let mut builder = Builder::new(&build);
builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Doc), &[]);
let a = TargetSelection::from_user(TEST_TRIPLE_1);

// error_index_generator uses stage 1 to share rustdoc artifacts with the
// rustdoc tool.
assert_eq!(
first(builder.cache.all::<doc::ErrorIndex>()),
&[doc::ErrorIndex { target: a },]
);
assert_eq!(
first(builder.cache.all::<tool::ErrorIndex>()),
&[tool::ErrorIndex { compiler: Compiler::new(1, a) }]
);
}
}

mod sysroot_target_dirs {
Expand Down Expand Up @@ -888,6 +841,19 @@ mod snapshot {
");
}

#[test]
fn build_error_index() {
let ctx = TestCtx::new();
insta::assert_snapshot!(
ctx.config("build")
.path("error_index_generator")
.render_steps(), @r"
[build] llvm <host>
[build] rustc 0 <host> -> rustc 1 <host>
[build] rustc 0 <host> -> error-index 1 <host>
");
}

#[test]
fn build_bootstrap_tool_no_explicit_stage() {
let ctx = TestCtx::new();
Expand Down Expand Up @@ -1032,6 +998,8 @@ mod snapshot {
[build] rustc 1 <host> -> rustc 2 <host>
[build] rustdoc 2 <host>
[doc] std 2 <host> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind]
[build] rustc 1 <host> -> error-index 2 <host>
[doc] rustc 1 <host> -> error-index 2 <host>
[build] rustc 2 <host> -> std 2 <host>
[build] rustc 0 <host> -> LintDocs 1 <host>
[build] rustc 0 <host> -> RustInstaller 1 <host>
Expand Down Expand Up @@ -1074,6 +1042,8 @@ mod snapshot {
[build] rustc 1 <host> -> LlvmBitcodeLinker 2 <host>
[build] rustdoc 2 <host>
[doc] std 2 <host> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind]
[build] rustc 1 <host> -> error-index 2 <host>
[doc] rustc 1 <host> -> error-index 2 <host>
[build] rustc 2 <host> -> std 2 <host>
[build] rustc 0 <host> -> LintDocs 1 <host>
[build] rustc 0 <host> -> RustInstaller 1 <host>
Expand Down Expand Up @@ -1114,6 +1084,8 @@ mod snapshot {
[build] rustdoc 2 <host>
[doc] std 2 <host> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind]
[doc] std 2 <target1> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind]
[build] rustc 1 <host> -> error-index 2 <host>
[doc] rustc 1 <host> -> error-index 2 <host>
[build] rustc 2 <host> -> std 2 <host>
[build] rustc 0 <host> -> LintDocs 1 <host>
[build] rustc 0 <host> -> RustInstaller 1 <host>
Expand Down Expand Up @@ -1150,18 +1122,22 @@ mod snapshot {
[build] rustc 1 <host> -> rustc 2 <host>
[build] rustdoc 2 <host>
[doc] std 2 <host> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind]
[build] rustc 1 <host> -> error-index 2 <host>
[doc] rustc 1 <host> -> error-index 2 <host>
[build] llvm <target1>
[build] rustc 1 <host> -> std 1 <target1>
[build] rustc 1 <host> -> rustc 2 <target1>
[build] rustc 1 <host> -> error-index 2 <target1>
[doc] rustc 1 <host> -> error-index 2 <target1>
[build] rustc 2 <host> -> std 2 <host>
[build] rustc 0 <host> -> LintDocs 1 <host>
[build] rustc 1 <host> -> std 1 <target1>
[build] rustc 2 <host> -> std 2 <target1>
[build] rustc 0 <host> -> RustInstaller 1 <host>
[dist] docs <host>
[doc] std 2 <host> crates=[]
[dist] mingw <host>
[build] rustc 0 <host> -> GenerateCopyright 1 <host>
[dist] rustc <host>
[build] llvm <target1>
[build] rustc 1 <host> -> rustc 2 <target1>
[build] rustdoc 2 <target1>
[dist] rustc <target1>
[dist] rustc 1 <host> -> std 1 <host>
Expand All @@ -1188,9 +1164,15 @@ mod snapshot {
[build] rustdoc 2 <host>
[doc] std 2 <host> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind]
[doc] std 2 <target1> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind]
[build] rustc 1 <host> -> error-index 2 <host>
[doc] rustc 1 <host> -> error-index 2 <host>
[build] llvm <target1>
[build] rustc 1 <host> -> std 1 <target1>
[build] rustc 1 <host> -> rustc 2 <target1>
[build] rustc 1 <host> -> error-index 2 <target1>
[doc] rustc 1 <host> -> error-index 2 <target1>
[build] rustc 2 <host> -> std 2 <host>
[build] rustc 0 <host> -> LintDocs 1 <host>
[build] rustc 1 <host> -> std 1 <target1>
[build] rustc 2 <host> -> std 2 <target1>
[build] rustc 0 <host> -> RustInstaller 1 <host>
[dist] docs <host>
Expand All @@ -1201,8 +1183,6 @@ mod snapshot {
[dist] mingw <target1>
[build] rustc 0 <host> -> GenerateCopyright 1 <host>
[dist] rustc <host>
[build] llvm <target1>
[build] rustc 1 <host> -> rustc 2 <target1>
[build] rustdoc 2 <target1>
[dist] rustc <target1>
[dist] rustc 1 <host> -> std 1 <host>
Expand Down Expand Up @@ -1261,17 +1241,19 @@ mod snapshot {
[build] rustc 1 <host> -> WasmComponentLd 2 <host>
[build] rustdoc 2 <host>
[doc] std 2 <target1> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind]
[build] rustc 2 <host> -> std 2 <host>
[build] llvm <target1>
[build] rustc 1 <host> -> std 1 <target1>
[build] rustc 1 <host> -> rustc 2 <target1>
[build] rustc 1 <host> -> WasmComponentLd 2 <target1>
[build] rustc 1 <host> -> error-index 2 <target1>
[doc] rustc 1 <host> -> error-index 2 <target1>
[build] rustc 2 <host> -> std 2 <host>
[build] rustc 2 <host> -> std 2 <target1>
[build] rustc 0 <host> -> LintDocs 1 <host>
[build] rustc 0 <host> -> RustInstaller 1 <host>
[dist] docs <target1>
[doc] std 2 <target1> crates=[]
[dist] mingw <target1>
[build] llvm <target1>
[build] rustc 1 <host> -> rustc 2 <target1>
[build] rustc 1 <host> -> WasmComponentLd 2 <target1>
[build] rustdoc 2 <target1>
[build] rustc 1 <host> -> rust-analyzer-proc-macro-srv 2 <target1>
[build] rustc 0 <host> -> GenerateCopyright 1 <host>
Expand Down Expand Up @@ -1651,6 +1633,25 @@ mod snapshot {
");
}

#[test]
fn doc_all() {
let ctx = TestCtx::new();
insta::assert_snapshot!(
ctx.config("doc")
.render_steps(), @r"
[build] rustc 0 <host> -> UnstableBookGen 1 <host>
[build] rustc 0 <host> -> Rustbook 1 <host>
[build] llvm <host>
[build] rustc 0 <host> -> rustc 1 <host>
[build] rustdoc 1 <host>
[doc] std 1 <host> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind]
[build] rustc 0 <host> -> error-index 1 <host>
[doc] rustc 0 <host> -> error-index 1 <host>
[build] rustc 1 <host> -> std 1 <host>
[build] rustc 0 <host> -> LintDocs 1 <host>
");
}

#[test]
fn doc_library() {
let ctx = TestCtx::new();
Expand Down
Loading