Skip to content

Commit 52b83d7

Browse files
committed
Added rustdoc documentation step outputting into compiler documentation.
1 parent fd18d25 commit 52b83d7

File tree

2 files changed

+84
-8
lines changed

2 files changed

+84
-8
lines changed

src/bootstrap/builder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,8 @@ impl<'a> Builder<'a> {
352352
Kind::Bench => describe!(test::Crate, test::CrateLibrustc),
353353
Kind::Doc => describe!(doc::UnstableBook, doc::UnstableBookGen, doc::TheBook,
354354
doc::Standalone, doc::Std, doc::Test, doc::WhitelistedRustc, doc::Rustc,
355-
doc::ErrorIndex, doc::Nomicon, doc::Reference, doc::Rustdoc, doc::RustByExample,
356-
doc::RustcBook, doc::CargoBook),
355+
doc::Rustdoc, doc::ErrorIndex, doc::Nomicon, doc::Reference, doc::RustdocBook,
356+
doc::RustByExample, doc::RustcBook, doc::CargoBook),
357357
Kind::Dist => describe!(dist::Docs, dist::RustcDocs, dist::Mingw, dist::Rustc,
358358
dist::DebuggerScripts, dist::Std, dist::Analysis, dist::Src,
359359
dist::PlainSourceTarball, dist::Cargo, dist::Rls, dist::Rustfmt, dist::Extended,

src/bootstrap/doc.rs

+82-6
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use build_helper::up_to_date;
2828

2929
use util::symlink_dir;
3030
use builder::{Builder, Compiler, RunConfig, ShouldRun, Step};
31-
use tool::Tool;
31+
use tool::{self, prepare_tool_cargo, Tool};
3232
use compile;
3333
use cache::{INTERNER, Interned};
3434
use config::Config;
@@ -70,7 +70,7 @@ macro_rules! book {
7070
book!(
7171
Nomicon, "src/doc/nomicon", "nomicon";
7272
Reference, "src/doc/reference", "reference";
73-
Rustdoc, "src/doc/rustdoc", "rustdoc";
73+
RustdocBook, "src/doc/rustdoc", "rustdoc";
7474
RustcBook, "src/doc/rustc", "rustc";
7575
RustByExample, "src/doc/rust-by-example", "rust-by-example";
7676
);
@@ -665,8 +665,12 @@ impl Step for Rustc {
665665
let stage = self.stage;
666666
let target = self.target;
667667
builder.info(&format!("Documenting stage{} compiler ({})", stage, target));
668+
669+
// This is the intended out directory for compiler documentation.
668670
let out = builder.compiler_doc_out(target);
669671
t!(fs::create_dir_all(&out));
672+
673+
// Get the correct compiler for this stage.
670674
let compiler = builder.compiler(stage, builder.config.build);
671675
let rustdoc = builder.rustdoc(compiler.host);
672676
let compiler = if builder.force_use_stage1(compiler, target) {
@@ -676,21 +680,23 @@ impl Step for Rustc {
676680
};
677681

678682
if !builder.config.compiler_docs {
679-
builder.info(&format!("\tskipping - compiler docs disabled"));
683+
builder.info(&format!("\tskipping - compiler/librustdoc docs disabled"));
680684
return;
681685
}
682686

683-
// Build libstd docs so that we generate relative links
687+
// Build libstd docs so that we generate relative links.
684688
builder.ensure(Std { stage, target });
685689

690+
// Build rustc.
686691
builder.ensure(compile::Rustc { compiler, target });
687-
let out_dir = builder.stage_out(compiler, Mode::Librustc)
688-
.join(target).join("doc");
692+
689693
// We do not symlink to the same shared folder that already contains std library
690694
// documentation from previous steps as we do not want to include that.
695+
let out_dir = builder.stage_out(compiler, Mode::Librustc).join(target).join("doc");
691696
builder.clear_if_dirty(&out, &rustdoc);
692697
t!(symlink_dir_force(&builder.config, &out, &out_dir));
693698

699+
// Build cargo command.
694700
let mut cargo = builder.cargo(compiler, Mode::Librustc, target, "doc");
695701
cargo.env("RUSTDOCFLAGS", "--document-private-items");
696702
compile::rustc_cargo(builder, &mut cargo);
@@ -729,6 +735,76 @@ fn find_compiler_crates(
729735
}
730736
}
731737

738+
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
739+
pub struct Rustdoc {
740+
stage: u32,
741+
target: Interned<String>,
742+
}
743+
744+
impl Step for Rustdoc {
745+
type Output = ();
746+
const DEFAULT: bool = true;
747+
const ONLY_HOSTS: bool = true;
748+
749+
fn should_run(run: ShouldRun) -> ShouldRun {
750+
run.krate("rustdoc-tool")
751+
}
752+
753+
fn make_run(run: RunConfig) {
754+
run.builder.ensure(Rustdoc {
755+
stage: run.builder.top_stage,
756+
target: run.target,
757+
});
758+
}
759+
760+
/// Generate compiler documentation.
761+
///
762+
/// This will generate all documentation for compiler and dependencies.
763+
/// Compiler documentation is distributed separately, so we make sure
764+
/// we do not merge it with the other documentation from std, test and
765+
/// proc_macros. This is largely just a wrapper around `cargo doc`.
766+
fn run(self, builder: &Builder) {
767+
let stage = self.stage;
768+
let target = self.target;
769+
builder.info(&format!("Documenting stage{} rustdoc ({})", stage, target));
770+
771+
// This is the intended out directory for compiler documentation.
772+
let out = builder.compiler_doc_out(target);
773+
t!(fs::create_dir_all(&out));
774+
775+
// Get the correct compiler for this stage.
776+
let compiler = builder.compiler(stage, builder.config.build);
777+
let rustdoc = builder.rustdoc(compiler.host);
778+
let compiler = if builder.force_use_stage1(compiler, target) {
779+
builder.compiler(1, compiler.host)
780+
} else {
781+
compiler
782+
};
783+
784+
if !builder.config.compiler_docs {
785+
builder.info(&format!("\tskipping - compiler/librustdoc docs disabled"));
786+
return;
787+
}
788+
789+
// Build libstd docs so that we generate relative links.
790+
builder.ensure(Std { stage, target });
791+
792+
// Build rustdoc.
793+
builder.ensure(tool::Rustdoc { host: compiler.host });
794+
795+
// Symlink compiler docs to the output directory of rustdoc documentation.
796+
let out_dir = builder.stage_out(compiler, Mode::Tool).join(target).join("doc");
797+
t!(fs::create_dir_all(&out_dir));
798+
builder.clear_if_dirty(&out, &rustdoc);
799+
t!(symlink_dir_force(&builder.config, &out, &out_dir));
800+
801+
// Build cargo command.
802+
let mut cargo = prepare_tool_cargo(builder, compiler, target, "doc", "src/tools/rustdoc");
803+
cargo.env("RUSTDOCFLAGS", "--document-private-items");
804+
builder.run(&mut cargo);
805+
}
806+
}
807+
732808
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
733809
pub struct ErrorIndex {
734810
target: Interned<String>,

0 commit comments

Comments
 (0)