Skip to content

Commit e64180f

Browse files
committed
Update RustcBook doc step
1 parent c2d22c6 commit e64180f

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

src/bootstrap/src/core/build_steps/doc.rs

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,9 +1186,15 @@ fn symlink_dir_force(config: &Config, original: &Path, link: &Path) {
11861186

11871187
#[derive(Ord, PartialOrd, Debug, Clone, Hash, PartialEq, Eq)]
11881188
pub struct RustcBook {
1189-
pub compiler: Compiler,
1190-
pub target: TargetSelection,
1191-
pub validate: bool,
1189+
build_compiler: Compiler,
1190+
target: TargetSelection,
1191+
validate: bool,
1192+
}
1193+
1194+
impl RustcBook {
1195+
pub fn validate(build_compiler: Compiler, target: TargetSelection) -> Self {
1196+
Self { build_compiler, target, validate: true }
1197+
}
11921198
}
11931199

11941200
impl Step for RustcBook {
@@ -1202,8 +1208,17 @@ impl Step for RustcBook {
12021208
}
12031209

12041210
fn make_run(run: RunConfig<'_>) {
1211+
// Bump the stage to 2, because the rustc book requires an in-tree compiler.
1212+
// At the same time, since this step is enabled by default, we don't want `x doc` to fail
1213+
// in stage 1.
1214+
let stage = if run.builder.config.is_explicit_stage() || run.builder.top_stage >= 2 {
1215+
run.builder.top_stage
1216+
} else {
1217+
2
1218+
};
1219+
12051220
run.builder.ensure(RustcBook {
1206-
compiler: run.builder.compiler(run.builder.top_stage, run.builder.config.host_target),
1221+
build_compiler: prepare_doc_compiler(run.builder, run.target, stage),
12071222
target: run.target,
12081223
validate: false,
12091224
});
@@ -1221,10 +1236,10 @@ impl Step for RustcBook {
12211236
builder.cp_link_r(&builder.src.join("src/doc/rustc"), &out_base);
12221237
builder.info(&format!("Generating lint docs ({})", self.target));
12231238

1224-
let rustc = builder.rustc(self.compiler);
1239+
let rustc = builder.rustc(self.build_compiler);
12251240
// The tool runs `rustc` for extracting output examples, so it needs a
12261241
// functional sysroot.
1227-
builder.std(self.compiler, self.target);
1242+
builder.std(self.build_compiler, self.target);
12281243
let mut cmd = builder.tool_cmd(Tool::LintDocs);
12291244
cmd.arg("--src");
12301245
cmd.arg(builder.src.join("compiler"));
@@ -1250,12 +1265,12 @@ impl Step for RustcBook {
12501265
// If the lib directories are in an unusual location (changed in
12511266
// bootstrap.toml), then this needs to explicitly update the dylib search
12521267
// path.
1253-
builder.add_rustc_lib_path(self.compiler, &mut cmd);
1268+
builder.add_rustc_lib_path(self.build_compiler, &mut cmd);
12541269
let doc_generator_guard = builder.msg(
12551270
Kind::Run,
1256-
self.compiler.stage,
1271+
self.build_compiler.stage,
12571272
"lint-docs",
1258-
self.compiler.host,
1273+
self.build_compiler.host,
12591274
self.target,
12601275
);
12611276
cmd.run(builder);

src/bootstrap/src/core/build_steps/test.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3312,11 +3312,8 @@ impl Step for LintDocs {
33123312
/// Tests that the lint examples in the rustc book generate the correct
33133313
/// lints and have the expected format.
33143314
fn run(self, builder: &Builder<'_>) {
3315-
builder.ensure(crate::core::build_steps::doc::RustcBook {
3316-
compiler: self.compiler,
3317-
target: self.target,
3318-
validate: true,
3319-
});
3315+
builder
3316+
.ensure(crate::core::build_steps::doc::RustcBook::validate(self.compiler, self.target));
33203317
}
33213318
}
33223319

0 commit comments

Comments
 (0)