Skip to content

Commit 8cce35e

Browse files
committed
Follow symlinks in sysroot
Before this commit, rustc looked in `dirname $0`/../lib for libraries but that doesn't work when rustc is invoked through a symlink. This commit makes rustc look in `dirname $(readlink $0)`/../lib, i.e. it first canonicalizes the symlink before walking up the directory tree. Fixes #3632.
1 parent cdd146b commit 8cce35e

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/librustc/metadata/filesearch.rs

+18-2
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,24 @@ fn make_rustpkg_target_lib_path(dir: &Path,
160160
}
161161

162162
pub fn get_or_default_sysroot() -> Path {
163-
match os::self_exe_path() {
164-
option::Some(p) => { let mut p = p; p.pop(); p }
163+
// Follow symlinks. If the resolved path is relative, make it absolute.
164+
fn canonicalize(path: Option<Path>) -> Option<Path> {
165+
path.and_then(|mut path|
166+
match io::io_error::cond.trap(|_| ()).inside(|| fs::readlink(&path)) {
167+
Some(canon) => {
168+
if canon.is_absolute() {
169+
Some(canon)
170+
} else {
171+
path.pop();
172+
Some(path.join(canon))
173+
}
174+
},
175+
None => Some(path),
176+
})
177+
}
178+
179+
match canonicalize(os::self_exe_name()) {
180+
option::Some(p) => { let mut p = p; p.pop(); p.pop(); p }
165181
option::None => fail!("can't determine value for sysroot")
166182
}
167183
}

0 commit comments

Comments
 (0)