Skip to content

Commit 0c572b1

Browse files
committed
[Mac] Consistently specify rpaths for plug-ins
C++ plug-ins now consistently use the `plugin_rpath` or `ui_plugin_rpath` macros to ensure they have `SKIP_BUILD_RPATH` set when building on Mac (i.e., no `LC_RPATH` is added). Rust plug-ins have their build.rs updated to only specify `-Wl,-rpath` when building for Linux. It is not needed on macOS. On macOS we instead explicitly specify an `@rpath`-relative install name. This doesn't change any behavior, but avoids leaving an absolute path as the library's install name and is consistent with CMake's behavior for C++ plug-ins.
1 parent 5957643 commit 0c572b1

File tree

15 files changed

+83
-9
lines changed

15 files changed

+83
-9
lines changed

arch/msp430/build.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,18 @@ fn main() {
55
println!("cargo::rustc-link-lib=dylib=binaryninjacore");
66
println!("cargo::rustc-link-search={}", link_path.to_str().unwrap());
77

8-
#[cfg(not(target_os = "windows"))]
8+
#[cfg(target_os = "linux")]
99
{
1010
println!(
1111
"cargo::rustc-link-arg=-Wl,-rpath,{0},-L{0}",
1212
link_path.to_string_lossy()
1313
);
1414
}
15+
16+
#[cfg(target_os = "macos")]
17+
{
18+
let crate_name = std::env::var("CARGO_PKG_NAME").expect("CARGO_PKG_NAME not set");
19+
let lib_name = crate_name.replace('-', "_");
20+
println!("cargo::rustc-link-arg=-Wl,-install_name,@rpath/lib{}.dylib", lib_name);
21+
}
1522
}

arch/riscv/build.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,18 @@ fn main() {
55
println!("cargo::rustc-link-lib=dylib=binaryninjacore");
66
println!("cargo::rustc-link-search={}", link_path.to_str().unwrap());
77

8-
#[cfg(not(target_os = "windows"))]
8+
#[cfg(target_os = "linux")]
99
{
1010
println!(
1111
"cargo::rustc-link-arg=-Wl,-rpath,{0},-L{0}",
1212
link_path.to_string_lossy()
1313
);
1414
}
15+
16+
#[cfg(target_os = "macos")]
17+
{
18+
let crate_name = std::env::var("CARGO_PKG_NAME").expect("CARGO_PKG_NAME not set");
19+
let lib_name = crate_name.replace('-', "_");
20+
println!("cargo::rustc-link-arg=-Wl,-install_name,@rpath/lib{}.dylib", lib_name);
21+
}
1522
}

plugins/dwarf/dwarf_export/build.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,18 @@ fn main() {
55
println!("cargo::rustc-link-lib=dylib=binaryninjacore");
66
println!("cargo::rustc-link-search={}", link_path.to_str().unwrap());
77

8-
#[cfg(not(target_os = "windows"))]
8+
#[cfg(target_os = "linux")]
99
{
1010
println!(
1111
"cargo::rustc-link-arg=-Wl,-rpath,{0},-L{0}",
1212
link_path.to_string_lossy()
1313
);
1414
}
15+
16+
#[cfg(target_os = "macos")]
17+
{
18+
let crate_name = std::env::var("CARGO_PKG_NAME").expect("CARGO_PKG_NAME not set");
19+
let lib_name = crate_name.replace('-', "_");
20+
println!("cargo::rustc-link-arg=-Wl,-install_name,@rpath/lib{}.dylib", lib_name);
21+
}
1522
}

plugins/dwarf/dwarf_import/build.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,18 @@ fn main() {
55
println!("cargo::rustc-link-lib=dylib=binaryninjacore");
66
println!("cargo::rustc-link-search={}", link_path.to_str().unwrap());
77

8-
#[cfg(not(target_os = "windows"))]
8+
#[cfg(target_os = "linux")]
99
{
1010
println!(
1111
"cargo::rustc-link-arg=-Wl,-rpath,{0},-L{0}",
1212
link_path.to_string_lossy()
1313
);
1414
}
15+
16+
#[cfg(target_os = "macos")]
17+
{
18+
let crate_name = std::env::var("CARGO_PKG_NAME").expect("CARGO_PKG_NAME not set");
19+
let lib_name = crate_name.replace('-', "_");
20+
println!("cargo::rustc-link-arg=-Wl,-install_name,@rpath/lib{}.dylib", lib_name);
21+
}
1522
}

plugins/efi_resolver/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ file(
2525

2626
add_library(efi_resolver SHARED ${SOURCE_FILES})
2727
target_link_libraries(efi_resolver binaryninjaapi)
28+
29+
plugin_rpath(efi_resolver)
2830
target_include_directories(${PROJECT_NAME} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/include")
2931
target_compile_features(efi_resolver PRIVATE cxx_std_20 c_std_99)
3032

plugins/idb_import/build.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,18 @@ fn main() {
55
println!("cargo::rustc-link-lib=dylib=binaryninjacore");
66
println!("cargo::rustc-link-search={}", link_path.to_str().unwrap());
77

8-
#[cfg(not(target_os = "windows"))]
8+
#[cfg(target_os = "linux")]
99
{
1010
println!(
1111
"cargo::rustc-link-arg=-Wl,-rpath,{0},-L{0}",
1212
link_path.to_string_lossy()
1313
);
1414
}
15+
16+
#[cfg(target_os = "macos")]
17+
{
18+
let crate_name = std::env::var("CARGO_PKG_NAME").expect("CARGO_PKG_NAME not set");
19+
let lib_name = crate_name.replace('-', "_");
20+
println!("cargo::rustc-link-arg=-Wl,-install_name,@rpath/lib{}.dylib", lib_name);
21+
}
1522
}

plugins/pdb-ng/build.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,18 @@ fn main() {
55
println!("cargo::rustc-link-lib=dylib=binaryninjacore");
66
println!("cargo::rustc-link-search={}", link_path.to_str().unwrap());
77

8-
#[cfg(not(target_os = "windows"))]
8+
#[cfg(target_os = "linux")]
99
{
1010
println!(
1111
"cargo::rustc-link-arg=-Wl,-rpath,{0},-L{0}",
1212
link_path.to_string_lossy()
1313
);
1414
}
15+
16+
#[cfg(target_os = "macos")]
17+
{
18+
let crate_name = std::env::var("CARGO_PKG_NAME").expect("CARGO_PKG_NAME not set");
19+
let lib_name = crate_name.replace('-', "_");
20+
println!("cargo::rustc-link-arg=-Wl,-install_name,@rpath/lib{}.dylib", lib_name);
21+
}
1522
}

plugins/svd/build.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,21 @@ fn main() {
77
println!("cargo::rustc-link-lib=dylib=binaryninjacore");
88
println!("cargo::rustc-link-search={}", link_path.to_str().unwrap());
99

10-
#[cfg(not(target_os = "windows"))]
10+
#[cfg(target_os = "linux")]
1111
{
1212
println!(
1313
"cargo::rustc-link-arg=-Wl,-rpath,{0},-L{0}",
1414
link_path.to_string_lossy()
1515
);
1616
}
1717

18+
#[cfg(target_os = "macos")]
19+
{
20+
let crate_name = std::env::var("CARGO_PKG_NAME").expect("CARGO_PKG_NAME not set");
21+
let lib_name = crate_name.replace('-', "_");
22+
println!("cargo::rustc-link-arg=-Wl,-install_name,@rpath/lib{}.dylib", lib_name);
23+
}
24+
1825
let out_dir = std::env::var("OUT_DIR").expect("OUT_DIR specified");
1926
let out_dir_path = PathBuf::from(out_dir);
2027

plugins/warp/build.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,21 @@ fn main() {
77
println!("cargo::rustc-link-lib=dylib=binaryninjacore");
88
println!("cargo::rustc-link-search={}", link_path.to_str().unwrap());
99

10-
#[cfg(not(target_os = "windows"))]
10+
#[cfg(target_os = "linux")]
1111
{
1212
println!(
1313
"cargo::rustc-link-arg=-Wl,-rpath,{0},-L{0}",
1414
link_path.to_string_lossy()
1515
);
1616
}
1717

18+
#[cfg(target_os = "macos")]
19+
{
20+
let crate_name = std::env::var("CARGO_PKG_NAME").expect("CARGO_PKG_NAME not set");
21+
let lib_name = crate_name.replace('-', "_");
22+
println!("cargo::rustc-link-arg=-Wl,-install_name,@rpath/lib{}.dylib", lib_name);
23+
}
24+
1825
let out_dir = std::env::var("OUT_DIR").expect("OUT_DIR specified");
1926
let out_dir_path = PathBuf::from(out_dir);
2027

plugins/workflow_objc/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ set(PLUGIN_SOURCE
2828
add_library(workflow_objc SHARED ${PLUGIN_SOURCE})
2929
target_link_libraries(workflow_objc binaryninjaapi)
3030
target_compile_features(workflow_objc PRIVATE cxx_std_20 c_std_99)
31+
plugin_rpath(workflow_objc)
3132

3233
# Library targets linking against the Binary Ninja API need to be compiled with
3334
# position-independent code on Linux.

0 commit comments

Comments
 (0)