-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.rs
44 lines (38 loc) · 1.38 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
use std::collections::HashSet;
use std::path::PathBuf;
#[derive(Debug)]
struct IgnoreMacros(HashSet<String>);
impl bindgen::callbacks::ParseCallbacks for IgnoreMacros {
fn will_parse_macro(&self, name: &str) -> bindgen::callbacks::MacroParsingBehavior {
if self.0.contains(name) {
bindgen::callbacks::MacroParsingBehavior::Ignore
} else {
bindgen::callbacks::MacroParsingBehavior::Default
}
}
}
// https://fitzgeraldnick.com/2016/12/14/using-libbindgen-in-build-rs.html
fn main() {
println!("cargo:rustc-link-lib=gvc");
println!("cargo:rustc-link-lib=cgraph");
// https://github.com/rust-lang/rust-bindgen/issues/687
let ignored_macros = IgnoreMacros(
vec![
"FP_INFINITE".into(),
"FP_NAN".into(),
"FP_NORMAL".into(),
"FP_SUBNORMAL".into(),
"FP_ZERO".into(),
]
.into_iter()
.collect(),
);
let bindings = bindgen::Builder::default()
.header("wrapper.h")
.parse_callbacks(Box::new(ignored_macros))
.formatter(bindgen::Formatter::Rustfmt)
.generate() // Finish the builder and generate the bindings.
.expect("unable to generate bindings");
let out_path = PathBuf::from(std::env::var("OUT_DIR").unwrap());
bindings.write_to_file(out_path.join("bindings.rs")).expect("cannot write bindings");
}