opengl_sdk/glrs/build.rs
2026-02-26 14:35:15 +01:00

42 lines
1.1 KiB
Rust

use cc;
fn collect_c_files(dir: &str) -> Vec<std::path::PathBuf> {
let mut files = vec![];
for entry in std::fs::read_dir(dir).unwrap() {
let path = entry.unwrap().path();
if path.is_dir() {
files.extend(collect_c_files(path.to_str().unwrap()));
} else if path.extension().map_or(false, |e| e == "c") {
files.push(path);
}
}
files
}
fn main() {
let cfiles = collect_c_files("../glc/src");
cc::Build::new()
.files(&cfiles)
.compile("glc"); // produces libgl_layer.a
let bindings = bindgen::Builder::default()
.header("../glc/src/glc_api.h")
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
.generate()
.unwrap();
bindings
.write_to_file(std::path::PathBuf::from(std::env::var("OUT_DIR").unwrap()).join("bindings.rs"))
.unwrap();
let bindings_header = "../glc/src/glc_api.h";
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed={bindings_header}");
cfiles.iter().for_each(|c| {
println!("cargo::rerun-if-changed={}", c.parent().unwrap().to_str().unwrap());
});
}