-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.rs
98 lines (83 loc) · 2.75 KB
/
build.rs
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
extern crate bindgen;
extern crate cc;
extern crate num_cpus;
use std::env;
use std::path::PathBuf;
fn main() {
println!("cargo:rerun-if-changed=src/bindgen.h");
#[cfg(feature = "dynamorio")]
{
use std::fs;
use std::process::Command;
println!("cargo:rerun-if-changed=dynamorio/");
let mut out_dir_64 = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
let mut out_dir_32 = out_dir_64.clone();
out_dir_64.push("build_64");
out_dir_64.push("dynamorio");
out_dir_32.push("build_32");
out_dir_32.push("dynamorio");
fs::create_dir_all(&out_dir_64).expect("Failed to make build_64 dir");
fs::create_dir_all(&out_dir_32).expect("Failed to make build_32 dir");
let cpus = num_cpus::get();
let run_cmake = |cmd: &mut Command| {
if !cmd
.spawn()
.expect("Failed to spawn cmake")
.wait()
.expect("Failed to run cmake")
.success()
{
panic!("cmake failed!");
}
};
let run_make = |dir| {
if !Command::new("make")
.args(&["-j", &format!("{}", cpus)])
.current_dir(dir)
.spawn()
.expect("Failed to spawn make")
.wait()
.expect("Failed to run make")
.success()
{
panic!("make failed!");
}
};
run_cmake(
Command::new("cmake")
.args(&[
"../../dynamorio",
"-DDISABLE_WARNINGS=yes",
"-DBUILD_DOCS=no",
])
.current_dir(&out_dir_64),
);
run_make(&out_dir_64);
run_cmake(
Command::new("cmake")
.args(&[
"../../dynamorio",
"-DDISABLE_WARNINGS=yes",
"-DCMAKE_DISABLE_FIND_PACKAGE_Qt5Widgets=TRUE",
"-DBUILD_DOCS=no",
])
.env("CXXFLAGS", "-m32")
.env("CFLAGS", "-m32")
.current_dir(&out_dir_32),
);
run_make(&out_dir_32);
}
// Generate Rust bindings
let bindings = bindgen::Builder::default()
.header("src/bindgen.h")
.whitelist_type("perf_event_attr")
.whitelist_type("perf_type_id")
.whitelist_type("perf_hw_id")
.generate()
.expect("Unable to generate bindings");
// Output rust bindings to a file
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");
}