Skip to content

Commit 633d786

Browse files
committed
Add option to build rust api without linking to core
1 parent 1b2f5c4 commit 633d786

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

rust/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ no_exports = []
1212
# Add this if you want to support the demo version of the product.
1313
# This will disable certain functions that do not exist in the demo build.
1414
demo = ["no_exports"]
15+
# Add this to build without linking to binaryninjacore.
16+
# This option is only for shared libraries that will later be loaded in the same process as binaryninjacore.
17+
no_core = []
1518

1619
[dependencies]
1720
log = { version = "0.4", features = ["std"] }

rust/build.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
use std::path::PathBuf;
22

33
fn main() {
4-
let link_path =
5-
std::env::var_os("DEP_BINARYNINJACORE_PATH").expect("DEP_BINARYNINJACORE_PATH specified");
4+
if std::env::var("CARGO_FEATURE_NO_CORE").is_err() {
5+
let link_path = std::env::var_os("DEP_BINARYNINJACORE_PATH")
6+
.expect("DEP_BINARYNINJACORE_PATH not specified");
67

7-
println!("cargo::rustc-link-lib=dylib=binaryninjacore");
8-
println!("cargo::rustc-link-search={}", link_path.to_str().unwrap());
8+
println!("cargo::rustc-link-lib=dylib=binaryninjacore");
9+
println!("cargo::rustc-link-search={}", link_path.to_str().unwrap());
910

10-
#[cfg(not(target_os = "windows"))]
11-
{
12-
println!(
13-
"cargo::rustc-link-arg=-Wl,-rpath,{0},-L{0}",
14-
link_path.to_string_lossy()
15-
);
11+
#[cfg(not(target_os = "windows"))]
12+
{
13+
println!(
14+
"cargo::rustc-link-arg=-Wl,-rpath,{0},-L{0}",
15+
link_path.to_string_lossy()
16+
);
17+
}
1618
}
1719

18-
let out_dir = std::env::var("OUT_DIR").expect("OUT_DIR specified");
20+
let out_dir = std::env::var("OUT_DIR").expect("OUT_DIR not specified");
1921
let out_dir_path = PathBuf::from(out_dir);
2022

2123
// Copy all binaries to OUT_DIR for unit tests.

0 commit comments

Comments
 (0)