Skip to content

Commit 5239ad6

Browse files
committed
WARP: Attempt auto linking to core
This was missing as apparently some of this was written against the `rust_break_everything` branch.
1 parent 53b587d commit 5239ad6

File tree

1 file changed

+49
-8
lines changed

1 file changed

+49
-8
lines changed

plugins/warp/build.rs

+49-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,46 @@
11
#![allow(unused_imports)]
2+
use std::env;
23
use std::path::PathBuf;
34
use std::process::Command;
45

6+
#[cfg(target_os = "macos")]
7+
static LASTRUN_PATH: (&str, &str) = ("HOME", "Library/Application Support/Binary Ninja/lastrun");
8+
9+
#[cfg(target_os = "linux")]
10+
static LASTRUN_PATH: (&str, &str) = ("HOME", ".binaryninja/lastrun");
11+
12+
#[cfg(windows)]
13+
static LASTRUN_PATH: (&str, &str) = ("APPDATA", "Binary Ninja\\lastrun");
14+
15+
// Check last run location for path to BinaryNinja; Otherwise check the default install locations
16+
fn link_path() -> PathBuf {
17+
use std::io::prelude::*;
18+
use std::io::BufReader;
19+
20+
let home = PathBuf::from(env::var(LASTRUN_PATH.0).unwrap());
21+
let lastrun = PathBuf::from(&home).join(LASTRUN_PATH.1);
22+
23+
std::fs::File::open(lastrun)
24+
.and_then(|f| {
25+
let mut binja_path = String::new();
26+
let mut reader = BufReader::new(f);
27+
28+
reader.read_line(&mut binja_path)?;
29+
Ok(PathBuf::from(binja_path.trim()))
30+
})
31+
.unwrap_or_else(|_| {
32+
#[cfg(target_os = "macos")]
33+
return PathBuf::from("/Applications/Binary Ninja.app/Contents/MacOS");
34+
35+
#[cfg(target_os = "linux")]
36+
return home.join("binaryninja");
37+
38+
#[cfg(windows)]
39+
return PathBuf::from(env::var("PROGRAMFILES").unwrap())
40+
.join("Vector35\\BinaryNinja\\");
41+
})
42+
}
43+
544
#[cfg(feature = "test")]
645
fn compile_rust(file: PathBuf) -> bool {
746
let out_dir = std::env::var_os("OUT_DIR").unwrap();
@@ -18,14 +57,16 @@ fn compile_rust(file: PathBuf) -> bool {
1857
}
1958

2059
fn main() {
21-
if let Some(link_path) = option_env!("BINARYNINJADIR") {
22-
println!("cargo::rustc-link-lib=dylib=binaryninjacore");
23-
println!("cargo::rustc-link-search={}", link_path);
24-
25-
#[cfg(not(target_os = "windows"))]
26-
{
27-
println!("cargo::rustc-link-arg=-Wl,-rpath,{0},-L{0}", link_path);
28-
}
60+
// Use BINARYNINJADIR first for custom BN builds/configurations (BN devs/build server), fallback on defaults
61+
let link_path = env::var("BINARYNINJADIR")
62+
.map(PathBuf::from)
63+
.unwrap_or_else(|_| link_path());
64+
let link_path_str = link_path.to_str().unwrap();
65+
println!("cargo::rustc-link-lib=dylib=binaryninjacore");
66+
println!("cargo::rustc-link-search={}", link_path_str);
67+
#[cfg(not(target_os = "windows"))]
68+
{
69+
println!("cargo::rustc-link-arg=-Wl,-rpath,{0},-L{0}", link_path_str);
2970
}
3071

3172
#[cfg(feature = "test")]

0 commit comments

Comments
 (0)