summaryrefslogtreecommitdiff
path: root/rust/binaryninjacore-sys
diff options
context:
space:
mode:
authorKyleMiles <krm504@nyu.edu>2021-06-28 22:13:43 -0400
committerKyleMiles <krm504@nyu.edu>2021-06-29 00:26:33 -0400
commit2c344cf7a77031021e346fd8649de2b7715b5c45 (patch)
treefc9b48db5748231aed4e05128d38ab649717a102 /rust/binaryninjacore-sys
parent58e515b3bfa3a96e4934b8a625bb6e51399057ec (diff)
Resolves #2521; Rust API Linking Errors
Diffstat (limited to 'rust/binaryninjacore-sys')
-rw-r--r--rust/binaryninjacore-sys/build.rs102
1 files changed, 19 insertions, 83 deletions
diff --git a/rust/binaryninjacore-sys/build.rs b/rust/binaryninjacore-sys/build.rs
index 38a656e6..38f8d208 100644
--- a/rust/binaryninjacore-sys/build.rs
+++ b/rust/binaryninjacore-sys/build.rs
@@ -6,86 +6,12 @@ use std::io::BufRead;
use std::io::BufReader;
use std::path::PathBuf;
-#[cfg(target_os = "macos")]
-static LASTRUN_PATH: (&str, &str) = ("HOME", "Library/Application Support/Binary Ninja/lastrun");
-
-#[cfg(target_os = "linux")]
-static LASTRUN_PATH: (&str, &str) = ("HOME", ".binaryninja/lastrun");
-
-#[cfg(windows)]
-static LASTRUN_PATH: (&str, &str) = ("APPDATA", "Binary Ninja\\lastrun");
-
-// 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(target_os = "macos")]
- return PathBuf::from("/Applications/Binary Ninja.app/Contents/MacOS");
-
- #[cfg(target_os = "linux")]
- return home.join("binaryninja");
-
- #[cfg(windows)]
- return PathBuf::from(env::var("PROGRAMFILES").unwrap())
- .join("Vector35\\BinaryNinja\\");
- })
-}
-
fn main() {
println!("cargo:rerun-if-changed=../../binaryninjacore.h");
//Cargo's output directory
let out_dir = env::var("OUT_DIR").unwrap();
- // Detect for custom Clang or LLVM installations (BN devs/build server)
- let llvm_dir = env::var("LIBCLANG_PATH");
- let llvm_version = env::var("LLVM_VERSION");
- let llvm_install_dir = env::var("LLVM_INSTALL_DIR");
-
- // Use BINARYNINJADIR first for custom BN builds/configurations (BN devs/build server), fallback on defaults
- let install_path = env::var("BINARYNINJADIR")
- .map(PathBuf::from)
- .unwrap_or_else(|_| link_path());
-
- #[cfg(target_os = "linux")]
- println!(
- "cargo:rustc-link-arg=-Wl,-rpath,{},-L{},-l:libbinaryninjacore.so.1",
- install_path.to_str().unwrap(),
- install_path.to_str().unwrap(),
- );
-
- #[cfg(not(target_os = "linux"))]
- println!(
- "cargo:rustc-link-arg=-Wl,-rpath,{},-L{},-lbinaryninjacore",
- install_path.to_str().unwrap(),
- install_path.to_str().unwrap(),
- );
-
- // TODO : Clean this up even more
- #[warn(unused_assignments)]
- let is_mac = {
- #[cfg(target_os = "macos")]
- {
- true
- }
- #[cfg(not(target_os = "macos"))]
- {
- false
- }
- };
-
let current_line = "#define BN_CURRENT_UI_ABI_VERSION ";
let minimum_line = "#define BN_MINIMUM_UI_ABI_VERSION ";
let mut current_version = "0".to_string();
@@ -100,8 +26,6 @@ fn main() {
}
}
- // Difference between global LLVM/Clang install and custom LLVM/Clang install...
- // First option is for the build server, second option is being nice to our dev who have `LLVM_INSTALL_DIR` set, third is for people with "normal" setups (and Macs)
let mut bindings = bindgen::builder()
.header("../../binaryninjacore.h")
.clang_arg("-std=c++17")
@@ -121,13 +45,25 @@ fn main() {
minimum_version
))
.rustified_enum("BN.*");
- if let (false, Ok(llvm_dir), Ok(llvm_version)) = (is_mac, llvm_dir, llvm_version) {
- let llvm_include_path = format!("-I{}/clang/{}/include", llvm_dir, llvm_version);
- bindings = bindings.clang_arg(llvm_include_path);
- } else if let (false, Ok(llvm_install_dir)) = (is_mac, llvm_install_dir) {
- let llvm_include_path = format!("-I{}/12.0.0/lib/clang/12.0.0/include", llvm_install_dir);
- env::set_var("LIBCLANG_PATH", format!("{}/12.0.0/lib", llvm_install_dir));
- bindings = bindings.clang_arg(llvm_include_path);
+
+ // Difference between global LLVM/Clang install and custom LLVM/Clang install...
+ // First option is for the build server, second option is being nice to our dev who have `LLVM_INSTALL_DIR` set, default is for people with "normal" setups (and Macs)
+ #[cfg(not(target_os = "macos"))]
+ {
+ // Detect for custom Clang or LLVM installations (BN devs/build server)
+ let llvm_dir = env::var("LIBCLANG_PATH");
+ let llvm_version = env::var("LLVM_VERSION");
+ let llvm_install_dir = env::var("LLVM_INSTALL_DIR");
+
+ if let (Ok(llvm_dir), Ok(llvm_version)) = (llvm_dir, llvm_version) {
+ let llvm_include_path = format!("-I{}/clang/{}/include", llvm_dir, llvm_version);
+ bindings = bindings.clang_arg(llvm_include_path);
+ } else if let Ok(llvm_install_dir) = llvm_install_dir {
+ let llvm_include_path =
+ format!("-I{}/12.0.0/lib/clang/12.0.0/include", llvm_install_dir);
+ env::set_var("LIBCLANG_PATH", format!("{}/12.0.0/lib", llvm_install_dir));
+ bindings = bindings.clang_arg(llvm_include_path);
+ }
}
bindings