From 85a26f2928ea3bccbd86cc0c0c9ba74ac542ca32 Mon Sep 17 00:00:00 2001 From: Mason Reed Date: Wed, 10 Jul 2024 17:59:21 -0400 Subject: [PATCH] Link against core # Conflicts: # rust/build.rs --- rust/binaryninjacore-sys/Cargo.toml | 2 ++ rust/binaryninjacore-sys/build.rs | 3 +-- rust/build.rs | 25 +++++++++++++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/rust/binaryninjacore-sys/Cargo.toml b/rust/binaryninjacore-sys/Cargo.toml index 6faafaa6d4..9ae249453f 100644 --- a/rust/binaryninjacore-sys/Cargo.toml +++ b/rust/binaryninjacore-sys/Cargo.toml @@ -3,6 +3,8 @@ name = "binaryninjacore-sys" version = "0.1.0" authors = ["Ryan Snyder ", "Kyle Martin "] build = "build.rs" +edition = "2021" +links = "binaryninjacore" [build-dependencies] bindgen = "^0.69.2" diff --git a/rust/binaryninjacore-sys/build.rs b/rust/binaryninjacore-sys/build.rs index 00abcfd3ca..ba9c2f3b2f 100644 --- a/rust/binaryninjacore-sys/build.rs +++ b/rust/binaryninjacore-sys/build.rs @@ -72,8 +72,7 @@ fn main() { println!("cargo:rustc-link-search={}", out_dir); } - println!("cargo:rustc-link-lib=binaryninjacore"); - println!("cargo:rustc-link-search={}", link_path.to_str().unwrap()); + println!("cargo:path={}", link_path.to_str().unwrap()); let current_line = "#define BN_CURRENT_UI_ABI_VERSION "; let minimum_line = "#define BN_MINIMUM_UI_ABI_VERSION "; diff --git a/rust/build.rs b/rust/build.rs index 91f1021f12..559b2e2808 100644 --- a/rust/build.rs +++ b/rust/build.rs @@ -1,3 +1,5 @@ +use std::env; + fn main() { // TODO : Enable the following when https://github.com/rust-lang/rust/issues/43781 stabilizes // #[cfg(doc)] @@ -9,4 +11,27 @@ fn main() { "target/doc/under_construction.png", ); let _ = std::fs::copy("../docs/img/logo.png", "target/doc/logo.png"); + + let Some(link_path) = env::var_os("DEP_BINARYNINJACORE_PATH") else { + // TODO: This needs to be moved into the sys crate? + panic!("no DEP_BINARYNINJA_PATH specified!"); + }; + + println!("cargo::rustc-link-lib=dylib=binaryninjacore"); + + #[cfg(not(target_os = "windows"))] + { + println!( + "cargo::rustc-link-arg=-Wl,-rpath,{0},-L{0}", + link_path.to_string_lossy() + ); + } + + #[cfg(target_os = "windows")] + { + println!( + "cargo::rustc-link-search={}", + link_path.to_string_lossy() + ); + } }