Skip to content

Commit 3d471c7

Browse files
committed
Fix staging for doc compiler
1 parent d8dca72 commit 3d471c7

File tree

4 files changed

+35
-34
lines changed

4 files changed

+35
-34
lines changed

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

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -756,21 +756,31 @@ fn doc_std(
756756
builder.cp_link_r(&out_dir, out);
757757
}
758758

759+
/// Prepare a compiler that will be able to document something for `target` at `stage`.
760+
fn prepare_doc_compiler(builder: &Builder<'_>, target: TargetSelection, stage: u32) -> Compiler {
761+
let build_compiler = builder.compiler(stage - 1, builder.host_target);
762+
builder.std(build_compiler, target);
763+
build_compiler
764+
}
765+
766+
/// Document the compiler for the given `target` using rustdoc from `build_compiler`.
759767
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
760768
pub struct Rustc {
761-
pub stage: u32,
762-
pub target: TargetSelection,
769+
build_compiler: Compiler,
770+
target: TargetSelection,
763771
crates: Vec<String>,
764772
}
765773

766774
impl Rustc {
767-
pub(crate) fn new(stage: u32, target: TargetSelection, builder: &Builder<'_>) -> Self {
775+
/// Document `stage` compiler for the given `target`.
776+
pub(crate) fn for_stage(builder: &Builder<'_>, target: TargetSelection, stage: u32) -> Self {
768777
let crates = builder
769778
.in_tree_crates("rustc-main", Some(target))
770779
.into_iter()
771780
.map(|krate| krate.name.to_string())
772781
.collect();
773-
Self { stage, target, crates }
782+
let build_compiler = prepare_doc_compiler(builder, target, stage);
783+
Self { build_compiler, target, crates }
774784
}
775785
}
776786

@@ -787,11 +797,7 @@ impl Step for Rustc {
787797
}
788798

789799
fn make_run(run: RunConfig<'_>) {
790-
run.builder.ensure(Rustc {
791-
stage: run.builder.top_stage,
792-
target: run.target,
793-
crates: run.make_run_crates(Alias::Compiler),
794-
});
800+
run.builder.ensure(Rustc::for_stage(run.builder, run.target, run.builder.top_stage));
795801
}
796802

797803
/// Generates compiler documentation.
@@ -801,7 +807,6 @@ impl Step for Rustc {
801807
/// we do not merge it with the other documentation from std, test and
802808
/// proc_macros. This is largely just a wrapper around `cargo doc`.
803809
fn run(self, builder: &Builder<'_>) {
804-
let stage = self.stage;
805810
let target = self.target;
806811

807812
// This is the intended out directory for compiler documentation.
@@ -810,21 +815,21 @@ impl Step for Rustc {
810815

811816
// Build the standard library, so that proc-macros can use it.
812817
// (Normally, only the metadata would be necessary, but proc-macros are special since they run at compile-time.)
813-
let compiler = builder.compiler(stage, builder.config.host_target);
814-
builder.std(compiler, builder.config.host_target);
818+
let build_compiler = self.build_compiler;
819+
builder.std(build_compiler, builder.config.host_target);
815820

816821
let _guard = builder.msg_rustc_tool(
817822
Kind::Doc,
818-
stage,
823+
build_compiler.stage,
819824
format!("compiler{}", crate_description(&self.crates)),
820-
compiler.host,
825+
build_compiler.host,
821826
target,
822827
);
823828

824829
// Build cargo command.
825830
let mut cargo = builder::Cargo::new(
826831
builder,
827-
compiler,
832+
build_compiler,
828833
Mode::Rustc,
829834
SourceType::InTree,
830835
target,
@@ -842,7 +847,7 @@ impl Step for Rustc {
842847
// If there is any bug, please comment out the next line.
843848
cargo.rustdocflag("--generate-link-to-definition");
844849

845-
compile::rustc_cargo(builder, &mut cargo, target, &compiler, &self.crates);
850+
compile::rustc_cargo(builder, &mut cargo, target, &build_compiler, &self.crates);
846851
cargo.arg("-Zskip-rustdoc-fingerprint");
847852

848853
// Only include compiler crates, no dependencies of those, such as `libc`.
@@ -857,7 +862,7 @@ impl Step for Rustc {
857862

858863
let mut to_open = None;
859864

860-
let out_dir = builder.stage_out(compiler, Mode::Rustc).join(target).join("doc");
865+
let out_dir = builder.stage_out(build_compiler, Mode::Rustc).join(target).join("doc");
861866
for krate in &*self.crates {
862867
// Create all crate output directories first to make sure rustdoc uses
863868
// relative links.
@@ -879,7 +884,7 @@ impl Step for Rustc {
879884
symlink_dir_force(&builder.config, &out, &out_dir);
880885
// Cargo puts proc macros in `target/doc` even if you pass `--target`
881886
// explicitly (https://github.com/rust-lang/cargo/issues/7677).
882-
let proc_macro_out_dir = builder.stage_out(compiler, Mode::Rustc).join("doc");
887+
let proc_macro_out_dir = builder.stage_out(build_compiler, Mode::Rustc).join("doc");
883888
symlink_dir_force(&builder.config, &out, &proc_macro_out_dir);
884889

885890
cargo.into_cmd().run(builder);
@@ -905,7 +910,7 @@ impl Step for Rustc {
905910
}
906911

907912
fn metadata(&self) -> Option<StepMetadata> {
908-
Some(StepMetadata::doc("rustc", self.target).stage(self.stage))
913+
Some(StepMetadata::doc("rustc", self.target).built_by(self.build_compiler))
909914
}
910915
}
911916

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,10 @@ impl Step for HtmlCheck {
212212
}
213213
// Ensure that a few different kinds of documentation are available.
214214
builder.default_doc(&[]);
215-
builder.ensure(crate::core::build_steps::doc::Rustc::new(
216-
builder.top_stage,
217-
self.target,
215+
builder.ensure(crate::core::build_steps::doc::Rustc::for_stage(
218216
builder,
217+
self.target,
218+
builder.top_stage,
219219
));
220220

221221
builder

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1756,11 +1756,9 @@ mod snapshot {
17561756
.path("compiler")
17571757
.stage(1)
17581758
.render_steps(), @r"
1759+
[build] rustdoc 0 <host>
17591760
[build] llvm <host>
1760-
[build] rustc 0 <host> -> rustc 1 <host>
1761-
[build] rustc 1 <host> -> std 1 <host>
1762-
[build] rustdoc 1 <host>
1763-
[doc] rustc 1 <host>
1761+
[doc] rustc 0 <host> -> rustc 1 <host>
17641762
");
17651763
}
17661764

@@ -1775,10 +1773,8 @@ mod snapshot {
17751773
[build] llvm <host>
17761774
[build] rustc 0 <host> -> rustc 1 <host>
17771775
[build] rustc 1 <host> -> std 1 <host>
1778-
[build] rustc 1 <host> -> rustc 2 <host>
1779-
[build] rustc 2 <host> -> std 2 <host>
1780-
[build] rustdoc 2 <host>
1781-
[doc] rustc 2 <host>
1776+
[build] rustdoc 1 <host>
1777+
[doc] rustc 1 <host> -> rustc 2 <host>
17821778
");
17831779
}
17841780

src/ci/docker/host-x86_64/pr-check-2/Dockerfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ ENV SCRIPT \
3131
python3 ../x.py clippy ci && \
3232
python3 ../x.py test --stage 1 core alloc std test proc_macro && \
3333
python3 ../x.py test --stage 1 src/tools/compiletest && \
34-
python3 ../x.py doc --stage 0 bootstrap && \
34+
python3 ../x.py doc bootstrap && \
3535
# Build both public and internal documentation.
36-
RUSTDOCFLAGS=\"--document-private-items --document-hidden-items\" python3 ../x.py doc --stage 0 compiler && \
37-
RUSTDOCFLAGS=\"--document-private-items --document-hidden-items\" python3 ../x.py doc --stage 1 library && \
36+
RUSTDOCFLAGS=\"--document-private-items --document-hidden-items\" python3 ../x.py doc compiler && \
37+
RUSTDOCFLAGS=\"--document-private-items --document-hidden-items\" python3 ../x.py doc library && \
3838
mkdir -p /checkout/obj/staging/doc && \
3939
cp -r build/x86_64-unknown-linux-gnu/doc /checkout/obj/staging && \
40-
RUSTDOCFLAGS=\"--document-private-items --document-hidden-items\" python3 ../x.py doc --stage 1 library/test && \
40+
RUSTDOCFLAGS=\"--document-private-items --document-hidden-items\" python3 ../x.py doc library/test && \
4141
# The BOOTSTRAP_TRACING flag is added to verify whether the
4242
# bootstrap process compiles successfully with this flag enabled.
4343
BOOTSTRAP_TRACING=1 python3 ../x.py --help

0 commit comments

Comments
 (0)