Skip to content

Commit dd0ad73

Browse files
committed
Don't build the library and standard library before documenting them
Rustdoc doesn't require the build artifacts to generate the docs, and especially in the case of rustc, it greatly increases the time needed to run the build. - Statically ensure that only the top_stage of a tool is documented If another part of rustbuild tried to document a different stage, it would run into errors because `check::Rustc` unconditionally uses the top stage. - Try building rustc instead of checking to avoid duplicate artifacts Tries to workaround the following error: ``` error[E0464]: multiple matching crates for `rustc_ast` --> src/librustdoc/lib.rs:40:1 | 40 | extern crate rustc_ast; | ^^^^^^^^^^^^^^^^^^^^^^^ | = note: candidates: crate `rustc_ast`: /checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_ast-6d7c193782263d89.rlib crate `rustc_ast`: /checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_ast-e5d09eda5beb759c.rmeta ```
1 parent 027a232 commit dd0ad73

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

src/bootstrap/doc.rs

+20-16
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,6 @@ impl Step for Std {
441441
t!(fs::create_dir_all(&out));
442442
let compiler = builder.compiler(stage, builder.config.build);
443443

444-
builder.ensure(compile::Std { compiler, target });
445444
let out_dir = builder.stage_out(compiler, Mode::Std).join(target.triple).join("doc");
446445

447446
t!(fs::copy(builder.src.join("src/doc/rust.css"), out.join("rust.css")));
@@ -548,7 +547,6 @@ impl Step for Rustc {
548547
fn run(self, builder: &Builder<'_>) {
549548
let stage = self.stage;
550549
let target = self.target;
551-
builder.info(&format!("Documenting stage{} compiler ({})", stage, target));
552550

553551
let paths = builder
554552
.paths
@@ -563,9 +561,12 @@ impl Step for Rustc {
563561
let out = builder.compiler_doc_out(target);
564562
t!(fs::create_dir_all(&out));
565563

566-
// Build rustc.
564+
// Build the standard library, so that proc-macros can use it.
565+
// (Normally, only the metadata would be necessary, but proc-macros are special since they run at compile-time.)
567566
let compiler = builder.compiler(stage, builder.config.build);
568-
builder.ensure(compile::Rustc { compiler, target });
567+
builder.ensure(compile::Std { compiler, target: builder.config.build });
568+
569+
builder.info(&format!("Documenting stage{} compiler ({})", stage, target));
569570

570571
// This uses a shared directory so that librustdoc documentation gets
571572
// correctly built and merged with the rustc documentation. This is
@@ -642,7 +643,6 @@ macro_rules! tool_doc {
642643
($tool: ident, $should_run: literal, $path: literal, [$($krate: literal),+ $(,)?] $(,)?) => {
643644
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
644645
pub struct $tool {
645-
stage: u32,
646646
target: TargetSelection,
647647
}
648648

@@ -657,7 +657,7 @@ macro_rules! tool_doc {
657657
}
658658

659659
fn make_run(run: RunConfig<'_>) {
660-
run.builder.ensure($tool { stage: run.builder.top_stage, target: run.target });
660+
run.builder.ensure($tool { target: run.target });
661661
}
662662

663663
/// Generates compiler documentation.
@@ -667,8 +667,21 @@ macro_rules! tool_doc {
667667
/// we do not merge it with the other documentation from std, test and
668668
/// proc_macros. This is largely just a wrapper around `cargo doc`.
669669
fn run(self, builder: &Builder<'_>) {
670-
let stage = self.stage;
670+
let stage = builder.top_stage;
671671
let target = self.target;
672+
673+
// This is the intended out directory for compiler documentation.
674+
let out = builder.compiler_doc_out(target);
675+
t!(fs::create_dir_all(&out));
676+
677+
// Build rustc docs so that we generate relative links.
678+
builder.ensure(Rustc { stage, target });
679+
// Rustdoc needs the rustc sysroot available to build.
680+
// FIXME: is there a way to only ensure `check::Rustc` here? Last time I tried it failed
681+
// with strange errors, but only on a full bors test ...
682+
let compiler = builder.compiler(stage, builder.config.build);
683+
builder.ensure(compile::Rustc { compiler, target });
684+
672685
builder.info(
673686
&format!(
674687
"Documenting stage{} {} ({})",
@@ -678,15 +691,6 @@ macro_rules! tool_doc {
678691
),
679692
);
680693

681-
// This is the intended out directory for compiler documentation.
682-
let out = builder.compiler_doc_out(target);
683-
t!(fs::create_dir_all(&out));
684-
685-
let compiler = builder.compiler(stage, builder.config.build);
686-
687-
// Build rustc docs so that we generate relative links.
688-
builder.ensure(Rustc { stage, target });
689-
690694
// Symlink compiler docs to the output directory of rustdoc documentation.
691695
let out_dir = builder.stage_out(compiler, Mode::ToolRustc).join(target.triple).join("doc");
692696
t!(fs::create_dir_all(&out_dir));

0 commit comments

Comments
 (0)