Skip to content

Commit 80970e6

Browse files
committed
rustbuild: Restore Config.libdir_relative
This re-introduces a `Config.libdir_relative` field, now derived from `libdir` and made relative to `prefix` if necessary. This fixes a regression from #46592 when `--libdir` is given an absolute path. `Builder::sysroot_libdir` should always use a relative path so its callers don't clobber system locations, and `librustc` also asserts that `CFG_LIBDIR_RELATIVE` is really relative.
1 parent 27a046e commit 80970e6

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

src/bootstrap/builder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -444,8 +444,8 @@ impl<'a> Builder<'a> {
444444

445445
fn run(self, builder: &Builder) -> Interned<PathBuf> {
446446
let compiler = self.compiler;
447-
let lib = if compiler.stage >= 1 && builder.build.config.libdir.is_some() {
448-
builder.build.config.libdir.clone().unwrap()
447+
let lib = if compiler.stage >= 1 && builder.build.config.libdir_relative.is_some() {
448+
builder.build.config.libdir_relative.clone().unwrap()
449449
} else {
450450
PathBuf::from("lib")
451451
};

src/bootstrap/compile.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ fn rustc_cargo_env(build: &Build, cargo: &mut Command) {
517517
.env("CFG_PREFIX", build.config.prefix.clone().unwrap_or_default());
518518

519519
let libdir_relative =
520-
build.config.libdir.clone().unwrap_or(PathBuf::from("lib"));
520+
build.config.libdir_relative.clone().unwrap_or(PathBuf::from("lib"));
521521
cargo.env("CFG_LIBDIR_RELATIVE", libdir_relative);
522522

523523
// If we're not building a compiler with debugging information then remove

src/bootstrap/config.rs

+17
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ pub struct Config {
126126
pub docdir: Option<PathBuf>,
127127
pub bindir: Option<PathBuf>,
128128
pub libdir: Option<PathBuf>,
129+
pub libdir_relative: Option<PathBuf>,
129130
pub mandir: Option<PathBuf>,
130131
pub codegen_tests: bool,
131132
pub nodejs: Option<PathBuf>,
@@ -417,6 +418,22 @@ impl Config {
417418
config.mandir = install.mandir.clone().map(PathBuf::from);
418419
}
419420

421+
// Try to infer `libdir_relative` from `libdir`.
422+
if let Some(ref libdir) = config.libdir {
423+
let mut libdir = libdir.as_path();
424+
if !libdir.is_relative() {
425+
// Try to make it relative to the prefix.
426+
if let Some(ref prefix) = config.prefix {
427+
if let Ok(suffix) = libdir.strip_prefix(prefix) {
428+
libdir = suffix;
429+
}
430+
}
431+
}
432+
if libdir.is_relative() {
433+
config.libdir_relative = Some(libdir.to_path_buf());
434+
}
435+
}
436+
420437
// Store off these values as options because if they're not provided
421438
// we'll infer default values for them later
422439
let mut thinlto = None;

0 commit comments

Comments
 (0)