-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild.rs
More file actions
41 lines (33 loc) · 1.1 KB
/
build.rs
File metadata and controls
41 lines (33 loc) · 1.1 KB
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
use glob::glob;
use std::{env, path::PathBuf};
fn main() {
build_lerc();
generate_bindings("vendor/lerc/src/LercLib/include");
}
fn build_lerc() {
let base = "vendor/lerc/src/LercLib";
let mut build = cc::Build::new();
build
.cpp(true)
.std("c++17")
.include(format!("{base}/include"))
.include(base);
for entry in glob(&format!("{base}/**/*.cpp")).expect("Failed to read glob pattern") {
let path = entry.expect("Invalid .cpp path");
build.file(path);
}
build.compile("lerc");
println!("cargo:rerun-if-changed={base}");
}
fn generate_bindings(include_path: &str) {
let bindings = bindgen::Builder::default()
.header(format!("{}/Lerc_c_api.h", include_path))
.clang_arg(format!("-I{}", include_path))
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
.generate()
.expect("Unable to generate bindings");
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");
}