Skip to content

Commit

Permalink
Don't build the library and standard library before documenting them
Browse files Browse the repository at this point in the history
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
```
  • Loading branch information
jyn514 committed Apr 15, 2022
1 parent 027a232 commit dd0ad73
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions src/bootstrap/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,6 @@ impl Step for Std {
t!(fs::create_dir_all(&out));
let compiler = builder.compiler(stage, builder.config.build);

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

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

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

// Build rustc.
// Build the standard library, so that proc-macros can use it.
// (Normally, only the metadata would be necessary, but proc-macros are special since they run at compile-time.)
let compiler = builder.compiler(stage, builder.config.build);
builder.ensure(compile::Rustc { compiler, target });
builder.ensure(compile::Std { compiler, target: builder.config.build });

builder.info(&format!("Documenting stage{} compiler ({})", stage, target));

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

Expand All @@ -657,7 +657,7 @@ macro_rules! tool_doc {
}

fn make_run(run: RunConfig<'_>) {
run.builder.ensure($tool { stage: run.builder.top_stage, target: run.target });
run.builder.ensure($tool { target: run.target });
}

/// Generates compiler documentation.
Expand All @@ -667,8 +667,21 @@ macro_rules! tool_doc {
/// we do not merge it with the other documentation from std, test and
/// proc_macros. This is largely just a wrapper around `cargo doc`.
fn run(self, builder: &Builder<'_>) {
let stage = self.stage;
let stage = builder.top_stage;
let target = self.target;

// This is the intended out directory for compiler documentation.
let out = builder.compiler_doc_out(target);
t!(fs::create_dir_all(&out));

// Build rustc docs so that we generate relative links.
builder.ensure(Rustc { stage, target });
// Rustdoc needs the rustc sysroot available to build.
// FIXME: is there a way to only ensure `check::Rustc` here? Last time I tried it failed
// with strange errors, but only on a full bors test ...
let compiler = builder.compiler(stage, builder.config.build);
builder.ensure(compile::Rustc { compiler, target });

builder.info(
&format!(
"Documenting stage{} {} ({})",
Expand All @@ -678,15 +691,6 @@ macro_rules! tool_doc {
),
);

// This is the intended out directory for compiler documentation.
let out = builder.compiler_doc_out(target);
t!(fs::create_dir_all(&out));

let compiler = builder.compiler(stage, builder.config.build);

// Build rustc docs so that we generate relative links.
builder.ensure(Rustc { stage, target });

// Symlink compiler docs to the output directory of rustdoc documentation.
let out_dir = builder.stage_out(compiler, Mode::ToolRustc).join(target.triple).join("doc");
t!(fs::create_dir_all(&out_dir));
Expand Down

0 comments on commit dd0ad73

Please sign in to comment.