summaryrefslogtreecommitdiff
path: root/rust/binaryninjacore-sys/build.rs
diff options
context:
space:
mode:
authorJosh Ferrell <josh@vector35.com>2025-09-01 17:47:08 -0400
committerJosh Ferrell <josh@vector35.com>2025-09-01 17:47:08 -0400
commiteef93b932844110cf19a4b2741b528623b77998e (patch)
treeb8c89a56e603dc837d3fe48a33aa619baf2e7d4a /rust/binaryninjacore-sys/build.rs
parent42fd7435e2713181facfc6d4f54b42bdaa1d2825 (diff)
Add option to build rust api without linking to core
Diffstat (limited to 'rust/binaryninjacore-sys/build.rs')
-rw-r--r--rust/binaryninjacore-sys/build.rs25
1 files changed, 22 insertions, 3 deletions
diff --git a/rust/binaryninjacore-sys/build.rs b/rust/binaryninjacore-sys/build.rs
index 579276a6..672615da 100644
--- a/rust/binaryninjacore-sys/build.rs
+++ b/rust/binaryninjacore-sys/build.rs
@@ -41,6 +41,22 @@ fn link_path() -> PathBuf {
})
}
+// Generate and compile stub shared library and return the path to the folder containing the built stub library
+fn generate_stubs() -> PathBuf {
+ let manifest_dir = std::env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set");
+
+ let api_base_path = std::path::PathBuf::from(manifest_dir)
+ .join("../../")
+ .canonicalize()
+ .unwrap();
+
+ let stubs_path = api_base_path.join("stubs");
+ cmake::Config::new(stubs_path)
+ .generator("Ninja")
+ .build()
+ .join("build")
+}
+
fn main() {
println!("cargo:rerun-if-env-changed=BINARYNINJADIR");
println!("cargo:rerun-if-changed=../../binaryninjacore.h");
@@ -48,9 +64,12 @@ fn main() {
//Cargo's output directory
let out_dir = env::var("OUT_DIR").unwrap();
- let link_path = env::var("BINARYNINJADIR")
- .map(PathBuf::from)
- .unwrap_or_else(|_| link_path());
+ let link_path = match env::var("CARGO_FEATURE_CORE") {
+ Ok(_) => env::var("BINARYNINJADIR")
+ .map(PathBuf::from)
+ .unwrap_or_else(|_| link_path()),
+ Err(_) => generate_stubs(),
+ };
// Linux builds of binaryninja ship with libbinaryninjacore.so.1 in the
// application folder and no symlink. The linker will attempt to link with