Skip to content

Commit 2824572

Browse files
committed
Update RustcBook doc step
1 parent abd1e28 commit 2824572

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
@@ -1200,9 +1200,15 @@ fn symlink_dir_force(config: &Config, original: &Path, link: &Path) {
12001200

12011201
#[derive(Ord, PartialOrd, Debug, Clone, Hash, PartialEq, Eq)]
12021202
pub struct RustcBook {
1203-
pub compiler: Compiler,
1204-
pub target: TargetSelection,
1205-
pub validate: bool,
1203+
build_compiler: Compiler,
1204+
target: TargetSelection,
1205+
validate: bool,
1206+
}
1207+
1208+
impl RustcBook {
1209+
pub fn validate(build_compiler: Compiler, target: TargetSelection) -> Self {
1210+
Self { build_compiler, target, validate: true }
1211+
}
12061212
}
12071213

12081214
impl Step for RustcBook {
@@ -1216,8 +1222,17 @@ impl Step for RustcBook {
12161222
}
12171223

12181224
fn make_run(run: RunConfig<'_>) {
1225+
// Bump the stage to 2, because the rustc book requires an in-tree compiler.
1226+
// At the same time, since this step is enabled by default, we don't want `x doc` to fail
1227+
// in stage 1.
1228+
let stage = if run.builder.config.is_explicit_stage() || run.builder.top_stage >= 2 {
1229+
run.builder.top_stage
1230+
} else {
1231+
2
1232+
};
1233+
12191234
run.builder.ensure(RustcBook {
1220-
compiler: run.builder.compiler(run.builder.top_stage, run.builder.config.host_target),
1235+
build_compiler: prepare_doc_compiler(run.builder, run.target, stage),
12211236
target: run.target,
12221237
validate: false,
12231238
});
@@ -1235,10 +1250,10 @@ impl Step for RustcBook {
12351250
builder.cp_link_r(&builder.src.join("src/doc/rustc"), &out_base);
12361251
builder.info(&format!("Generating lint docs ({})", self.target));
12371252

1238-
let rustc = builder.rustc(self.compiler);
1253+
let rustc = builder.rustc(self.build_compiler);
12391254
// The tool runs `rustc` for extracting output examples, so it needs a
12401255
// functional sysroot.
1241-
builder.std(self.compiler, self.target);
1256+
builder.std(self.build_compiler, self.target);
12421257
let mut cmd = builder.tool_cmd(Tool::LintDocs);
12431258
cmd.arg("--src");
12441259
cmd.arg(builder.src.join("compiler"));
@@ -1264,12 +1279,12 @@ impl Step for RustcBook {
12641279
// If the lib directories are in an unusual location (changed in
12651280
// bootstrap.toml), then this needs to explicitly update the dylib search
12661281
// path.
1267-
builder.add_rustc_lib_path(self.compiler, &mut cmd);
1282+
builder.add_rustc_lib_path(self.build_compiler, &mut cmd);
12681283
let doc_generator_guard = builder.msg(
12691284
Kind::Run,
1270-
self.compiler.stage,
1285+
self.build_compiler.stage,
12711286
"lint-docs",
1272-
self.compiler.host,
1287+
self.build_compiler.host,
12731288
self.target,
12741289
);
12751290
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
@@ -3310,11 +3310,8 @@ impl Step for LintDocs {
33103310
/// Tests that the lint examples in the rustc book generate the correct
33113311
/// lints and have the expected format.
33123312
fn run(self, builder: &Builder<'_>) {
3313-
builder.ensure(crate::core::build_steps::doc::RustcBook {
3314-
compiler: self.compiler,
3315-
target: self.target,
3316-
validate: true,
3317-
});
3313+
builder
3314+
.ensure(crate::core::build_steps::doc::RustcBook::validate(self.compiler, self.target));
33183315
}
33193316
}
33203317

0 commit comments

Comments
 (0)