extern crate bindgen;
use std::env::{self};
use std::path::PathBuf;
use bindgen::CargoCallbacks;
fn main() {
let root_dir = PathBuf::from(
&std::env::var("CARGO_MANIFEST_DIR").expect("Should have CARGO_MANIFEST_DIR"),
);
let quickjs_dir = root_dir.join("quickjs");
println!("cargo:rustc-link-lib=libregexp");
[
quickjs_dir.join("libregexp.c"),
quickjs_dir.join("libunicode.c"),
quickjs_dir.join("cutils.c"),
root_dir.join("shims.c"),
root_dir.join("build.rs"),
]
.into_iter()
.for_each(|p| {
assert!(p.exists(), "File does not exist: {}", p.to_str().unwrap());
println!("cargo:rerun-if-changed={}", p.to_str().unwrap());
});
cc::Build::new()
.file(quickjs_dir.join("libregexp.c"))
.file(quickjs_dir.join("libunicode.c"))
.file(quickjs_dir.join("cutils.c"))
.file(root_dir.join("shims.c"))
.warnings(false)
.compile("libregexp");
let bindings = bindgen::Builder::default()
.header(
quickjs_dir
.join("libregexp.h")
.to_str()
.unwrap()
.to_string(),
)
.header(
quickjs_dir
.join("libunicode.h")
.to_str()
.unwrap()
.to_string(),
)
.header(quickjs_dir.join("cutils.h").to_str().unwrap().to_string())
.parse_callbacks(Box::new(CargoCallbacks))
.generate()
.expect("Unable to generate bindings");
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()).join("bindings.rs");
bindings
.write_to_file(out_path)
.expect("Couldn't write bindings!");
}