-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
70 lines (62 loc) · 2.04 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
use std::{env, path::PathBuf};
#[cfg(feature = "theta")]
fn build_theta() {
let dst = cmake::Config::new("libuvc-theta")
.define("CMAKE_BUILD_TARGET", "Static")
.define("BUILD_EXAMPLE", "OFF")
.define("CMAKE_BUILD_TYPE", "Release")
.build();
println!(
"cargo:rustc-link-search=native={}",
dst.join("lib").display()
);
println!("cargo:rustc-link-lib=static=uvc");
println!("cargo:rustc-link-lib=usb-1.0");
let bindings = bindgen::Builder::default()
.header(
dst.join("include/libuvc/libuvc.h")
.into_os_string()
.into_string()
.unwrap(),
)
.clang_arg(format!(
"-I{}",
dst.join("include").into_os_string().into_string().unwrap()
))
.default_enum_style(bindgen::EnumVariation::Rust {
non_exhaustive: true,
})
.derive_default(true)
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
.generate()
.expect("Unable to generate bindings");
// Write the bindings to the $OUT_DIR/bindings.rs file.
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings
.write_to_file(out_path.join("theta.rs"))
.expect("Couldn't write bindings!");
}
#[cfg(feature = "k4a")]
fn build_k4a() {
println!("cargo:rustc-link-lib=dylib=k4a");
let bindings = bindgen::Builder::default()
.header("k4a_wrapper.h")
.default_enum_style(bindgen::EnumVariation::Rust {
non_exhaustive: true,
})
.derive_default(true)
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
.generate()
.expect("Unable to generate bindings");
// Write the bindings to the $OUT_DIR/bindings.rs file.
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings
.write_to_file(out_path.join("k4a.rs"))
.expect("Couldn't write bindings!");
}
fn main() {
#[cfg(feature = "theta")]
build_theta();
#[cfg(feature = "k4a")]
build_k4a();
}