@@ -14,8 +14,10 @@ import util::filesearch;
14
14
export get_rpath_flags, test;
15
15
16
16
fn get_rpath_flags ( sess : session:: session , out_filename : str ) -> [ str ] {
17
+ let os = sess. get_targ_cfg ( ) . os ;
18
+
17
19
// No rpath on windows
18
- if sess . get_targ_cfg ( ) . os == session:: os_win32 {
20
+ if os == session:: os_win32 {
19
21
ret [ ] ;
20
22
}
21
23
@@ -30,7 +32,7 @@ fn get_rpath_flags(sess: session::session, out_filename: str) -> [str] {
30
32
let libs = libs + [ get_sysroot_absolute_rt_lib ( sess) ] ;
31
33
32
34
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) ;
34
36
rpaths_to_flags ( rpaths)
35
37
}
36
38
@@ -47,7 +49,7 @@ fn rpaths_to_flags(rpaths: [str]) -> [str] {
47
49
vec:: map ( { |rpath| #fmt ( "-Wl,-rpath,%s" , rpath) } , rpaths)
48
50
}
49
51
50
- fn get_rpaths ( cwd : fs:: path , sysroot : fs:: path ,
52
+ fn get_rpaths ( os : session :: os , cwd : fs:: path , sysroot : fs:: path ,
51
53
output : fs:: path , libs : [ fs:: path ] ,
52
54
target_triple : str ) -> [ str ] {
53
55
log #fmt( "cwd: %s" , cwd) ;
@@ -62,7 +64,7 @@ fn get_rpaths(cwd: fs::path, sysroot: fs::path,
62
64
// Use relative paths to the libraries. Binaries can be moved
63
65
// as long as they maintain the relative relationship to the
64
66
// 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) ;
66
68
67
69
// Make backup absolute paths to the libraries. Binaries can
68
70
// 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,
89
91
ret rpaths;
90
92
}
91
93
92
- fn get_rpaths_relative_to_output ( cwd : fs:: path ,
94
+ fn get_rpaths_relative_to_output ( os : session:: os ,
95
+ cwd : fs:: path ,
93
96
output : fs:: path ,
94
97
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)
96
99
}
97
100
98
- fn get_rpath_relative_to_output ( cwd : fs:: path ,
101
+ fn get_rpath_relative_to_output ( os : session:: os ,
102
+ cwd : fs:: path ,
99
103
output : fs:: path ,
100
104
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 (
102
112
get_absolute ( cwd, output) ,
103
113
get_absolute ( cwd, lib) )
104
114
}
@@ -293,12 +303,21 @@ mod test {
293
303
}
294
304
295
305
#[ test]
306
+ #[ cfg( target_os = "linux" ) ]
296
307
fn test_rpath_relative ( ) {
297
- let res = get_rpath_relative_to_output (
308
+ let res = get_rpath_relative_to_output ( session :: os_linux ,
298
309
"/usr" , "bin/rustc" , "lib/libstd.so" ) ;
299
310
assert res == "$ORIGIN/../lib" ;
300
311
}
301
312
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
+
302
321
#[ test]
303
322
fn test_get_absolute_rpath ( ) {
304
323
let res = get_absolute_rpath ( "/usr" , "lib/libstd.so" ) ;
0 commit comments