Skip to content

Commit 644774c

Browse files
committed
auto merge of #7192 : brson/rust/rpath, r=thestinger
r? @thestinger This reverts commit 708395d. Fixes #7191.
2 parents 9a5bdd7 + fd09e40 commit 644774c

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

src/librustc/back/rpath.rs

+26-1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ fn get_rpaths(os: session::os,
7777
// crates they depend on.
7878
let rel_rpaths = get_rpaths_relative_to_output(os, output, libs);
7979

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+
8084
// And a final backup rpath to the global library location.
8185
let fallback_rpaths = ~[get_install_prefix_rpath(target_triple)];
8286

@@ -88,9 +92,11 @@ fn get_rpaths(os: session::os,
8892
}
8993

9094
log_rpaths("relative", rel_rpaths);
95+
log_rpaths("absolute", abs_rpaths);
9196
log_rpaths("fallback", fallback_rpaths);
9297

9398
let mut rpaths = rel_rpaths;
99+
rpaths.push_all(abs_rpaths);
94100
rpaths.push_all(fallback_rpaths);
95101

96102
// Remove duplicates
@@ -160,6 +166,14 @@ pub fn get_relative_to(abs1: &Path, abs2: &Path) -> Path {
160166
}
161167
}
162168

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+
163177
#[cfg(stage0)]
164178
pub fn get_install_prefix_rpath(target_triple: &str) -> Path {
165179
let install_prefix = env!("CFG_PREFIX");
@@ -198,12 +212,13 @@ pub fn minimize_rpaths(rpaths: &[Path]) -> ~[Path] {
198212
#[cfg(unix, test)]
199213
mod test {
200214
use core::prelude::*;
215+
use core::os;
201216

202217
// FIXME(#2119): the outer attribute should be #[cfg(unix, test)], then
203218
// these redundant #[cfg(test)] blocks can be removed
204219
#[cfg(test)]
205220
#[cfg(test)]
206-
use back::rpath::{get_install_prefix_rpath};
221+
use back::rpath::{get_absolute_rpath, get_install_prefix_rpath};
207222
use back::rpath::{get_relative_to, get_rpath_relative_to_output};
208223
use back::rpath::{minimize_rpaths, rpaths_to_flags};
209224
use driver::session;
@@ -347,4 +362,14 @@ mod test {
347362
&Path("lib/libstd.so"));
348363
assert_eq!(res.to_str(), ~"@executable_path/../lib");
349364
}
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+
}
350375
}

0 commit comments

Comments
 (0)