Skip to content

Commit 21feca0

Browse files
committed
---
yaml --- r: 5715 b: refs/heads/master c: e4068f6 h: refs/heads/master i: 5713: 7a5d358 5711: 9fb5a03 v: v3
1 parent 97c6c76 commit 21feca0

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 06087e67e166512a623f584bfb52a17dfb974b51
2+
refs/heads/master: e4068f67153807f4c2554600bc60d2b3699ce682

trunk/src/comp/back/rpath.rs

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ import util::filesearch;
1414
export get_rpath_flags, test;
1515

1616
fn get_rpath_flags(sess: session::session, out_filename: str) -> [str] {
17+
let os = sess.get_targ_cfg().os;
18+
1719
// No rpath on windows
18-
if sess.get_targ_cfg().os == session::os_win32 {
20+
if os == session::os_win32 {
1921
ret [];
2022
}
2123

@@ -30,7 +32,7 @@ fn get_rpath_flags(sess: session::session, out_filename: str) -> [str] {
3032
let libs = libs + [get_sysroot_absolute_rt_lib(sess)];
3133

3234
let target_triple = sess.get_opts().target_triple;
33-
let rpaths = get_rpaths(cwd, sysroot, output, libs, target_triple);
35+
let rpaths = get_rpaths(os, cwd, sysroot, output, libs, target_triple);
3436
rpaths_to_flags(rpaths)
3537
}
3638

@@ -47,7 +49,7 @@ fn rpaths_to_flags(rpaths: [str]) -> [str] {
4749
vec::map({ |rpath| #fmt("-Wl,-rpath,%s",rpath)}, rpaths)
4850
}
4951

50-
fn get_rpaths(cwd: fs::path, sysroot: fs::path,
52+
fn get_rpaths(os: session::os, cwd: fs::path, sysroot: fs::path,
5153
output: fs::path, libs: [fs::path],
5254
target_triple: str) -> [str] {
5355
log #fmt("cwd: %s", cwd);
@@ -62,7 +64,7 @@ fn get_rpaths(cwd: fs::path, sysroot: fs::path,
6264
// Use relative paths to the libraries. Binaries can be moved
6365
// as long as they maintain the relative relationship to the
6466
// crates they depend on.
65-
let rel_rpaths = get_rpaths_relative_to_output(cwd, output, libs);
67+
let rel_rpaths = get_rpaths_relative_to_output(os, cwd, output, libs);
6668

6769
// Make backup absolute paths to the libraries. Binaries can
6870
// be moved as long as the crates they link against don't move.
@@ -89,16 +91,24 @@ fn get_rpaths(cwd: fs::path, sysroot: fs::path,
8991
ret rpaths;
9092
}
9193

92-
fn get_rpaths_relative_to_output(cwd: fs::path,
94+
fn get_rpaths_relative_to_output(os: session::os,
95+
cwd: fs::path,
9396
output: fs::path,
9497
libs: [fs::path]) -> [str] {
95-
vec::map(bind get_rpath_relative_to_output(cwd, output, _), libs)
98+
vec::map(bind get_rpath_relative_to_output(os, cwd, output, _), libs)
9699
}
97100

98-
fn get_rpath_relative_to_output(cwd: fs::path,
101+
fn get_rpath_relative_to_output(os: session::os,
102+
cwd: fs::path,
99103
output: fs::path,
100104
lib: fs::path) -> str {
101-
"$ORIGIN" + fs::path_sep() + get_relative_to(
105+
// Mac doesn't appear to support $ORIGIN
106+
let prefix = alt os {
107+
session::os_linux. { "$ORIGIN" + fs::path_sep() }
108+
session::os_macos. { "" }
109+
};
110+
111+
prefix + get_relative_to(
102112
get_absolute(cwd, output),
103113
get_absolute(cwd, lib))
104114
}
@@ -293,12 +303,21 @@ mod test {
293303
}
294304

295305
#[test]
306+
#[cfg(target_os = "linux")]
296307
fn test_rpath_relative() {
297-
let res = get_rpath_relative_to_output(
308+
let res = get_rpath_relative_to_output(session::os_linux,
298309
"/usr", "bin/rustc", "lib/libstd.so");
299310
assert res == "$ORIGIN/../lib";
300311
}
301312

313+
#[test]
314+
#[cfg(target_os = "macos")]
315+
fn test_rpath_relative() {
316+
let res = get_rpath_relative_to_output(session::os_macos,
317+
"/usr", "bin/rustc", "lib/libstd.so");
318+
assert res == "../lib";
319+
}
320+
302321
#[test]
303322
fn test_get_absolute_rpath() {
304323
let res = get_absolute_rpath("/usr", "lib/libstd.so");

0 commit comments

Comments
 (0)