Use sysroot instead of CFG_PREFIX for the rpath

CFG_PREFIX is incorrect for rustup installed rustc versions. It also
causes unnecessary recompilation when changing the install prefix.
This commit is contained in:
bjorn3 2021-06-05 16:36:27 +02:00
parent 016e9b5e33
commit a3205a6698
2 changed files with 3 additions and 5 deletions

View file

@ -1567,13 +1567,12 @@ fn add_rpath_args(
) {
// FIXME (#2397): At some point we want to rpath our guesses as to
// where extern libraries might live, based on the
// addl_lib_search_paths
// add_lib_search_paths
if sess.opts.cg.rpath {
let target_triple = sess.opts.target_triple.triple();
let mut get_install_prefix_lib_path = || {
let install_prefix = option_env!("CFG_PREFIX").expect("CFG_PREFIX");
let tlib = rustc_target::target_rustlib_path(&sess.sysroot, target_triple).join("lib");
let mut path = PathBuf::from(install_prefix);
let mut path = PathBuf::from(&sess.sysroot);
path.push(&tlib);
path

View file

@ -629,8 +629,7 @@ pub fn rustc_cargo_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetS
cargo
.env("CFG_RELEASE", builder.rust_release())
.env("CFG_RELEASE_CHANNEL", &builder.config.channel)
.env("CFG_VERSION", builder.rust_version())
.env("CFG_PREFIX", builder.config.prefix.clone().unwrap_or_default());
.env("CFG_VERSION", builder.rust_version());
let libdir_relative = builder.config.libdir_relative().unwrap_or_else(|| Path::new("lib"));
cargo.env("CFG_LIBDIR_RELATIVE", libdir_relative);