-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.rs
67 lines (59 loc) · 1.9 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
use std::{env, path::PathBuf};
fn main() {
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap();
// clone openal-soft (if needed)
let oal_soft_dir = PathBuf::from("openal-soft");
let profile = if let Ok(opt_level) = env::var("OPT_LEVEL") {
if opt_level == "z" || opt_level == "s" {
"MinSizeRel"
} else {
"Release"
}
} else {
"Release"
};
let build_dir = cmake::Config::new(&oal_soft_dir)
.profile(profile)
.define("ALSOFT_UTILS", "OFF")
.define("ALSOFT_EXAMPLES", "OFF")
.define("ALSOFT_TESTS", "OFF")
.define("ALSOFT_INSTALL", "OFF")
.build();
println!(
"cargo:rustc-link-search={}",
build_dir.join("build").display()
);
println!(
"cargo:rustc-link-search={}",
build_dir.join("build").join("Release").display()
);
match &target_os[..] {
"windows" => {
println!("cargo:rustc-link-lib=dylib=OpenAL32");
}
_ => {
println!("cargo:rustc-link-lib=dylib=openal");
}
}
// generate bindings
bindgen::Builder::default()
.header_contents(
"main.h",
&["al.h", "alc.h", "alext.h"] // TODO: efx.h
.into_iter()
.map(|s| {
format!(
"#include \"{}\"\n",
&oal_soft_dir.join("include").join("AL").join(s).display()
)
})
.collect::<String>(),
)
.default_macro_constant_type(bindgen::MacroTypeVariation::Signed)
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
.generate()
.expect("failed to generate bindings")
.write_to_file(&out_dir.join("bindings.rs"))
.expect("failed to write bindings");
}