Skip to content

Commit c2d22c6

Browse files
committed
Update Reference doc step
1 parent 772ca37 commit c2d22c6

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
@@ -55,7 +55,7 @@ macro_rules! book {
5555
src: builder.src.join($path),
5656
parent: Some(self),
5757
languages: $lang.into(),
58-
rustdoc_compiler: None,
58+
build_compiler: None,
5959
})
6060
}
6161
}
@@ -103,7 +103,7 @@ impl Step for UnstableBook {
103103
src: builder.md_doc_out(self.target).join("unstable-book"),
104104
parent: Some(self),
105105
languages: vec![],
106-
rustdoc_compiler: None,
106+
build_compiler: None,
107107
})
108108
}
109109
}
@@ -115,7 +115,8 @@ struct RustbookSrc<P: Step> {
115115
src: PathBuf,
116116
parent: Option<P>,
117117
languages: Vec<&'static str>,
118-
rustdoc_compiler: Option<Compiler>,
118+
/// Compiler whose rustdoc should be used to document things using `mdbook-spec`.
119+
build_compiler: Option<Compiler>,
119120
}
120121

121122
impl<P: Step> Step for RustbookSrc<P> {
@@ -148,7 +149,7 @@ impl<P: Step> Step for RustbookSrc<P> {
148149

149150
let mut rustbook_cmd = builder.tool_cmd(Tool::Rustbook);
150151

151-
if let Some(compiler) = self.rustdoc_compiler {
152+
if let Some(compiler) = self.build_compiler {
152153
let mut rustdoc = builder.rustdoc_for_compiler(compiler);
153154
rustdoc.pop();
154155
let old_path = env::var_os("PATH").unwrap_or_default();
@@ -191,11 +192,21 @@ impl<P: Step> Step for RustbookSrc<P> {
191192
builder.maybe_open_in_browser::<P>(index)
192193
}
193194
}
195+
196+
fn metadata(&self) -> Option<StepMetadata> {
197+
let mut metadata = StepMetadata::doc(&format!("{} (book)", self.name), self.target);
198+
if let Some(compiler) = self.build_compiler {
199+
metadata = metadata.built_by(compiler);
200+
}
201+
202+
Some(metadata)
203+
}
194204
}
195205

196206
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
197207
pub struct TheBook {
198-
compiler: Compiler,
208+
/// Compiler whose rustdoc will be used to generated documentation.
209+
build_compiler: Compiler,
199210
target: TargetSelection,
200211
}
201212

@@ -210,7 +221,7 @@ impl Step for TheBook {
210221

211222
fn make_run(run: RunConfig<'_>) {
212223
run.builder.ensure(TheBook {
213-
compiler: run.builder.compiler(run.builder.top_stage, run.builder.config.host_target),
224+
build_compiler: prepare_doc_compiler(run.builder, run.target, run.builder.top_stage),
214225
target: run.target,
215226
});
216227
}
@@ -227,7 +238,7 @@ impl Step for TheBook {
227238
fn run(self, builder: &Builder<'_>) {
228239
builder.require_submodule("src/doc/book", None);
229240

230-
let compiler = self.compiler;
241+
let compiler = self.build_compiler;
231242
let target = self.target;
232243

233244
let absolute_path = builder.src.join("src/doc/book");
@@ -240,7 +251,7 @@ impl Step for TheBook {
240251
src: absolute_path.clone(),
241252
parent: Some(self),
242253
languages: vec![],
243-
rustdoc_compiler: None,
254+
build_compiler: None,
244255
});
245256

246257
// building older edition redirects
@@ -253,7 +264,7 @@ impl Step for TheBook {
253264
// treat the other editions as not having a parent.
254265
parent: Option::<Self>::None,
255266
languages: vec![],
256-
rustdoc_compiler: None,
267+
build_compiler: None,
257268
});
258269
}
259270

@@ -1257,15 +1268,18 @@ impl Step for RustcBook {
12571268
src: out_base,
12581269
parent: Some(self),
12591270
languages: vec![],
1260-
rustdoc_compiler: None,
1271+
build_compiler: None,
12611272
});
12621273
}
12631274
}
12641275

1276+
/// Documents the reference.
1277+
/// It is always done using a stage 1+ compiler, because it references in-tree compiler/stdlib
1278+
/// concepts.
12651279
#[derive(Ord, PartialOrd, Debug, Clone, Hash, PartialEq, Eq)]
12661280
pub struct Reference {
1267-
pub compiler: Compiler,
1268-
pub target: TargetSelection,
1281+
build_compiler: Compiler,
1282+
target: TargetSelection,
12691283
}
12701284

12711285
impl Step for Reference {
@@ -1278,8 +1292,19 @@ impl Step for Reference {
12781292
}
12791293

12801294
fn make_run(run: RunConfig<'_>) {
1295+
// Bump the stage to 2, because the reference requires an in-tree compiler.
1296+
// At the same time, since this step is enabled by default, we don't want `x doc` to fail
1297+
// in stage 1.
1298+
// FIXME: create a shared method on builder for auto-bumping, and print some warning when
1299+
// it happens.
1300+
let stage = if run.builder.config.is_explicit_stage() || run.builder.top_stage >= 2 {
1301+
run.builder.top_stage
1302+
} else {
1303+
2
1304+
};
1305+
12811306
run.builder.ensure(Reference {
1282-
compiler: run.builder.compiler(run.builder.top_stage, run.builder.config.host_target),
1307+
build_compiler: prepare_doc_compiler(run.builder, run.target, stage),
12831308
target: run.target,
12841309
});
12851310
}
@@ -1290,14 +1315,14 @@ impl Step for Reference {
12901315

12911316
// This is needed for generating links to the standard library using
12921317
// the mdbook-spec plugin.
1293-
builder.std(self.compiler, builder.config.host_target);
1318+
builder.std(self.build_compiler, builder.config.host_target);
12941319

12951320
// Run rustbook/mdbook to generate the HTML pages.
12961321
builder.ensure(RustbookSrc {
12971322
target: self.target,
12981323
name: "reference".to_owned(),
12991324
src: builder.src.join("src/doc/reference"),
1300-
rustdoc_compiler: Some(self.compiler),
1325+
build_compiler: Some(self.build_compiler),
13011326
parent: Some(self),
13021327
languages: vec![],
13031328
});

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1817,6 +1817,22 @@ mod snapshot {
18171817
[doc] Compiletest <host>
18181818
");
18191819
}
1820+
1821+
// Reference should be auto-bumped to stage 2.
1822+
#[test]
1823+
fn doc_reference() {
1824+
let ctx = TestCtx::new();
1825+
insta::assert_snapshot!(
1826+
ctx.config("doc")
1827+
.path("reference")
1828+
.render_steps(), @r"
1829+
[build] llvm <host>
1830+
[build] rustc 0 <host> -> rustc 1 <host>
1831+
[build] rustc 1 <host> -> std 1 <host>
1832+
[build] rustc 0 <host> -> Rustbook 1 <host>
1833+
[doc] rustc 1 <host> -> reference (book) 2 <host>
1834+
");
1835+
}
18201836
}
18211837

18221838
struct ExecutedSteps {

0 commit comments

Comments
 (0)