forked from deepgram/dgmrcp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
57 lines (50 loc) · 1.71 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
use std::env;
use std::path::PathBuf;
/// Where our native code is stored.
fn native() -> PathBuf {
// TODO: I think this should come from a cargo env var.
let mut absolute = env::current_dir().unwrap();
absolute.push("native");
absolute
}
/// Where our generated code is stored.
fn output() -> PathBuf {
PathBuf::from(env::var("OUT_DIR").unwrap())
}
fn main() {
println!("cargo:rerun-if-changed=native/dgmrcp.h");
println!("cargo:rerun-if-env-changed=MRCP_INCLUDE_PATH");
let mut includes = env::var("MRCP_INCLUDE_PATH")
.map(|x| {
x.split(':')
.filter(|x| !x.is_empty())
.map(|x| x.to_string())
.collect::<Vec<_>>()
})
.unwrap_or_else(|_| {
["/usr/local/unimrcp/include", "/usr/local/apr/include/apr-1"]
.iter()
.map(|&x| x.to_string())
.collect::<Vec<_>>()
});
includes.push(native().to_string_lossy().to_string());
let mut builder = bindgen::Builder::default();
builder = builder
.clang_args(
&includes
.into_iter()
.map(|x| format!("-I{}", x))
.collect::<Vec<_>>(),
)
.header(native().join("dgmrcp.h").to_string_lossy())
.constified_enum_module("*")
.prepend_enum_name(false)
// The autogenerated type is u32, but we want it to be
// apt_bool_t, so we'll manually define this.
.blacklist_item("FALSE")
.derive_eq(true);
let bindings = builder.generate().expect("Unable to generate bindings.");
bindings
.write_to_file(output().join("bindings.rs"))
.expect("Unable to write bindings.");
}