diff options
| author | KyleMiles <krm504@nyu.edu> | 2021-03-17 19:05:41 +0000 |
|---|---|---|
| committer | KyleMiles <krm504@nyu.edu> | 2021-03-18 13:12:21 -0400 |
| commit | ca369aced1654ffe89d473a03ff2ac1b54bf1200 (patch) | |
| tree | 4a4737221bd725ec9570c24b100d398efe66c7d4 /rust | |
| parent | 534c3bc85860d2c14a490cf68ea1174cb9edbfde (diff) | |
Build System Updates
Diffstat (limited to 'rust')
| -rw-r--r-- | rust/binaryninjacore-sys/Cargo.toml | 2 | ||||
| -rw-r--r-- | rust/binaryninjacore-sys/build.rs | 74 |
2 files changed, 62 insertions, 14 deletions
diff --git a/rust/binaryninjacore-sys/Cargo.toml b/rust/binaryninjacore-sys/Cargo.toml index 0a1e47aa..e06c2db3 100644 --- a/rust/binaryninjacore-sys/Cargo.toml +++ b/rust/binaryninjacore-sys/Cargo.toml @@ -5,7 +5,7 @@ authors = ["Ryan Snyder <ryan@vector35.com>", "Kyle Martin <kyle@vector35.com>"] build = "build.rs" [build-dependencies] -bindgen = "0.55" +bindgen = "0.57" [features] headless = [] diff --git a/rust/binaryninjacore-sys/build.rs b/rust/binaryninjacore-sys/build.rs index 126077d6..f3db915d 100644 --- a/rust/binaryninjacore-sys/build.rs +++ b/rust/binaryninjacore-sys/build.rs @@ -51,6 +51,9 @@ fn main() { // Allow the library search path to be overridden for internal dev builds, but // otherwise search the usual install paths let out_dir = env::var("OUT_DIR").unwrap(); + let llvm_dir = env::var("LIBCLANG_PATH"); + let llvm_version = env::var("LLVM_VERSION"); + let llvm_install_dir = env::var("LLVM_INSTALL_DIR"); #[cfg(any(windows, feature = "headless"))] let link_path = env::var("BINARYNINJADIR") @@ -146,19 +149,64 @@ fn main() { println!("cargo:rustc-link-search={}", link_path.to_str().unwrap()); } - let bindings = bindgen::builder() - .header("../../binaryninjacore.h") - .clang_arg("-std=c++17") - .clang_arg("-x") - .clang_arg("c++") - .size_t_is_usize(true) - .generate_comments(false) - .whitelist_function("BN.*") - .whitelist_var("BN_CURRENT_CORE_ABI_VERSION") - .whitelist_var("BN_MINIMUM_CORE_ABI_VERSION") - .rustified_enum("BN.*") - .generate() - .expect("Unable to generate bindings"); + #[warn(unused_assignments)] + let mut is_mac = false; + #[cfg(target_os = "macos")] + { + is_mac = true; + } + + // 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 bindings; + 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 = bindgen::builder() + .header("../../binaryninjacore.h") + .clang_arg("-std=c++17") + .clang_arg("-x") + .clang_arg("c++") + .clang_arg(llvm_include_path) + .size_t_is_usize(true) + .generate_comments(false) + .whitelist_function("BN.*") + .whitelist_var("BN_CURRENT_CORE_ABI_VERSION") + .whitelist_var("BN_MINIMUM_CORE_ABI_VERSION") + .rustified_enum("BN.*") + .generate() + .expect("Unable to generate bindings"); + } else if let (false, Ok(llvm_install_dir)) = (is_mac, llvm_install_dir) { + let llvm_include_path = format!("-I{}/11.0.0/lib/clang/11.0.0/include", llvm_install_dir); + env::set_var("LIBCLANG_PATH", format!("{}/11.0.0/lib", llvm_install_dir)); + bindings = bindgen::builder() + .header("../../binaryninjacore.h") + .clang_arg("-std=c++17") + .clang_arg("-x") + .clang_arg("c++") + .clang_arg(llvm_include_path) + .size_t_is_usize(true) + .generate_comments(false) + .whitelist_function("BN.*") + .whitelist_var("BN_CURRENT_CORE_ABI_VERSION") + .whitelist_var("BN_MINIMUM_CORE_ABI_VERSION") + .rustified_enum("BN.*") + .generate() + .expect("Unable to generate bindings"); + } else { + bindings = bindgen::builder() + .header("../../binaryninjacore.h") + .clang_arg("-std=c++17") + .clang_arg("-x") + .clang_arg("c++") + .size_t_is_usize(true) + .generate_comments(false) + .whitelist_function("BN.*") + .whitelist_var("BN_CURRENT_CORE_ABI_VERSION") + .whitelist_var("BN_MINIMUM_CORE_ABI_VERSION") + .rustified_enum("BN.*") + .generate() + .expect("Unable to generate bindings"); + } bindings .write_to_file(PathBuf::from(out_dir).join("bindings.rs")) |
