-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.rs
77 lines (64 loc) · 2.57 KB
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#[cfg(feature = "binja")]
use std::env;
#[cfg(feature = "binja")]
use std::fs::File;
#[cfg(feature = "binja")]
use std::io::BufReader;
#[cfg(feature = "binja")]
use std::path::PathBuf;
#[cfg(all(target_os = "macos", feature = "binja"))]
static LASTRUN_PATH: (&str, &str) =
("HOME", "Library/Application Support/Binary Ninja/lastrun");
#[cfg(all(target_os = "linux", feature = "binja"))]
static LASTRUN_PATH: (&str, &str) = ("HOME", ".binaryninja/lastrun");
#[cfg(all(windows, feature = "binja"))]
static LASTRUN_PATH: (&str, &str) = ("APPDATA", "Binary Ninja\\lastrun");
#[cfg(feature = "binja")]
// Check last run location for path to BinaryNinja; Otherwise check the default install locations
fn link_path() -> PathBuf {
use std::io::prelude::*;
let home = PathBuf::from(env::var(LASTRUN_PATH.0).unwrap());
let lastrun = PathBuf::from(&home).join(LASTRUN_PATH.1);
File::open(lastrun)
.and_then(|f| {
let mut binja_path = String::new();
let mut reader = BufReader::new(f);
reader.read_line(&mut binja_path)?;
Ok(PathBuf::from(binja_path.trim()))
})
.unwrap_or_else(|_| {
#[cfg(all(target_os = "macos", feature = "binja"))]
return PathBuf::from(
"/Applications/Binary Ninja.app/Contents/MacOS",
);
#[cfg(all(target_os = "linux", feature = "binja"))]
return home.join("binaryninja");
#[cfg(all(windows, feature = "binja"))]
return PathBuf::from(env::var("PROGRAMFILES").unwrap())
.join("Vector35\\BinaryNinja\\");
})
}
fn main() {
#[cfg(feature = "binja")]
// do nothing if not building with "binja" feature
// Use BINARYNINJADIR first for custom BN builds/configurations (BN devs/build server), fallback on defaults
let install_path =
env::var("BINARYNINJADIR").map_or_else(|_| link_path(), PathBuf::from);
#[cfg(all(target_os = "linux", feature = "binja"))]
println!(
"cargo:rustc-link-arg=-Wl,-rpath,{},-L{},-l:libbinaryninjacore.so.1",
install_path.to_str().unwrap(),
install_path.to_str().unwrap(),
);
#[cfg(all(target_os = "macos", feature = "binja"))]
println!(
"cargo:rustc-link-arg=-Wl,-rpath,{},-L{},-lbinaryninjacore",
install_path.to_str().unwrap(),
install_path.to_str().unwrap(),
);
#[cfg(all(target_os = "windows", feature = "binja"))]
{
println!("cargo:rustc-link-lib=binaryninjacore");
println!("cargo:rustc-link-search={}", install_path.to_str().unwrap());
}
}