|
1 |
| -use std::env; |
2 |
| -use std::fs::File; |
3 |
| -use std::io::BufReader; |
4 |
| -use std::path::PathBuf; |
5 |
| - |
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 |
| - |
19 |
| - let home = PathBuf::from(env::var(LASTRUN_PATH.0).unwrap()); |
20 |
| - let lastrun = PathBuf::from(&home).join(LASTRUN_PATH.1); |
21 |
| - |
22 |
| - File::open(lastrun) |
23 |
| - .and_then(|f| { |
24 |
| - let mut binja_path = String::new(); |
25 |
| - let mut reader = BufReader::new(f); |
26 |
| - |
27 |
| - reader.read_line(&mut binja_path)?; |
28 |
| - Ok(PathBuf::from(binja_path.trim())) |
29 |
| - }) |
30 |
| - .unwrap_or_else(|_| { |
31 |
| - #[cfg(target_os = "macos")] |
32 |
| - return PathBuf::from("/Applications/Binary Ninja.app/Contents/MacOS"); |
33 |
| - |
34 |
| - #[cfg(target_os = "linux")] |
35 |
| - return home.join("binaryninja"); |
36 |
| - |
37 |
| - #[cfg(windows)] |
38 |
| - return PathBuf::from(env::var("PROGRAMFILES").unwrap()) |
39 |
| - .join("Vector35\\BinaryNinja\\"); |
40 |
| - }) |
41 |
| -} |
42 |
| - |
43 | 1 | fn main() {
|
44 |
| - // Use BINARYNINJADIR first for custom BN builds/configurations (BN devs/build server), fallback on defaults |
45 |
| - let install_path = env::var("BINARYNINJADIR") |
46 |
| - .map(PathBuf::from) |
47 |
| - .unwrap_or_else(|_| link_path()); |
48 |
| - |
49 |
| - #[cfg(target_os = "linux")] |
50 |
| - println!( |
51 |
| - "cargo:rustc-link-arg=-Wl,-rpath,{},-L{},-l:libbinaryninjacore.so.1", |
52 |
| - install_path.to_str().unwrap(), |
53 |
| - install_path.to_str().unwrap(), |
54 |
| - ); |
55 |
| - |
56 |
| - #[cfg(target_os = "macos")] |
57 |
| - println!( |
58 |
| - "cargo:rustc-link-arg=-Wl,-rpath,{},-L{},-lbinaryninjacore", |
59 |
| - install_path.to_str().unwrap(), |
60 |
| - install_path.to_str().unwrap(), |
61 |
| - ); |
62 |
| - |
63 |
| - #[cfg(target_os = "windows")] |
| 2 | + let link_path = |
| 3 | + std::env::var_os("DEP_BINARYNINJACORE_PATH").expect("DEP_BINARYNINJACORE_PATH specified"); |
| 4 | + |
| 5 | + println!("cargo::rustc-link-lib=dylib=binaryninjacore"); |
| 6 | + println!("cargo::rustc-link-search={}", link_path.to_str().unwrap()); |
| 7 | + |
| 8 | + #[cfg(not(target_os = "windows"))] |
64 | 9 | {
|
65 |
| - println!("cargo:rustc-link-lib=binaryninjacore"); |
66 |
| - println!("cargo:rustc-link-search={}", install_path.to_str().unwrap()); |
| 10 | + println!( |
| 11 | + "cargo::rustc-link-arg=-Wl,-rpath,{0},-L{0}", |
| 12 | + link_path.to_string_lossy() |
| 13 | + ); |
67 | 14 | }
|
68 | 15 | }
|
0 commit comments