Newer
Older
Tasuku SUENAGA a.k.a. gunyarakun
committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#[cfg(feature = "use_system_keystone")]
extern crate pkg_config;
use std::env;
use std::path::PathBuf;
use std::process::Command;
fn build_with_cmake() {
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
let cmake_dir = PathBuf::from("keystone");
let build_dir = cmake_dir.join("build");
if !cmake_dir.exists() {
run(Command::new("ln").arg("-s").arg("../../..").arg("keystone"));
}
run(Command::new("mkdir")
.current_dir(&cmake_dir)
.arg("-p")
.arg("build"));
run(Command::new("../make-share.sh").current_dir(&build_dir));
run(Command::new("cmake").current_dir(&build_dir).args(&[
&format!("-DCMAKE_INSTALL_PREFIX={}", out_dir.display()),
"-DCMAKE_BUILD_TYPE=Release",
"-DBUILD_LIBS_ONLY=1",
"-DCMAKE_OSX_ARCHITECTURES=",
"-DBUILD_SHARED_LIBS=ON",
"-DLLVM_TARGET_ARCH=host",
"-G",
"Unix Makefiles",
"..",
]));
run(Command::new("make").current_dir(&build_dir).arg("install"));
println!("cargo:rustc-link-search=native={}/lib", out_dir.display());
println!("cargo:rustc-link-lib=keystone");
}
fn main() {
if cfg!(feature = "use_system_keystone") {
#[cfg(feature = "use_system_keystone")]
pkg_config::find_library("keystone").expect("Could not find system keystone");
} else {
build_with_cmake();
}
}
fn run(cmd: &mut Command) {
println!("run: {:?}", cmd);
let status = match cmd.status() {
Ok(s) => s,
Err(ref e) => fail(&format!("failed to execute command: {}", e)),
};
if !status.success() {
fail(&format!(
"command did not execute successfully, got: {}",
status
));
}
}
fn fail(s: &str) -> ! {
panic!("\n{}\n\nbuild script failed, must exit now", s);
}