Skip to content

Commit 02fc091

Browse files
committed
Update Reference doc step
1 parent 980fe06 commit 02fc091

File tree

2 files changed

+56
-15
lines changed

2 files changed

+56
-15
lines changed

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

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ macro_rules! book {
5757
src: builder.src.join($path),
5858
parent: Some(self),
5959
languages: $lang.into(),
60-
rustdoc_compiler: None,
60+
build_compiler: None,
6161
})
6262
}
6363
}
@@ -105,7 +105,7 @@ impl Step for UnstableBook {
105105
src: builder.md_doc_out(self.target).join("unstable-book"),
106106
parent: Some(self),
107107
languages: vec![],
108-
rustdoc_compiler: None,
108+
build_compiler: None,
109109
})
110110
}
111111
}
@@ -117,7 +117,8 @@ struct RustbookSrc<P: Step> {
117117
src: PathBuf,
118118
parent: Option<P>,
119119
languages: Vec<&'static str>,
120-
rustdoc_compiler: Option<Compiler>,
120+
/// Compiler whose rustdoc should be used to document things using `mdbook-spec`.
121+
build_compiler: Option<Compiler>,
121122
}
122123

123124
impl<P: Step> Step for RustbookSrc<P> {
@@ -150,7 +151,7 @@ impl<P: Step> Step for RustbookSrc<P> {
150151

151152
let mut rustbook_cmd = builder.tool_cmd(Tool::Rustbook);
152153

153-
if let Some(compiler) = self.rustdoc_compiler {
154+
if let Some(compiler) = self.build_compiler {
154155
let mut rustdoc = builder.rustdoc_for_compiler(compiler);
155156
rustdoc.pop();
156157
let old_path = env::var_os("PATH").unwrap_or_default();
@@ -193,11 +194,21 @@ impl<P: Step> Step for RustbookSrc<P> {
193194
builder.maybe_open_in_browser::<P>(index)
194195
}
195196
}
197+
198+
fn metadata(&self) -> Option<StepMetadata> {
199+
let mut metadata = StepMetadata::doc(&format!("{} (book)", self.name), self.target);
200+
if let Some(compiler) = self.build_compiler {
201+
metadata = metadata.built_by(compiler);
202+
}
203+
204+
Some(metadata)
205+
}
196206
}
197207

198208
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
199209
pub struct TheBook {
200-
compiler: Compiler,
210+
/// Compiler whose rustdoc will be used to generated documentation.
211+
build_compiler: Compiler,
201212
target: TargetSelection,
202213
}
203214

@@ -212,7 +223,7 @@ impl Step for TheBook {
212223

213224
fn make_run(run: RunConfig<'_>) {
214225
run.builder.ensure(TheBook {
215-
compiler: run.builder.compiler(run.builder.top_stage, run.builder.config.host_target),
226+
build_compiler: prepare_doc_compiler(run.builder, run.target, run.builder.top_stage),
216227
target: run.target,
217228
});
218229
}
@@ -229,7 +240,7 @@ impl Step for TheBook {
229240
fn run(self, builder: &Builder<'_>) {
230241
builder.require_submodule("src/doc/book", None);
231242

232-
let compiler = self.compiler;
243+
let compiler = self.build_compiler;
233244
let target = self.target;
234245

235246
let absolute_path = builder.src.join("src/doc/book");
@@ -242,7 +253,7 @@ impl Step for TheBook {
242253
src: absolute_path.clone(),
243254
parent: Some(self),
244255
languages: vec![],
245-
rustdoc_compiler: None,
256+
build_compiler: None,
246257
});
247258

248259
// building older edition redirects
@@ -255,7 +266,7 @@ impl Step for TheBook {
255266
// treat the other editions as not having a parent.
256267
parent: Option::<Self>::None,
257268
languages: vec![],
258-
rustdoc_compiler: None,
269+
build_compiler: None,
259270
});
260271
}
261272

@@ -1271,15 +1282,18 @@ impl Step for RustcBook {
12711282
src: out_base,
12721283
parent: Some(self),
12731284
languages: vec![],
1274-
rustdoc_compiler: None,
1285+
build_compiler: None,
12751286
});
12761287
}
12771288
}
12781289

1290+
/// Documents the reference.
1291+
/// It is always done using a stage 1+ compiler, because it references in-tree compiler/stdlib
1292+
/// concepts.
12791293
#[derive(Ord, PartialOrd, Debug, Clone, Hash, PartialEq, Eq)]
12801294
pub struct Reference {
1281-
pub compiler: Compiler,
1282-
pub target: TargetSelection,
1295+
build_compiler: Compiler,
1296+
target: TargetSelection,
12831297
}
12841298

12851299
impl Step for Reference {
@@ -1292,8 +1306,19 @@ impl Step for Reference {
12921306
}
12931307

12941308
fn make_run(run: RunConfig<'_>) {
1309+
// Bump the stage to 2, because the reference requires an in-tree compiler.
1310+
// At the same time, since this step is enabled by default, we don't want `x doc` to fail
1311+
// in stage 1.
1312+
// FIXME: create a shared method on builder for auto-bumping, and print some warning when
1313+
// it happens.
1314+
let stage = if run.builder.config.is_explicit_stage() || run.builder.top_stage >= 2 {
1315+
run.builder.top_stage
1316+
} else {
1317+
2
1318+
};
1319+
12951320
run.builder.ensure(Reference {
1296-
compiler: run.builder.compiler(run.builder.top_stage, run.builder.config.host_target),
1321+
build_compiler: prepare_doc_compiler(run.builder, run.target, stage),
12971322
target: run.target,
12981323
});
12991324
}
@@ -1304,14 +1329,14 @@ impl Step for Reference {
13041329

13051330
// This is needed for generating links to the standard library using
13061331
// the mdbook-spec plugin.
1307-
builder.std(self.compiler, builder.config.host_target);
1332+
builder.std(self.build_compiler, builder.config.host_target);
13081333

13091334
// Run rustbook/mdbook to generate the HTML pages.
13101335
builder.ensure(RustbookSrc {
13111336
target: self.target,
13121337
name: "reference".to_owned(),
13131338
src: builder.src.join("src/doc/reference"),
1314-
rustdoc_compiler: Some(self.compiler),
1339+
build_compiler: Some(self.build_compiler),
13151340
parent: Some(self),
13161341
languages: vec![],
13171342
});

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1870,6 +1870,22 @@ mod snapshot {
18701870
[doc] Compiletest <host>
18711871
");
18721872
}
1873+
1874+
// Reference should be auto-bumped to stage 2.
1875+
#[test]
1876+
fn doc_reference() {
1877+
let ctx = TestCtx::new();
1878+
insta::assert_snapshot!(
1879+
ctx.config("doc")
1880+
.path("reference")
1881+
.render_steps(), @r"
1882+
[build] llvm <host>
1883+
[build] rustc 0 <host> -> rustc 1 <host>
1884+
[build] rustc 1 <host> -> std 1 <host>
1885+
[build] rustc 0 <host> -> Rustbook 1 <host>
1886+
[doc] rustc 1 <host> -> reference (book) 2 <host>
1887+
");
1888+
}
18731889
}
18741890

18751891
struct ExecutedSteps {

0 commit comments

Comments
 (0)