Fix rpath for libdir is specified

Signed-off-by: WANG Rui <wangrui@loongson.cn>
This commit is contained in:
WANG Rui 2023-07-15 11:07:26 +08:00
parent ad963232d9
commit e326e1ad18

View File

@ -1644,6 +1644,7 @@ pub fn cargo(
// fun to pass a flag to a tool to pass a flag to pass a flag to a tool // fun to pass a flag to a tool to pass a flag to pass a flag to a tool
// to change a flag in a binary? // to change a flag in a binary?
if self.config.rpath_enabled(target) && util::use_host_linker(target) { if self.config.rpath_enabled(target) && util::use_host_linker(target) {
let libdir = self.sysroot_libdir_relative(compiler).to_str().unwrap();
let rpath = if target.contains("apple") { let rpath = if target.contains("apple") {
// Note that we need to take one extra step on macOS to also pass // Note that we need to take one extra step on macOS to also pass
// `-Wl,-instal_name,@rpath/...` to get things to work right. To // `-Wl,-instal_name,@rpath/...` to get things to work right. To
@ -1651,10 +1652,10 @@ pub fn cargo(
// so. Note that this is definitely a hack, and we should likely // so. Note that this is definitely a hack, and we should likely
// flesh out rpath support more fully in the future. // flesh out rpath support more fully in the future.
rustflags.arg("-Zosx-rpath-install-name"); rustflags.arg("-Zosx-rpath-install-name");
Some("-Wl,-rpath,@loader_path/../lib") Some(format!("-Wl,-rpath,@loader_path/../{}", libdir))
} else if !target.contains("windows") && !target.contains("aix") { } else if !target.contains("windows") && !target.contains("aix") {
rustflags.arg("-Clink-args=-Wl,-z,origin"); rustflags.arg("-Clink-args=-Wl,-z,origin");
Some("-Wl,-rpath,$ORIGIN/../lib") Some(format!("-Wl,-rpath,$ORIGIN/../{}", libdir))
} else { } else {
None None
}; };