-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.rs
51 lines (48 loc) · 1.97 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
fn main() {
#[cfg(feature = "bindgen")]
{
use std::env;
use std::path::PathBuf;
use bindgen::callbacks::ParseCallbacks;
#[derive(Debug)]
struct Parse;
impl ParseCallbacks for Parse {
fn int_macro(&self, name: &str, _value: i64) -> Option<bindgen::callbacks::IntKind> {
if name.starts_with("USBDEVFS_URB_TYPE_") {
Some(bindgen::callbacks::IntKind::U8)
} else {
None
}
}
fn item_name(&self, original_item_name: &str) -> Option<String> {
// TODO: maybe leave names unchanged to help online searches for these terms
for prefix in &["USBDEVFS_", "usbdevfs_"] {
if original_item_name.starts_with(prefix) {
return Some(original_item_name[prefix.len()..].to_string());
}
}
None
}
}
// The bindgen::Builder is the main entry point
// to bindgen, and lets you build up options for
// the resulting bindings.
let bindings = bindgen::Builder::default()
// TODO: actually might be simpler to copy the headers into this repo,
.header("/usr/include/linux/usbdevice_fs.h")
.generate_comments(true)
.whitelist_type("^usbdevfs.*")
.whitelist_function("^usbdevfs.*")
.whitelist_var("^USBDEVFS.*")
.parse_callbacks(Box::new(Parse))
// Finish the builder and generate the bindings.
.generate()
// Unwrap the Result and panic on failure.
.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("bindings.rs"))
.expect("Couldn't write bindings!");
}
}