Skip to content

Commit af12878

Browse files
committed
Fix documentation of tools
1 parent 377ba9e commit af12878

File tree

4 files changed

+57
-55
lines changed

4 files changed

+57
-55
lines changed

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

Lines changed: 49 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ use std::path::{Path, PathBuf};
1212
use std::{env, fs, mem};
1313

1414
use crate::core::build_steps::compile;
15-
use crate::core::build_steps::tool::{self, SourceType, Tool, prepare_tool_cargo};
15+
use crate::core::build_steps::tool::{
16+
self, RustcPrivateCompilers, SourceType, Tool, prepare_tool_cargo,
17+
};
1618
use crate::core::builder::{
17-
self, Alias, Builder, Compiler, Kind, RunConfig, ShouldRun, Step, StepMetadata,
18-
crate_description,
19+
self, Builder, Compiler, Kind, RunConfig, ShouldRun, Step, StepMetadata, crate_description,
1920
};
2021
use crate::core::config::{Config, TargetSelection};
2122
use crate::helpers::{submodule_path_of, symlink_dir, t, up_to_date};
@@ -24,7 +25,7 @@ use crate::{FileType, Mode};
2425
macro_rules! book {
2526
($($name:ident, $path:expr, $book_name:expr, $lang:expr ;)+) => {
2627
$(
27-
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
28+
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
2829
pub struct $name {
2930
target: TargetSelection,
3031
}
@@ -795,13 +796,21 @@ pub struct Rustc {
795796

796797
impl Rustc {
797798
/// Document `stage` compiler for the given `target`.
798-
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 {
799809
let crates = builder
800810
.in_tree_crates("rustc-main", Some(target))
801811
.into_iter()
802812
.map(|krate| krate.name.to_string())
803813
.collect();
804-
let build_compiler = prepare_doc_compiler(builder, target, stage);
805814
Self { build_compiler, target, crates }
806815
}
807816
}
@@ -819,7 +828,7 @@ impl Step for Rustc {
819828
}
820829

821830
fn make_run(run: RunConfig<'_>) {
822-
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));
823832
}
824833

825834
/// Generates compiler documentation.
@@ -940,12 +949,14 @@ macro_rules! tool_doc {
940949
(
941950
$tool: ident,
942951
$path: literal,
943-
$(rustc_tool = $rustc_tool:literal, )?
952+
$(rustc_private_tool = $rustc_private_tool:literal, )?
944953
$(is_library = $is_library:expr,)?
945954
$(crates = $crates:expr)?
946955
) => {
947956
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
948957
pub struct $tool {
958+
build_compiler: Compiler,
959+
mode: Mode,
949960
target: TargetSelection,
950961
}
951962

@@ -960,15 +971,26 @@ macro_rules! tool_doc {
960971
}
961972

962973
fn make_run(run: RunConfig<'_>) {
963-
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 });
964989
}
965990

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

@@ -977,31 +999,17 @@ macro_rules! tool_doc {
977999
builder.require_submodule(&submodule_path, None);
9781000
}
9791001

980-
let stage = builder.top_stage;
981-
let target = self.target;
1002+
let $tool { build_compiler, mode, target } = self;
9821003

9831004
// This is the intended out directory for compiler documentation.
9841005
let out = builder.compiler_doc_out(target);
9851006
t!(fs::create_dir_all(&out));
9861007

987-
let compiler = builder.compiler(stage, builder.config.host_target);
988-
builder.std(compiler, target);
989-
990-
if true $(&& $rustc_tool)? {
991-
// Build rustc docs so that we generate relative links.
992-
builder.ensure(Rustc::new(stage, target, builder));
993-
994-
// Rustdoc needs the rustc sysroot available to build.
995-
// FIXME: is there a way to only ensure `check::Rustc` here? Last time I tried it failed
996-
// with strange errors, but only on a full bors test ...
997-
builder.ensure(compile::Rustc::new(compiler, target));
998-
}
999-
10001008
// Build cargo command.
10011009
let mut cargo = prepare_tool_cargo(
10021010
builder,
1003-
compiler,
1004-
Mode::ToolRustc,
1011+
build_compiler,
1012+
mode,
10051013
target,
10061014
Kind::Doc,
10071015
$path,
@@ -1028,18 +1036,18 @@ macro_rules! tool_doc {
10281036
cargo.rustdocflag("--show-type-layout");
10291037
cargo.rustdocflag("--generate-link-to-definition");
10301038

1031-
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");
10321040
$(for krate in $crates {
10331041
let dir_name = krate.replace("-", "_");
10341042
t!(fs::create_dir_all(out_dir.join(&*dir_name)));
10351043
})?
10361044

10371045
// Symlink compiler docs to the output directory of rustdoc documentation.
10381046
symlink_dir_force(&builder.config, &out, &out_dir);
1039-
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");
10401048
symlink_dir_force(&builder.config, &out, &proc_macro_out_dir);
10411049

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

10451053
if !builder.config.dry_run() {
@@ -1053,7 +1061,7 @@ macro_rules! tool_doc {
10531061
}
10541062

10551063
fn metadata(&self) -> Option<StepMetadata> {
1056-
Some(StepMetadata::doc(stringify!($tool), self.target))
1064+
Some(StepMetadata::doc(stringify!($tool), self.target).built_by(self.build_compiler))
10571065
}
10581066
}
10591067
}
@@ -1063,7 +1071,7 @@ macro_rules! tool_doc {
10631071
tool_doc!(
10641072
BuildHelper,
10651073
"src/build_helper",
1066-
rustc_tool = false,
1074+
rustc_private_tool = false,
10671075
is_library = true,
10681076
crates = ["build_helper"]
10691077
);
@@ -1074,7 +1082,7 @@ tool_doc!(Miri, "src/tools/miri", crates = ["miri"]);
10741082
tool_doc!(
10751083
Cargo,
10761084
"src/tools/cargo",
1077-
rustc_tool = false,
1085+
rustc_private_tool = false,
10781086
crates = [
10791087
"cargo",
10801088
"cargo-credential",
@@ -1088,25 +1096,25 @@ tool_doc!(
10881096
"rustfix",
10891097
]
10901098
);
1091-
tool_doc!(Tidy, "src/tools/tidy", rustc_tool = false, crates = ["tidy"]);
1099+
tool_doc!(Tidy, "src/tools/tidy", rustc_private_tool = false, crates = ["tidy"]);
10921100
tool_doc!(
10931101
Bootstrap,
10941102
"src/bootstrap",
1095-
rustc_tool = false,
1103+
rustc_private_tool = false,
10961104
is_library = true,
10971105
crates = ["bootstrap"]
10981106
);
10991107
tool_doc!(
11001108
RunMakeSupport,
11011109
"src/tools/run-make-support",
1102-
rustc_tool = false,
1110+
rustc_private_tool = false,
11031111
is_library = true,
11041112
crates = ["run_make_support"]
11051113
);
11061114
tool_doc!(
11071115
Compiletest,
11081116
"src/tools/compiletest",
1109-
rustc_tool = false,
1117+
rustc_private_tool = false,
11101118
is_library = true,
11111119
crates = ["compiletest"]
11121120
);

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
@@ -498,7 +498,9 @@ impl Builder<'_> {
498498
if cmd_kind == Kind::Doc {
499499
let my_out = match mode {
500500
// This is the intended out directory for compiler documentation.
501-
Mode::Rustc | Mode::ToolRustc => self.compiler_doc_out(target),
501+
Mode::Rustc | Mode::ToolRustc | Mode::ToolBootstrap => {
502+
self.compiler_doc_out(target)
503+
}
502504
Mode::Std => {
503505
if self.config.cmd.json() {
504506
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
@@ -1792,11 +1792,8 @@ mod snapshot {
17921792
.path("src/tools/compiletest")
17931793
.stage(1)
17941794
.render_steps(), @r"
1795-
[build] llvm <host>
1796-
[build] rustc 0 <host> -> rustc 1 <host>
1797-
[build] rustc 1 <host> -> std 1 <host>
1798-
[build] rustdoc 1 <host>
1799-
[doc] Compiletest <host>
1795+
[build] rustdoc 0 <host>
1796+
[doc] rustc 0 <host> -> Compiletest 1 <host>
18001797
");
18011798
}
18021799

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

0 commit comments

Comments
 (0)