Skip to content

Commit 2a122dc

Browse files
Rollup merge of #86737 - jyn514:doc-tools, r=Mark-Simulacrum
Document rustfmt on nightly-rustc - Refactor the doc step for Rustdoc into a macro - Call the macro for both rustdoc and rustfmt - Add a `recursion_limit` macro to avoid overflow errors This does not currently pass --document-private-items for rustfmt due to rust-lang/cargo#8422 (comment). r? `@Mark-Simulacrum` cc `@calebcartwright`
2 parents ccdbda6 + 01cf0bd commit 2a122dc

File tree

3 files changed

+82
-67
lines changed

3 files changed

+82
-67
lines changed

src/bootstrap/builder.rs

+1
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,7 @@ impl<'a> Builder<'a> {
465465
doc::Std,
466466
doc::Rustc,
467467
doc::Rustdoc,
468+
doc::Rustfmt,
468469
doc::ErrorIndex,
469470
doc::Nomicon,
470471
doc::Reference,

src/bootstrap/doc.rs

+80-67
Original file line numberDiff line numberDiff line change
@@ -593,84 +593,97 @@ impl Step for Rustc {
593593
}
594594
}
595595

596-
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
597-
pub struct Rustdoc {
598-
stage: u32,
599-
target: TargetSelection,
600-
}
601-
602-
impl Step for Rustdoc {
603-
type Output = ();
604-
const DEFAULT: bool = true;
605-
const ONLY_HOSTS: bool = true;
606-
607-
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
608-
run.krate("rustdoc-tool")
609-
}
610-
611-
fn make_run(run: RunConfig<'_>) {
612-
run.builder.ensure(Rustdoc { stage: run.builder.top_stage, target: run.target });
613-
}
614-
615-
/// Generates compiler documentation.
616-
///
617-
/// This will generate all documentation for compiler and dependencies.
618-
/// Compiler documentation is distributed separately, so we make sure
619-
/// we do not merge it with the other documentation from std, test and
620-
/// proc_macros. This is largely just a wrapper around `cargo doc`.
621-
fn run(self, builder: &Builder<'_>) {
622-
let stage = self.stage;
623-
let target = self.target;
624-
builder.info(&format!("Documenting stage{} rustdoc ({})", stage, target));
625-
626-
// This is the intended out directory for compiler documentation.
627-
let out = builder.compiler_doc_out(target);
628-
t!(fs::create_dir_all(&out));
596+
macro_rules! tool_doc {
597+
($tool: ident, $should_run: literal, $path: literal, [$($krate: literal),+ $(,)?] $(, binary=$bin:expr)?) => {
598+
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
599+
pub struct $tool {
600+
stage: u32,
601+
target: TargetSelection,
602+
}
629603

630-
let compiler = builder.compiler(stage, builder.config.build);
604+
impl Step for $tool {
605+
type Output = ();
606+
const DEFAULT: bool = true;
607+
const ONLY_HOSTS: bool = true;
631608

632-
if !builder.config.compiler_docs {
633-
builder.info("\tskipping - compiler/librustdoc docs disabled");
634-
return;
635-
}
609+
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
610+
run.krate($should_run)
611+
}
636612

637-
// Build rustc docs so that we generate relative links.
638-
builder.ensure(Rustc { stage, target });
613+
fn make_run(run: RunConfig<'_>) {
614+
run.builder.ensure($tool { stage: run.builder.top_stage, target: run.target });
615+
}
639616

640-
// Build rustdoc.
641-
builder.ensure(tool::Rustdoc { compiler });
617+
/// Generates compiler documentation.
618+
///
619+
/// This will generate all documentation for compiler and dependencies.
620+
/// Compiler documentation is distributed separately, so we make sure
621+
/// we do not merge it with the other documentation from std, test and
622+
/// proc_macros. This is largely just a wrapper around `cargo doc`.
623+
fn run(self, builder: &Builder<'_>) {
624+
let stage = self.stage;
625+
let target = self.target;
626+
builder.info(&format!("Documenting stage{} {} ({})", stage, stringify!($tool).to_lowercase(), target));
642627

643-
// Symlink compiler docs to the output directory of rustdoc documentation.
644-
let out_dir = builder.stage_out(compiler, Mode::ToolRustc).join(target.triple).join("doc");
645-
t!(fs::create_dir_all(&out_dir));
646-
t!(symlink_dir_force(&builder.config, &out, &out_dir));
628+
// This is the intended out directory for compiler documentation.
629+
let out = builder.compiler_doc_out(target);
630+
t!(fs::create_dir_all(&out));
647631

648-
// Build cargo command.
649-
let mut cargo = prepare_tool_cargo(
650-
builder,
651-
compiler,
652-
Mode::ToolRustc,
653-
target,
654-
"doc",
655-
"src/tools/rustdoc",
656-
SourceType::InTree,
657-
&[],
658-
);
632+
let compiler = builder.compiler(stage, builder.config.build);
659633

660-
cargo.arg("-Zskip-rustdoc-fingerprint");
661-
// Only include compiler crates, no dependencies of those, such as `libc`.
662-
cargo.arg("--no-deps");
663-
cargo.arg("-p").arg("rustdoc");
664-
cargo.arg("-p").arg("rustdoc-json-types");
634+
if !builder.config.compiler_docs {
635+
builder.info("\tskipping - compiler/tool docs disabled");
636+
return;
637+
}
665638

666-
cargo.rustdocflag("--document-private-items");
667-
cargo.rustdocflag("--enable-index-page");
668-
cargo.rustdocflag("--show-type-layout");
669-
cargo.rustdocflag("-Zunstable-options");
670-
builder.run(&mut cargo.into());
639+
// Build rustc docs so that we generate relative links.
640+
builder.ensure(Rustc { stage, target });
641+
642+
// Symlink compiler docs to the output directory of rustdoc documentation.
643+
let out_dir = builder.stage_out(compiler, Mode::ToolRustc).join(target.triple).join("doc");
644+
t!(fs::create_dir_all(&out_dir));
645+
t!(symlink_dir_force(&builder.config, &out, &out_dir));
646+
647+
// Build cargo command.
648+
let mut cargo = prepare_tool_cargo(
649+
builder,
650+
compiler,
651+
Mode::ToolRustc,
652+
target,
653+
"doc",
654+
$path,
655+
SourceType::InTree,
656+
&[],
657+
);
658+
659+
cargo.arg("-Zskip-rustdoc-fingerprint");
660+
// Only include compiler crates, no dependencies of those, such as `libc`.
661+
cargo.arg("--no-deps");
662+
$(
663+
cargo.arg("-p").arg($krate);
664+
)+
665+
666+
$(if !$bin {
667+
cargo.rustdocflag("--document-private-items");
668+
})?
669+
cargo.rustdocflag("--enable-index-page");
670+
cargo.rustdocflag("--show-type-layout");
671+
cargo.rustdocflag("-Zunstable-options");
672+
builder.run(&mut cargo.into());
673+
}
674+
}
671675
}
672676
}
673677

678+
tool_doc!(Rustdoc, "rustdoc-tool", "src/tools/rustdoc", ["rustdoc", "rustdoc-json-types"]);
679+
tool_doc!(
680+
Rustfmt,
681+
"rustfmt-nightly",
682+
"src/tools/rustfmt",
683+
["rustfmt-nightly", "rustfmt-config_proc_macro"],
684+
binary = true
685+
);
686+
674687
#[derive(Ord, PartialOrd, Debug, Copy, Clone, Hash, PartialEq, Eq)]
675688
pub struct ErrorIndex {
676689
pub target: TargetSelection,

src/tools/rustfmt/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#![feature(rustc_private)]
22
#![deny(rust_2018_idioms)]
33
#![warn(unreachable_pub)]
4+
#![recursion_limit = "256"]
45

56
#[macro_use]
67
extern crate derive_new;

0 commit comments

Comments
 (0)