diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index 66a1c9724620..05aa6283ee57 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -444,8 +444,8 @@ impl<'a> Builder<'a> { fn run(self, builder: &Builder) -> Interned { let compiler = self.compiler; - let lib = if compiler.stage >= 1 && builder.build.config.libdir.is_some() { - builder.build.config.libdir.clone().unwrap() + let lib = if compiler.stage >= 1 && builder.build.config.libdir_relative.is_some() { + builder.build.config.libdir_relative.clone().unwrap() } else { PathBuf::from("lib") }; diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index 2dcc0e0e7cd9..e6389f27785b 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -517,7 +517,7 @@ fn rustc_cargo_env(build: &Build, cargo: &mut Command) { .env("CFG_PREFIX", build.config.prefix.clone().unwrap_or_default()); let libdir_relative = - build.config.libdir.clone().unwrap_or(PathBuf::from("lib")); + build.config.libdir_relative.clone().unwrap_or(PathBuf::from("lib")); cargo.env("CFG_LIBDIR_RELATIVE", libdir_relative); // If we're not building a compiler with debugging information then remove diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs index 812ca6d64fb6..6d98153e233b 100644 --- a/src/bootstrap/config.rs +++ b/src/bootstrap/config.rs @@ -126,6 +126,7 @@ pub struct Config { pub docdir: Option, pub bindir: Option, pub libdir: Option, + pub libdir_relative: Option, pub mandir: Option, pub codegen_tests: bool, pub nodejs: Option, @@ -417,6 +418,22 @@ impl Config { config.mandir = install.mandir.clone().map(PathBuf::from); } + // Try to infer `libdir_relative` from `libdir`. + if let Some(ref libdir) = config.libdir { + let mut libdir = libdir.as_path(); + if !libdir.is_relative() { + // Try to make it relative to the prefix. + if let Some(ref prefix) = config.prefix { + if let Ok(suffix) = libdir.strip_prefix(prefix) { + libdir = suffix; + } + } + } + if libdir.is_relative() { + config.libdir_relative = Some(libdir.to_path_buf()); + } + } + // Store off these values as options because if they're not provided // we'll infer default values for them later let mut thinlto = None;