-
Notifications
You must be signed in to change notification settings - Fork 11
/
build.rs
56 lines (48 loc) · 1.95 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
extern crate pkg_config;
#[cfg(feature = "use-bindgen")]
extern crate bindgen;
fn main() {
match pkg_config::Config::new().statik(false).probe("alsa") {
Err(pkg_config::Error::Failure { command, output }) => panic!(
"Pkg-config failed - usually this is because alsa development headers are not installed.\n\n\
For Fedora users:\n# dnf install alsa-lib-devel\n\n\
For Debian/Ubuntu users:\n# apt-get install libasound2-dev\n\n\
pkg_config details:\n{}\n", pkg_config::Error::Failure { command, output }),
Err(e) => panic!("{}", e),
Ok(_alsa_library) => {
#[cfg(feature = "use-bindgen")]
generate_bindings(&_alsa_library);
}
};
}
#[cfg(feature = "use-bindgen")]
fn generate_bindings(alsa_library: &pkg_config::Library) {
use std::env;
use std::path::PathBuf;
let clang_include_args = alsa_library.include_paths.iter().map(|include_path| {
format!(
"-I{}",
include_path.to_str().expect("include path was not UTF-8")
)
});
let mut codegen_config = bindgen::CodegenConfig::empty();
codegen_config.insert(bindgen::CodegenConfig::FUNCTIONS);
codegen_config.insert(bindgen::CodegenConfig::TYPES);
let builder = bindgen::Builder::default()
.size_t_is_usize(true)
.whitelist_recursively(false)
.prepend_enum_name(false)
.layout_tests(false)
.whitelist_function("snd_.*")
.whitelist_type("_?snd_.*")
.whitelist_type(".*va_list.*")
.with_codegen_config(codegen_config)
.clang_args(clang_include_args)
.header("wrapper.h")
.parse_callbacks(Box::new(bindgen::CargoCallbacks));
let bindings = builder.generate().expect("Unable to generate bindings");
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings
.write_to_file(out_path.join("generated.rs"))
.expect("Couldn't write bindings");
}