diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index 2748903f2d4..70b53cfc4e7 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -1231,7 +1231,9 @@ impl<'a> Builder<'a> { cargo.arg("--frozen"); } - cargo.env("RUSTC_INSTALL_BINDIR", &self.config.bindir); + // Try to use a sysroot-relative bindir, in case it was configured absolutely. + let bindir = self.config.bindir_relative().unwrap_or(&self.config.bindir); + cargo.env("RUSTC_INSTALL_BINDIR", bindir); self.ci_env.force_coloring_in_ci(&mut cargo); diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs index d1bdfa0a767..2493167f2f5 100644 --- a/src/bootstrap/config.rs +++ b/src/bootstrap/config.rs @@ -647,6 +647,17 @@ impl Config { config } + /// Try to find the relative path of `bindir`. + pub fn bindir_relative(&self) -> Option<&Path> { + let bindir = &self.bindir; + if bindir.is_relative() { + Some(bindir) + } else { + // Try to make it relative to the prefix. + bindir.strip_prefix(self.prefix.as_ref()?).ok() + } + } + /// Try to find the relative path of `libdir`. pub fn libdir_relative(&self) -> Option<&Path> { let libdir = self.libdir.as_ref()?;