about summary refs log tree commit diff
path: root/src/comp
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2011-10-06 14:28:52 -0700
committerBrian Anderson <banderson@mozilla.com>2011-10-06 14:29:03 -0700
commite4068f67153807f4c2554600bc60d2b3699ce682 (patch)
tree3c0c58b202575b37fc41f482cc5bacabcd44d386 /src/comp
parent06087e67e166512a623f584bfb52a17dfb974b51 (diff)
downloadrust-e4068f67153807f4c2554600bc60d2b3699ce682.tar.gz
rust-e4068f67153807f4c2554600bc60d2b3699ce682.zip
Mac doesn't seem to support rpath $ORIGIN
Diffstat (limited to 'src/comp')
-rw-r--r--src/comp/back/rpath.rs37
1 files changed, 28 insertions, 9 deletions
diff --git a/src/comp/back/rpath.rs b/src/comp/back/rpath.rs
index 2e9ac877254..3dc7c46ba6d 100644
--- a/src/comp/back/rpath.rs
+++ b/src/comp/back/rpath.rs
@@ -14,8 +14,10 @@ import util::filesearch;
 export get_rpath_flags, test;
 
 fn get_rpath_flags(sess: session::session, out_filename: str) -> [str] {
+    let os = sess.get_targ_cfg().os;
+
     // No rpath on windows
-    if sess.get_targ_cfg().os == session::os_win32 {
+    if os == session::os_win32 {
         ret [];
     }
 
@@ -30,7 +32,7 @@ fn get_rpath_flags(sess: session::session, out_filename: str) -> [str] {
     let libs = libs + [get_sysroot_absolute_rt_lib(sess)];
 
     let target_triple = sess.get_opts().target_triple;
-    let rpaths = get_rpaths(cwd, sysroot, output, libs, target_triple);
+    let rpaths = get_rpaths(os, cwd, sysroot, output, libs, target_triple);
     rpaths_to_flags(rpaths)
 }
 
@@ -47,7 +49,7 @@ fn rpaths_to_flags(rpaths: [str]) -> [str] {
     vec::map({ |rpath| #fmt("-Wl,-rpath,%s",rpath)}, rpaths)
 }
 
-fn get_rpaths(cwd: fs::path, sysroot: fs::path,
+fn get_rpaths(os: session::os, cwd: fs::path, sysroot: fs::path,
               output: fs::path, libs: [fs::path],
               target_triple: str) -> [str] {
     log #fmt("cwd: %s", cwd);
@@ -62,7 +64,7 @@ fn get_rpaths(cwd: fs::path, sysroot: fs::path,
     // Use relative paths to the libraries. Binaries can be moved
     // as long as they maintain the relative relationship to the
     // crates they depend on.
-    let rel_rpaths = get_rpaths_relative_to_output(cwd, output, libs);
+    let rel_rpaths = get_rpaths_relative_to_output(os, cwd, output, libs);
 
     // Make backup absolute paths to the libraries. Binaries can
     // 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,
     ret rpaths;
 }
 
-fn get_rpaths_relative_to_output(cwd: fs::path,
+fn get_rpaths_relative_to_output(os: session::os,
+                                 cwd: fs::path,
                                  output: fs::path,
                                  libs: [fs::path]) -> [str] {
-    vec::map(bind get_rpath_relative_to_output(cwd, output, _), libs)
+    vec::map(bind get_rpath_relative_to_output(os, cwd, output, _), libs)
 }
 
-fn get_rpath_relative_to_output(cwd: fs::path,
+fn get_rpath_relative_to_output(os: session::os,
+                                cwd: fs::path,
                                 output: fs::path,
                                 lib: fs::path) -> str {
-    "$ORIGIN" + fs::path_sep() + get_relative_to(
+    // Mac doesn't appear to support $ORIGIN
+    let prefix = alt os {
+        session::os_linux. { "$ORIGIN" + fs::path_sep() }
+        session::os_macos. { "" }
+    };
+
+    prefix + get_relative_to(
         get_absolute(cwd, output),
         get_absolute(cwd, lib))
 }
@@ -293,13 +303,22 @@ mod test {
     }
 
     #[test]
+    #[cfg(target_os = "linux")]
     fn test_rpath_relative() {
-        let res = get_rpath_relative_to_output(
+        let res = get_rpath_relative_to_output(session::os_linux,
             "/usr", "bin/rustc", "lib/libstd.so");
         assert res == "$ORIGIN/../lib";
     }
 
     #[test]
+    #[cfg(target_os = "macos")]
+    fn test_rpath_relative() {
+        let res = get_rpath_relative_to_output(session::os_macos,
+            "/usr", "bin/rustc", "lib/libstd.so");
+        assert res == "../lib";
+    }
+
+    #[test]
     fn test_get_absolute_rpath() {
         let res = get_absolute_rpath("/usr", "lib/libstd.so");
         assert res == "/usr/lib";