Skip to content

Commit 62878fb

Browse files
committed
WARP: Update build system to find binja dylibs on macOS
1 parent e2cfbbd commit 62878fb

File tree

2 files changed

+41
-11
lines changed

2 files changed

+41
-11
lines changed

plugins/warp/README.md

+1-10
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,4 @@ Example: `./sigem mylibrary.a` or `./sigem ./all-libs/`
4141

4242
Once its finished you should see a `.sbin` file next to the input file, this can be moved into the corresponding signature folder (see the [user docs](https://docs.binary.ninja/dev/annotation.html?h=install+path#signature-library) for more info)
4343

44-
If you encounter malloc errors or instability try and adjust the number of parallel threads using `RAYON_NUM_THREADS` environment variable (ex. `RAYON_NUM_THREADS=1 ./sigem mylib.a`)
45-
46-
#### macOS
47-
48-
If you are on macOS and the `sigem` binary fails to run due to missing `libbinaryninjacore.1.dylib`, you can set your [`DYLD_LIBRARY_PATH`](x-man-page://1/dyld) to include the `${DEP_BINARYNINJACORE_PATH}/Contents/MacOS/` directory.
49-
50-
```sh
51-
export DYLD_LIBRARY_PATH="${DYLD_LIBRARY_PATH}:${DEP_BINARYNINJACORE_PATH}/Contents/MacOS/"
52-
./sigem --help
53-
```
44+
If you encounter malloc errors or instability try and adjust the number of parallel threads using `RAYON_NUM_THREADS` environment variable (ex. `RAYON_NUM_THREADS=1 ./sigem mylib.a`)

plugins/warp/build.rs

+40-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#![allow(unused_imports)]
22
use std::path::PathBuf;
33
use std::process::Command;
4+
use std::path::Path;
45

56
#[cfg(feature = "test")]
67
fn compile_rust(file: PathBuf) -> bool {
@@ -18,10 +19,48 @@ fn compile_rust(file: PathBuf) -> bool {
1819
}
1920

2021
fn main() {
21-
if let Some(link_path) = option_env!("BINARYNINJADIR") {
22+
23+
let binja_base_dir: &str = option_env!("DEP_BINARYNINJACORE_BASE_DIR").unwrap_or_else(|| {
24+
// If the environment variable is not set, try the default locations from
25+
// https://docs.binary.ninja/guide/#binary-path
26+
27+
#[cfg(target_os = "macos")]
28+
{
29+
let default = "/Applications/Binary Ninja.app/";
30+
if Path::new(default).exists() {
31+
return default
32+
}
33+
}
34+
35+
#[cfg(target_os = "windows")]
36+
{
37+
let default = r"C:\Program Files\Vector35\BinaryNinja";
38+
if Path::new(default).exists() {
39+
return default
40+
}
41+
// Nothing at default path, check user path
42+
if let Some(local_app_data) = std::env::var_os("LOCALAPPDATA") {
43+
let user_path = Path::new(&local_app_data).join("Vector35").join("BinaryNinja");
44+
if user_path.exists() {
45+
return user_path.to_str().unwrap()
46+
}
47+
}
48+
}
49+
50+
panic!("DEP_BINARYNINJACORE_BASE_DIR must be set to the base directory of the Binary Ninja installation");
51+
});
52+
53+
if let link_path = binja_base_dir {
2254
println!("cargo::rustc-link-lib=dylib=binaryninjacore");
2355
println!("cargo::rustc-link-search={}", link_path);
2456

57+
#[cfg(target_os = "macos")]
58+
{
59+
// On macOS the binaryninjacore dylib is in the MacOS directory
60+
println!("cargo::rustc-link-search={}/Contents/MacOS", link_path);
61+
println!("cargo::rustc-link-arg=-Wl,-rpath,{0}/Contents/MacOS,-L{0}/Contents/MacOS", link_path);
62+
}
63+
2564
#[cfg(not(target_os = "windows"))]
2665
{
2766
println!("cargo::rustc-link-arg=-Wl,-rpath,{0},-L{0}", link_path);

0 commit comments

Comments
 (0)