Skip to content

Commit f28931f

Browse files
committed
Rollup merge of rust-lang#48362 - cuviper:libdir_relative, r=Mark-Simulacrum
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 rust-lang#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.
2 parents 6627cba + 8174c0d commit f28931f

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

src/bootstrap/builder.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -444,10 +444,11 @@ 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 config = &builder.build.config;
448+
let lib = if compiler.stage >= 1 && config.libdir_relative().is_some() {
449+
builder.build.config.libdir_relative().unwrap()
449450
} else {
450-
PathBuf::from("lib")
451+
Path::new("lib")
451452
};
452453
let sysroot = builder.sysroot(self.compiler).join(lib)
453454
.join("rustlib").join(self.target).join("lib");

src/bootstrap/compile.rs

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

519-
let libdir_relative =
520-
build.config.libdir.clone().unwrap_or(PathBuf::from("lib"));
519+
let libdir_relative = build.config.libdir_relative().unwrap_or(Path::new("lib"));
521520
cargo.env("CFG_LIBDIR_RELATIVE", libdir_relative);
522521

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

src/bootstrap/config.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use std::collections::{HashMap, HashSet};
1717
use std::env;
1818
use std::fs::File;
1919
use std::io::prelude::*;
20-
use std::path::PathBuf;
20+
use std::path::{Path, PathBuf};
2121
use std::process;
2222
use std::cmp;
2323

@@ -564,6 +564,17 @@ impl Config {
564564
config
565565
}
566566

567+
/// Try to find the relative path of `libdir`.
568+
pub fn libdir_relative(&self) -> Option<&Path> {
569+
let libdir = self.libdir.as_ref()?;
570+
if libdir.is_relative() {
571+
Some(libdir)
572+
} else {
573+
// Try to make it relative to the prefix.
574+
libdir.strip_prefix(self.prefix.as_ref()?).ok()
575+
}
576+
}
577+
567578
pub fn verbose(&self) -> bool {
568579
self.verbose > 0
569580
}

0 commit comments

Comments
 (0)