Skip to content

Rust binding: call cmake in build script #1444

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion bindings/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,16 @@ description = "Rust bindings for the Unicorn emulator with utility functions"
build = "build.rs"
links = "unicorn"

[features]
# one of the following features must be enabled.
build = ["cmake"]
system = []

[dependencies]
bitflags = "1.0"
libc = "0.2"
capstone="0.6.0"

[build-dependencies]
build-helper = "0.1"
cmake = { version = "0.1", optional = true }
pkg-config = "0.3"
39 changes: 23 additions & 16 deletions bindings/rust/build.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
use std::{env, process::Command};
#[cfg(feature = "build")]
fn main() {
use std::env;
use std::path::PathBuf;

use build_helper::rustc::{link_lib, link_search};
let manifest_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
let unicorn_dir = manifest_dir.parent().unwrap().parent().unwrap();
println!("cargo:rerun-if-changed={}", unicorn_dir.display());

fn main() {
println!("cargo:rerun-if-changed=unicorn");
let out_dir = env::var("OUT_DIR").unwrap();
let unicorn = "libunicorn.a";
let _ = Command::new("cp")
.current_dir("../..")
.arg(&unicorn)
.arg(&out_dir)
.status()
.unwrap();
link_search(
Some(build_helper::SearchKind::Native),
build_helper::out_dir(),
let install_dir = cmake::Config::new(unicorn_dir)
.define("UNICORN_BUILD_SHARED", "OFF")
.build();
env::remove_var("PKG_CONFIG_PATH");
env::set_var(
"PKG_CONFIG_LIBDIR",
install_dir.join("lib").join("pkgconfig"),
);
link_lib(Some(build_helper::LibKind::Static), "unicorn");
pkg_config::Config::new()
.statik(true)
.probe("unicorn")
.unwrap();
}

#[cfg(feature = "system")]
fn main() {
pkg_config::probe_library("unicorn").unwrap();
}