From 754329379e775c0d1cc714528353437d128a4c62 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Sun, 5 Sep 2021 20:07:57 +0000 Subject: [PATCH 1/2] 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. --- src/bootstrap/check.rs | 3 ++- src/bootstrap/doc.rs | 20 +++++++++++--------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/bootstrap/check.rs b/src/bootstrap/check.rs index f66f282bea933..1a25f29c9e2f4 100644 --- a/src/bootstrap/check.rs +++ b/src/bootstrap/check.rs @@ -55,7 +55,8 @@ fn cargo_subcommand(kind: Kind) -> &'static str { Kind::Check => "check", Kind::Clippy => "clippy", Kind::Fix => "fix", - _ => unreachable!(), + // Another top-level command is calling check + _ => "check", } } diff --git a/src/bootstrap/doc.rs b/src/bootstrap/doc.rs index 6f2470b706a64..63b411b3389f8 100644 --- a/src/bootstrap/doc.rs +++ b/src/bootstrap/doc.rs @@ -17,6 +17,7 @@ use build_helper::{t, up_to_date}; use crate::builder::{Builder, Compiler, RunConfig, ShouldRun, Step}; use crate::cache::{Interned, INTERNER}; +use crate::check; use crate::compile; use crate::config::{Config, TargetSelection}; use crate::tool::{self, prepare_tool_cargo, SourceType, Tool}; @@ -438,7 +439,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"))); @@ -569,9 +569,10 @@ 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 }); // This uses a shared directory so that librustdoc documentation gets // correctly built and merged with the rustc documentation. This is @@ -699,21 +700,22 @@ 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); - if !builder.config.compiler_docs && !builder.was_invoked_explicitly::() { builder.info("\tskipping - compiler/tool docs disabled"); return; } + // 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. + builder.ensure(check::Rustc { target }); // Symlink compiler docs to the output directory of rustdoc documentation. + let compiler = builder.compiler(stage, builder.config.build); let out_dir = builder.stage_out(compiler, Mode::ToolRustc).join(target.triple).join("doc"); t!(fs::create_dir_all(&out_dir)); t!(symlink_dir_force(&builder.config, &out, &out_dir)); From 29a6be5df70865768863989d4570ae6fbdfad2f8 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Sun, 26 Sep 2021 17:02:00 +0000 Subject: [PATCH 2/2] 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. --- src/bootstrap/doc.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/bootstrap/doc.rs b/src/bootstrap/doc.rs index 63b411b3389f8..59a8ae25e7921 100644 --- a/src/bootstrap/doc.rs +++ b/src/bootstrap/doc.rs @@ -665,7 +665,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, } @@ -679,7 +678,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. @@ -689,7 +688,7 @@ 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; builder.info( &format!(