Skip to content

Commit b5f2a71

Browse files
committed
Document Cargo with in-tree rustdoc
1 parent 79bdc62 commit b5f2a71

File tree

3 files changed

+63
-24
lines changed

3 files changed

+63
-24
lines changed

src/bootstrap/src/core/build_steps/doc.rs

Lines changed: 47 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,7 @@ macro_rules! tool_doc {
965965
(
966966
$tool: ident,
967967
$path: literal,
968-
$(rustc_private_tool = $rustc_private_tool:literal, )?
968+
mode = $mode:expr,
969969
$(is_library = $is_library:expr,)?
970970
$(crates = $crates:expr)?
971971
) => {
@@ -988,20 +988,29 @@ macro_rules! tool_doc {
988988

989989
fn make_run(run: RunConfig<'_>) {
990990
let target = run.target;
991-
let (build_compiler, mode) = if true $(&& $rustc_private_tool)? {
992-
// Rustdoc needs the rustc sysroot available to build.
993-
let compilers = RustcPrivateCompilers::new(run.builder, run.builder.top_stage, target);
994-
995-
// Build rustc docs so that we generate relative links.
996-
run.builder.ensure(Rustc::from_build_compiler(run.builder, compilers.build_compiler(), target));
997-
998-
(compilers.build_compiler(), Mode::ToolRustcPrivate)
999-
} else {
1000-
// bootstrap/host tools have to be documented with the stage 0 compiler
1001-
(prepare_doc_compiler(run.builder, run.builder.host_target, 1), Mode::ToolBootstrap)
991+
let build_compiler = match $mode {
992+
Mode::ToolRustcPrivate => {
993+
// Rustdoc needs the rustc sysroot available to build.
994+
let compilers = RustcPrivateCompilers::new(run.builder, run.builder.top_stage, target);
995+
996+
// Build rustc docs so that we generate relative links.
997+
run.builder.ensure(Rustc::from_build_compiler(run.builder, compilers.build_compiler(), target));
998+
compilers.build_compiler()
999+
}
1000+
Mode::ToolBootstrap => {
1001+
// bootstrap/host tools should be documented with the stage 0 compiler
1002+
prepare_doc_compiler(run.builder, run.builder.host_target, 1)
1003+
}
1004+
Mode::ToolTarget => {
1005+
// target tools should be documented with the in-tree compiler
1006+
prepare_doc_compiler(run.builder, run.builder.host_target, 2)
1007+
}
1008+
_ => {
1009+
panic!("Unexpected tool mode for documenting: {:?}", $mode);
1010+
}
10021011
};
10031012

1004-
run.builder.ensure($tool { build_compiler, mode, target });
1013+
run.builder.ensure($tool { build_compiler, mode: $mode, target });
10051014
}
10061015

10071016
/// Generates documentation for a tool.
@@ -1087,18 +1096,33 @@ macro_rules! tool_doc {
10871096
tool_doc!(
10881097
BuildHelper,
10891098
"src/build_helper",
1090-
rustc_private_tool = false,
1099+
mode = Mode::ToolBootstrap,
10911100
is_library = true,
10921101
crates = ["build_helper"]
10931102
);
1094-
tool_doc!(Rustdoc, "src/tools/rustdoc", crates = ["rustdoc", "rustdoc-json-types"]);
1095-
tool_doc!(Rustfmt, "src/tools/rustfmt", crates = ["rustfmt-nightly", "rustfmt-config_proc_macro"]);
1096-
tool_doc!(Clippy, "src/tools/clippy", crates = ["clippy_config", "clippy_utils"]);
1097-
tool_doc!(Miri, "src/tools/miri", crates = ["miri"]);
1103+
tool_doc!(
1104+
Rustdoc,
1105+
"src/tools/rustdoc",
1106+
mode = Mode::ToolRustcPrivate,
1107+
crates = ["rustdoc", "rustdoc-json-types"]
1108+
);
1109+
tool_doc!(
1110+
Rustfmt,
1111+
"src/tools/rustfmt",
1112+
mode = Mode::ToolRustcPrivate,
1113+
crates = ["rustfmt-nightly", "rustfmt-config_proc_macro"]
1114+
);
1115+
tool_doc!(
1116+
Clippy,
1117+
"src/tools/clippy",
1118+
mode = Mode::ToolRustcPrivate,
1119+
crates = ["clippy_config", "clippy_utils"]
1120+
);
1121+
tool_doc!(Miri, "src/tools/miri", mode = Mode::ToolRustcPrivate, crates = ["miri"]);
10981122
tool_doc!(
10991123
Cargo,
11001124
"src/tools/cargo",
1101-
rustc_private_tool = false,
1125+
mode = Mode::ToolTarget,
11021126
crates = [
11031127
"cargo",
11041128
"cargo-credential",
@@ -1112,25 +1136,25 @@ tool_doc!(
11121136
"rustfix",
11131137
]
11141138
);
1115-
tool_doc!(Tidy, "src/tools/tidy", rustc_private_tool = false, crates = ["tidy"]);
1139+
tool_doc!(Tidy, "src/tools/tidy", mode = Mode::ToolBootstrap, crates = ["tidy"]);
11161140
tool_doc!(
11171141
Bootstrap,
11181142
"src/bootstrap",
1119-
rustc_private_tool = false,
1143+
mode = Mode::ToolBootstrap,
11201144
is_library = true,
11211145
crates = ["bootstrap"]
11221146
);
11231147
tool_doc!(
11241148
RunMakeSupport,
11251149
"src/tools/run-make-support",
1126-
rustc_private_tool = false,
1150+
mode = Mode::ToolBootstrap,
11271151
is_library = true,
11281152
crates = ["run_make_support"]
11291153
);
11301154
tool_doc!(
11311155
Compiletest,
11321156
"src/tools/compiletest",
1133-
rustc_private_tool = false,
1157+
mode = Mode::ToolBootstrap,
11341158
is_library = true,
11351159
crates = ["compiletest"]
11361160
);

src/bootstrap/src/core/builder/cargo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ impl Builder<'_> {
533533
if cmd_kind == Kind::Doc {
534534
let my_out = match mode {
535535
// This is the intended out directory for compiler documentation.
536-
Mode::Rustc | Mode::ToolRustcPrivate | Mode::ToolBootstrap => {
536+
Mode::Rustc | Mode::ToolRustcPrivate | Mode::ToolBootstrap | Mode::ToolTarget => {
537537
self.compiler_doc_out(target)
538538
}
539539
Mode::Std => {

src/bootstrap/src/core/builder/tests.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2462,6 +2462,21 @@ mod snapshot {
24622462
");
24632463
}
24642464

2465+
#[test]
2466+
fn doc_cargo() {
2467+
let ctx = TestCtx::new();
2468+
insta::assert_snapshot!(
2469+
ctx.config("doc")
2470+
.path("cargo")
2471+
.render_steps(), @r"
2472+
[build] llvm <host>
2473+
[build] rustc 0 <host> -> rustc 1 <host>
2474+
[build] rustc 1 <host> -> std 1 <host>
2475+
[build] rustdoc 1 <host>
2476+
[doc] rustc 1 <host> -> Cargo 2 <host>
2477+
");
2478+
}
2479+
24652480
#[test]
24662481
fn doc_core() {
24672482
let ctx = TestCtx::new();

0 commit comments

Comments
 (0)