/
build.rs
51 lines (41 loc) · 1.47 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
extern crate bindgen;
use std::env;
use std::path::PathBuf;
use std::process::Command;
use vcpkg::Library;
const HARFBUZZ_PACKAGE_NAME: &'static str = "harfbuzz";
fn main() {
Command::new("cargo")
.args(&["install", "cargo-vcpkg"])
.status()
.expect("Failed to install cargo-vcpkg");
Command::new("cargo")
.args(&["vcpkg", "build"])
.status()
.expect("Failed to build vcpkg and dependencies, please run `cargo clean` and try again");
println!("cargo:rerun-if-changed=wrapper.h");
let harfbuzz_package = vcpkg::Config::new()
.emit_includes(true)
.find_package(HARFBUZZ_PACKAGE_NAME);
match harfbuzz_package {
Ok(lib) => generate_bindings(&lib),
Err(e) => panic!("{}", e)
};
}
fn generate_bindings(lib: &Library) {
let mut bindings = bindgen::Builder::default()
.header("wrapper.h")
.prepend_enum_name(false)
.parse_callbacks(Box::new(bindgen::CargoCallbacks)); // Tell cargo to invalidate the built crate whenever any of the included header files changed.
for include_path in &lib.include_paths {
bindings = bindings
.clang_arg("-I")
.clang_arg(include_path.display().to_string());
}
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings
.generate()
.expect("Unable to generate bindings")
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");
}