Skip to content

Commit 2639a3a

Browse files
committed
Fix documentation of tools
1 parent db44fe7 commit 2639a3a

File tree

4 files changed

+54
-54
lines changed

4 files changed

+54
-54
lines changed

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

Lines changed: 46 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ use crate::core::build_steps::tool::{
1616
self, RustcPrivateCompilers, SourceType, Tool, prepare_tool_cargo,
1717
};
1818
use crate::core::builder::{
19-
self, Alias, Builder, Compiler, Kind, RunConfig, ShouldRun, Step, StepMetadata,
20-
crate_description,
19+
self, Builder, Compiler, Kind, RunConfig, ShouldRun, Step, StepMetadata, crate_description,
2120
};
2221
use crate::core::config::{Config, TargetSelection};
2322
use crate::helpers::{submodule_path_of, symlink_dir, t, up_to_date};
@@ -26,7 +25,7 @@ use crate::{FileType, Mode};
2625
macro_rules! book {
2726
($($name:ident, $path:expr, $book_name:expr, $lang:expr ;)+) => {
2827
$(
29-
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
28+
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
3029
pub struct $name {
3130
target: TargetSelection,
3231
}
@@ -797,13 +796,21 @@ pub struct Rustc {
797796

798797
impl Rustc {
799798
/// Document `stage` compiler for the given `target`.
800-
pub(crate) fn for_stage(builder: &Builder<'_>, target: TargetSelection, stage: u32) -> Self {
799+
pub(crate) fn for_stage(builder: &Builder<'_>, stage: u32, target: TargetSelection) -> Self {
800+
let build_compiler = prepare_doc_compiler(builder, target, stage);
801+
Self::from_build_compiler(builder, build_compiler, target)
802+
}
803+
804+
fn from_build_compiler(
805+
builder: &Builder<'_>,
806+
build_compiler: Compiler,
807+
target: TargetSelection,
808+
) -> Self {
801809
let crates = builder
802810
.in_tree_crates("rustc-main", Some(target))
803811
.into_iter()
804812
.map(|krate| krate.name.to_string())
805813
.collect();
806-
let build_compiler = prepare_doc_compiler(builder, target, stage);
807814
Self { build_compiler, target, crates }
808815
}
809816
}
@@ -821,7 +828,7 @@ impl Step for Rustc {
821828
}
822829

823830
fn make_run(run: RunConfig<'_>) {
824-
run.builder.ensure(Rustc::for_stage(run.builder, run.target, run.builder.top_stage));
831+
run.builder.ensure(Rustc::for_stage(run.builder, run.builder.top_stage, run.target));
825832
}
826833

827834
/// Generates compiler documentation.
@@ -942,12 +949,14 @@ macro_rules! tool_doc {
942949
(
943950
$tool: ident,
944951
$path: literal,
945-
$(rustc_tool = $rustc_tool:literal, )?
952+
$(rustc_private_tool = $rustc_private_tool:literal, )?
946953
$(is_library = $is_library:expr,)?
947954
$(crates = $crates:expr)?
948955
) => {
949956
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
950957
pub struct $tool {
958+
build_compiler: Compiler,
959+
mode: Mode,
951960
target: TargetSelection,
952961
}
953962

@@ -962,15 +971,26 @@ macro_rules! tool_doc {
962971
}
963972

964973
fn make_run(run: RunConfig<'_>) {
965-
run.builder.ensure($tool { target: run.target });
974+
let target = run.target;
975+
let (build_compiler, mode) = if true $(&& $rustc_private_tool)? {
976+
// Rustdoc needs the rustc sysroot available to build.
977+
let compilers = RustcPrivateCompilers::new(run.builder, run.builder.top_stage, target);
978+
979+
// Build rustc docs so that we generate relative links.
980+
run.builder.ensure(Rustc::from_build_compiler(run.builder, compilers.build_compiler(), target));
981+
982+
(compilers.build_compiler(), Mode::ToolRustc)
983+
} else {
984+
// bootstrap/host tools have to be documented with the stage 0 compiler
985+
(prepare_doc_compiler(run.builder, target, 1), Mode::ToolBootstrap)
986+
};
987+
988+
run.builder.ensure($tool { build_compiler, mode, target });
966989
}
967990

968-
/// Generates compiler documentation.
991+
/// Generates documentation for a tool.
969992
///
970-
/// This will generate all documentation for compiler and dependencies.
971-
/// Compiler documentation is distributed separately, so we make sure
972-
/// we do not merge it with the other documentation from std, test and
973-
/// proc_macros. This is largely just a wrapper around `cargo doc`.
993+
/// This is largely just a wrapper around `cargo doc`.
974994
fn run(self, builder: &Builder<'_>) {
975995
let mut source_type = SourceType::InTree;
976996

@@ -979,31 +999,17 @@ macro_rules! tool_doc {
979999
builder.require_submodule(&submodule_path, None);
9801000
}
9811001

982-
let stage = builder.top_stage;
983-
let target = self.target;
1002+
let $tool { build_compiler, mode, target } = self;
9841003

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

989-
let compiler = builder.compiler(stage, builder.config.host_target);
990-
builder.std(compiler, target);
991-
992-
if true $(&& $rustc_tool)? {
993-
// Build rustc docs so that we generate relative links.
994-
builder.ensure(Rustc::new(stage, target, builder));
995-
996-
// Rustdoc needs the rustc sysroot available to build.
997-
// FIXME: is there a way to only ensure `check::Rustc` here? Last time I tried it failed
998-
// with strange errors, but only on a full bors test ...
999-
builder.ensure(compile::Rustc::new(compiler, target));
1000-
}
1001-
10021008
// Build cargo command.
10031009
let mut cargo = prepare_tool_cargo(
10041010
builder,
1005-
compiler,
1006-
Mode::ToolRustc,
1011+
build_compiler,
1012+
mode,
10071013
target,
10081014
Kind::Doc,
10091015
$path,
@@ -1030,18 +1036,18 @@ macro_rules! tool_doc {
10301036
cargo.rustdocflag("--show-type-layout");
10311037
cargo.rustdocflag("--generate-link-to-definition");
10321038

1033-
let out_dir = builder.stage_out(compiler, Mode::ToolRustc).join(target).join("doc");
1039+
let out_dir = builder.stage_out(build_compiler, mode).join(target).join("doc");
10341040
$(for krate in $crates {
10351041
let dir_name = krate.replace("-", "_");
10361042
t!(fs::create_dir_all(out_dir.join(&*dir_name)));
10371043
})?
10381044

10391045
// Symlink compiler docs to the output directory of rustdoc documentation.
10401046
symlink_dir_force(&builder.config, &out, &out_dir);
1041-
let proc_macro_out_dir = builder.stage_out(compiler, Mode::ToolRustc).join("doc");
1047+
let proc_macro_out_dir = builder.stage_out(build_compiler, mode).join("doc");
10421048
symlink_dir_force(&builder.config, &out, &proc_macro_out_dir);
10431049

1044-
let _guard = builder.msg_doc(compiler, stringify!($tool).to_lowercase(), target);
1050+
let _guard = builder.msg_doc(build_compiler, stringify!($tool).to_lowercase(), target);
10451051
cargo.into_cmd().run(builder);
10461052

10471053
if !builder.config.dry_run() {
@@ -1055,7 +1061,7 @@ macro_rules! tool_doc {
10551061
}
10561062

10571063
fn metadata(&self) -> Option<StepMetadata> {
1058-
Some(StepMetadata::doc(stringify!($tool), self.target))
1064+
Some(StepMetadata::doc(stringify!($tool), self.target).built_by(self.build_compiler))
10591065
}
10601066
}
10611067
}
@@ -1065,7 +1071,7 @@ macro_rules! tool_doc {
10651071
tool_doc!(
10661072
BuildHelper,
10671073
"src/build_helper",
1068-
rustc_tool = false,
1074+
rustc_private_tool = false,
10691075
is_library = true,
10701076
crates = ["build_helper"]
10711077
);
@@ -1076,7 +1082,7 @@ tool_doc!(Miri, "src/tools/miri", crates = ["miri"]);
10761082
tool_doc!(
10771083
Cargo,
10781084
"src/tools/cargo",
1079-
rustc_tool = false,
1085+
rustc_private_tool = false,
10801086
crates = [
10811087
"cargo",
10821088
"cargo-credential",
@@ -1090,25 +1096,25 @@ tool_doc!(
10901096
"rustfix",
10911097
]
10921098
);
1093-
tool_doc!(Tidy, "src/tools/tidy", rustc_tool = false, crates = ["tidy"]);
1099+
tool_doc!(Tidy, "src/tools/tidy", rustc_private_tool = false, crates = ["tidy"]);
10941100
tool_doc!(
10951101
Bootstrap,
10961102
"src/bootstrap",
1097-
rustc_tool = false,
1103+
rustc_private_tool = false,
10981104
is_library = true,
10991105
crates = ["bootstrap"]
11001106
);
11011107
tool_doc!(
11021108
RunMakeSupport,
11031109
"src/tools/run-make-support",
1104-
rustc_tool = false,
1110+
rustc_private_tool = false,
11051111
is_library = true,
11061112
crates = ["run_make_support"]
11071113
);
11081114
tool_doc!(
11091115
Compiletest,
11101116
"src/tools/compiletest",
1111-
rustc_tool = false,
1117+
rustc_private_tool = false,
11121118
is_library = true,
11131119
crates = ["compiletest"]
11141120
);

src/bootstrap/src/core/build_steps/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,8 @@ impl Step for HtmlCheck {
214214
builder.default_doc(&[]);
215215
builder.ensure(crate::core::build_steps::doc::Rustc::for_stage(
216216
builder,
217-
self.target,
218217
builder.top_stage,
218+
self.target,
219219
));
220220

221221
builder

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,9 @@ impl Builder<'_> {
493493
if cmd_kind == Kind::Doc {
494494
let my_out = match mode {
495495
// This is the intended out directory for compiler documentation.
496-
Mode::Rustc | Mode::ToolRustc => self.compiler_doc_out(target),
496+
Mode::Rustc | Mode::ToolRustc | Mode::ToolBootstrap => {
497+
self.compiler_doc_out(target)
498+
}
497499
Mode::Std => {
498500
if self.config.cmd.json() {
499501
out_dir.join(target).join("json-doc")

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

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1793,11 +1793,8 @@ mod snapshot {
17931793
.path("src/tools/compiletest")
17941794
.stage(1)
17951795
.render_steps(), @r"
1796-
[build] llvm <host>
1797-
[build] rustc 0 <host> -> rustc 1 <host>
1798-
[build] rustc 1 <host> -> std 1 <host>
1799-
[build] rustdoc 1 <host>
1800-
[doc] Compiletest <host>
1796+
[build] rustdoc 0 <host>
1797+
[doc] rustc 0 <host> -> Compiletest 1 <host>
18011798
");
18021799
}
18031800

@@ -1809,13 +1806,8 @@ mod snapshot {
18091806
.path("src/tools/compiletest")
18101807
.stage(2)
18111808
.render_steps(), @r"
1812-
[build] llvm <host>
1813-
[build] rustc 0 <host> -> rustc 1 <host>
1814-
[build] rustc 1 <host> -> std 1 <host>
1815-
[build] rustc 1 <host> -> rustc 2 <host>
1816-
[build] rustc 2 <host> -> std 2 <host>
1817-
[build] rustdoc 2 <host>
1818-
[doc] Compiletest <host>
1809+
[build] rustdoc 0 <host>
1810+
[doc] rustc 0 <host> -> Compiletest 1 <host>
18191811
");
18201812
}
18211813

0 commit comments

Comments
 (0)