rustc: Use realpath() for sysroot/rpath
When calculating the sysroot, it's more accurate to use realpath() rather than just one readlink() to account for any intermediate symlinks that the rustc binary resolves itself to. For rpath, realpath() is necessary because the rpath must dictate a relative rpath from the destination back to the originally linked library, which works more robustly if there are no symlinks involved. Concretely, any binary generated on OSX into $TMPDIR requires an absolute rpath because the temporary directory is behind a symlink with one layer of indirection. This symlink causes all relative rpaths to fail to resolve. cc #11734 cc #11857
This commit is contained in:
parent
25a6b6ef8b
commit
3f2c55f7d5
2 changed files with 10 additions and 14 deletions
|
|
@ -12,9 +12,10 @@
|
|||
use driver::session::Session;
|
||||
use metadata::cstore;
|
||||
use metadata::filesearch;
|
||||
use util::fs;
|
||||
|
||||
use collections::HashSet;
|
||||
use std::{os, slice};
|
||||
use std::os;
|
||||
use syntax::abi;
|
||||
|
||||
fn not_win32(os: abi::Os) -> bool {
|
||||
|
|
@ -121,9 +122,9 @@ pub fn get_rpath_relative_to_output(os: abi::Os,
|
|||
abi::OsWin32 => unreachable!()
|
||||
};
|
||||
|
||||
let mut lib = os::make_absolute(lib);
|
||||
let mut lib = fs::realpath(&os::make_absolute(lib)).unwrap();
|
||||
lib.pop();
|
||||
let mut output = os::make_absolute(output);
|
||||
let mut output = fs::realpath(&os::make_absolute(output)).unwrap();
|
||||
output.pop();
|
||||
let relative = lib.path_relative_from(&output);
|
||||
let relative = relative.expect("could not create rpath relative to output");
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@ use std::os;
|
|||
use std::io::fs;
|
||||
use collections::HashSet;
|
||||
|
||||
use myfs = util::fs;
|
||||
|
||||
pub enum FileMatch { FileMatches, FileDoesntMatch }
|
||||
|
||||
// A module for searching for libraries
|
||||
|
|
@ -156,17 +158,10 @@ fn make_rustpkg_target_lib_path(sysroot: &Path,
|
|||
pub fn get_or_default_sysroot() -> Path {
|
||||
// Follow symlinks. If the resolved path is relative, make it absolute.
|
||||
fn canonicalize(path: Option<Path>) -> Option<Path> {
|
||||
path.and_then(|mut path|
|
||||
match fs::readlink(&path) {
|
||||
Ok(canon) => {
|
||||
if canon.is_absolute() {
|
||||
Some(canon)
|
||||
} else {
|
||||
path.pop();
|
||||
Some(path.join(canon))
|
||||
}
|
||||
},
|
||||
Err(..) => Some(path),
|
||||
path.and_then(|path|
|
||||
match myfs::realpath(&path) {
|
||||
Ok(canon) => Some(canon),
|
||||
Err(e) => fail!("failed to get realpath: {}", e),
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue