Skip to content

Commit bb23b17

Browse files
This fixes doctests in stage 1
The RUSTDOC_LIBDIR should be rustc_libdir, not sysroot_libdir; rustdoc is like the compiler and should link against rustc's libdir. Some people currently (i.e., in general, may not be on master) have doc tests working, but no attempt to determine why has been attempted.
1 parent 861d007 commit bb23b17

File tree

2 files changed

+17
-24
lines changed

2 files changed

+17
-24
lines changed

Diff for: 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() {

Diff for: src/bootstrap/tool.rs

+12-18
Original file line numberDiff line numberDiff line change
@@ -425,24 +425,18 @@ impl Step for Rustdoc {
425425
return builder.initial_rustc.with_file_name(exe("rustdoc", &target_compiler.host));
426426
}
427427
let target = target_compiler.host;
428-
let build_compiler = if target_compiler.stage == 0 {
429-
builder.compiler(0, builder.config.build)
430-
} else if target_compiler.stage >= 2 {
431-
// Past stage 2, we consider the compiler to be ABI-compatible and hence capable of
432-
// building rustdoc itself.
433-
builder.compiler(target_compiler.stage, builder.config.build)
434-
} else {
435-
// Similar to `compile::Assemble`, build with the previous stage's compiler. Otherwise
436-
// we'd have stageN/bin/rustc and stageN/bin/rustdoc be effectively different stage
437-
// compilers, which isn't what we want.
438-
builder.compiler(target_compiler.stage - 1, builder.config.build)
439-
};
440-
441-
builder.ensure(compile::Rustc { compiler: build_compiler, target });
442-
builder.ensure(compile::Rustc {
443-
compiler: build_compiler,
444-
target: builder.config.build,
445-
});
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.
446440

447441
let mut cargo = prepare_tool_cargo(
448442
builder,

0 commit comments

Comments
 (0)