Skip to content

Commit c005afc

Browse files
committed
Auto merge of #58238 - Mark-Simulacrum:doctest-fix, r=alexcrichton
Fixes rustdoc in stage 0, stage 1 When a request for rustdoc is passed for stage 0, x.py build --stage 0 src/tools/rustdoc or ensure(tool::Rustdoc { .. }) with top_stage = 0, we return the rustdoc for that compiler (i.e., the beta rustdoc). This fixes stage 0 of #52186 as well as being part of general workflow improvements (making stage 0 testing for std work) for rustbuild. The stage 1 fix (second commit) completely resolves the problem, so this fixes #52186.
2 parents ccd23b9 + bb23b17 commit c005afc

File tree

2 files changed

+23
-24
lines changed

2 files changed

+23
-24
lines changed

src/bootstrap/builder.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -677,10 +677,9 @@ impl<'a> Builder<'a> {
677677
let compiler = self.compiler(self.top_stage, host);
678678
cmd.env("RUSTC_STAGE", compiler.stage.to_string())
679679
.env("RUSTC_SYSROOT", self.sysroot(compiler))
680-
.env(
681-
"RUSTDOC_LIBDIR",
682-
self.sysroot_libdir(compiler, self.config.build),
683-
)
680+
// Note that this is *not* the sysroot_libdir because rustdoc must be linked
681+
// equivalently to rustc.
682+
.env("RUSTDOC_LIBDIR", self.rustc_libdir(compiler))
684683
.env("CFG_RELEASE_CHANNEL", &self.config.channel)
685684
.env("RUSTDOC_REAL", self.rustdoc(host))
686685
.env("RUSTDOC_CRATE_VERSION", self.rust_version())
@@ -874,7 +873,7 @@ impl<'a> Builder<'a> {
874873
} else {
875874
&maybe_sysroot
876875
};
877-
let libdir = sysroot.join(libdir(&compiler.host));
876+
let libdir = self.rustc_libdir(compiler);
878877

879878
// Customize the compiler we're running. Specify the compiler to cargo
880879
// as our shim and then pass it some various options used to configure
@@ -916,7 +915,7 @@ impl<'a> Builder<'a> {
916915
cargo.env("RUSTC_ERROR_FORMAT", error_format);
917916
}
918917
if cmd != "build" && cmd != "check" && cmd != "rustc" && want_rustdoc {
919-
cargo.env("RUSTDOC_LIBDIR", self.sysroot_libdir(compiler, self.config.build));
918+
cargo.env("RUSTDOC_LIBDIR", self.rustc_libdir(compiler));
920919
}
921920

922921
if mode.is_tool() {

src/bootstrap/tool.rs

+18-18
Original file line numberDiff line numberDiff line change
@@ -418,25 +418,25 @@ impl Step for Rustdoc {
418418

419419
fn run(self, builder: &Builder) -> PathBuf {
420420
let target_compiler = builder.compiler(builder.top_stage, self.host);
421+
if target_compiler.stage == 0 {
422+
if !target_compiler.is_snapshot(builder) {
423+
panic!("rustdoc in stage 0 must be snapshot rustdoc");
424+
}
425+
return builder.initial_rustc.with_file_name(exe("rustdoc", &target_compiler.host));
426+
}
421427
let target = target_compiler.host;
422-
let build_compiler = if target_compiler.stage == 0 {
423-
builder.compiler(0, builder.config.build)
424-
} else if target_compiler.stage >= 2 {
425-
// Past stage 2, we consider the compiler to be ABI-compatible and hence capable of
426-
// building rustdoc itself.
427-
builder.compiler(target_compiler.stage, builder.config.build)
428-
} else {
429-
// Similar to `compile::Assemble`, build with the previous stage's compiler. Otherwise
430-
// we'd have stageN/bin/rustc and stageN/bin/rustdoc be effectively different stage
431-
// compilers, which isn't what we want.
432-
builder.compiler(target_compiler.stage - 1, builder.config.build)
433-
};
434-
435-
builder.ensure(compile::Rustc { compiler: build_compiler, target });
436-
builder.ensure(compile::Rustc {
437-
compiler: build_compiler,
438-
target: builder.config.build,
439-
});
428+
// Similar to `compile::Assemble`, build with the previous stage's compiler. Otherwise
429+
// we'd have stageN/bin/rustc and stageN/bin/rustdoc be effectively different stage
430+
// compilers, which isn't what we want. Rustdoc should be linked in the same way as the
431+
// rustc compiler it's paired with, so it must be built with the previous stage compiler.
432+
let build_compiler = builder.compiler(target_compiler.stage - 1, builder.config.build);
433+
434+
// The presence of `target_compiler` ensures that the necessary libraries (codegen backends,
435+
// compiler libraries, ...) are built. Rustdoc does not require the presence of any
436+
// libraries within sysroot_libdir (i.e., rustlib), though doctests may want it (since
437+
// they'll be linked to those libraries). As such, don't explicitly `ensure` any additional
438+
// libraries here. The intuition here is that If we've built a compiler, we should be able
439+
// to build rustdoc.
440440

441441
let mut cargo = prepare_tool_cargo(
442442
builder,

0 commit comments

Comments
 (0)