Skip to content

Commit 15d0c31

Browse files
authored
Rollup merge of rust-lang#66317 - cuviper:bindir_relative, r=Mark-Simulacrum
Use a relative bindir for rustdoc to find rustc In bootstrap, we set `RUSTC_INSTALL_BINDIR` to `config.bindir`, so rustdoc can find rustc relative to the toolchain sysroot. However, if a distro script like Fedora's `%configure` sets an absolute path, then rustdoc's `sysroot.join(bin_path)` ignores that sysroot altogether. That would be OK once the toolchain is actually installed, but it breaks the in-tree doc tests during the build, since `/usr/bin/rustc` is still the old version. So now we try to make `RUSTC_INSTALL_BINDIR` relative to the sysroot prefix in the first place. r? @Mark-Simulacrum
2 parents 57e0220 + bfa5e5f commit 15d0c31

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/bootstrap/builder.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1242,7 +1242,8 @@ impl<'a> Builder<'a> {
12421242
cargo.arg("--frozen");
12431243
}
12441244

1245-
cargo.env("RUSTC_INSTALL_BINDIR", &self.config.bindir);
1245+
// Try to use a sysroot-relative bindir, in case it was configured absolutely.
1246+
cargo.env("RUSTC_INSTALL_BINDIR", self.config.bindir_relative());
12461247

12471248
self.ci_env.force_coloring_in_ci(&mut cargo);
12481249

src/bootstrap/config.rs

+14
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,20 @@ impl Config {
647647
config
648648
}
649649

650+
/// Try to find the relative path of `bindir`, otherwise return it in full.
651+
pub fn bindir_relative(&self) -> &Path {
652+
let bindir = &self.bindir;
653+
if bindir.is_absolute() {
654+
// Try to make it relative to the prefix.
655+
if let Some(prefix) = &self.prefix {
656+
if let Ok(stripped) = bindir.strip_prefix(prefix) {
657+
return stripped;
658+
}
659+
}
660+
}
661+
bindir
662+
}
663+
650664
/// Try to find the relative path of `libdir`.
651665
pub fn libdir_relative(&self) -> Option<&Path> {
652666
let libdir = self.libdir.as_ref()?;

0 commit comments

Comments
 (0)