@@ -77,6 +77,10 @@ fn get_rpaths(os: session::os,
77
77
// crates they depend on.
78
78
let rel_rpaths = get_rpaths_relative_to_output ( os, output, libs) ;
79
79
80
+ // Make backup absolute paths to the libraries. Binaries can
81
+ // be moved as long as the crates they link against don't move.
82
+ let abs_rpaths = get_absolute_rpaths ( libs) ;
83
+
80
84
// And a final backup rpath to the global library location.
81
85
let fallback_rpaths = ~[ get_install_prefix_rpath ( target_triple) ] ;
82
86
@@ -88,9 +92,11 @@ fn get_rpaths(os: session::os,
88
92
}
89
93
90
94
log_rpaths ( "relative" , rel_rpaths) ;
95
+ log_rpaths ( "absolute" , abs_rpaths) ;
91
96
log_rpaths ( "fallback" , fallback_rpaths) ;
92
97
93
98
let mut rpaths = rel_rpaths;
99
+ rpaths. push_all ( abs_rpaths) ;
94
100
rpaths. push_all ( fallback_rpaths) ;
95
101
96
102
// Remove duplicates
@@ -160,6 +166,14 @@ pub fn get_relative_to(abs1: &Path, abs2: &Path) -> Path {
160
166
}
161
167
}
162
168
169
+ fn get_absolute_rpaths ( libs : & [ Path ] ) -> ~[ Path ] {
170
+ vec:: map ( libs, |a| get_absolute_rpath ( a) )
171
+ }
172
+
173
+ pub fn get_absolute_rpath ( lib : & Path ) -> Path {
174
+ os:: make_absolute ( lib) . dir_path ( )
175
+ }
176
+
163
177
#[ cfg( stage0) ]
164
178
pub fn get_install_prefix_rpath ( target_triple : & str ) -> Path {
165
179
let install_prefix = env ! ( "CFG_PREFIX" ) ;
@@ -198,12 +212,13 @@ pub fn minimize_rpaths(rpaths: &[Path]) -> ~[Path] {
198
212
#[ cfg( unix, test) ]
199
213
mod test {
200
214
use core:: prelude:: * ;
215
+ use core:: os;
201
216
202
217
// FIXME(#2119): the outer attribute should be #[cfg(unix, test)], then
203
218
// these redundant #[cfg(test)] blocks can be removed
204
219
#[ cfg( test) ]
205
220
#[ cfg( test) ]
206
- use back:: rpath:: { get_install_prefix_rpath} ;
221
+ use back:: rpath:: { get_absolute_rpath , get_install_prefix_rpath} ;
207
222
use back:: rpath:: { get_relative_to, get_rpath_relative_to_output} ;
208
223
use back:: rpath:: { minimize_rpaths, rpaths_to_flags} ;
209
224
use driver:: session;
@@ -347,4 +362,14 @@ mod test {
347
362
&Path(" lib/libstd. so"));
348
363
assert_eq!(res.to_str(), ~" @executable_path/../lib");
349
364
}
365
+
366
+ #[test]
367
+ fn test_get_absolute_rpath() {
368
+ let res = get_absolute_rpath(&Path(" lib/libstd. so"));
369
+ debug!(" test_get_absolute_rpath: %s vs. %s",
370
+ res.to_str(),
371
+ os::make_absolute(&Path(" lib")).to_str());
372
+
373
+ assert_eq!(res, os::make_absolute(&Path(" lib") ) ) ;
374
+ }
350
375
}
0 commit comments