use std::env;
use std::path::PathBuf;
use std::error::Error;
use std::env::temp_dir;
use std::process::Command;
fn clone_and_build() -> Result<(), Box<dyn Error>> {
let target_dir: PathBuf = "./".into();
Command::new("make")
.current_dir(&target_dir.join("RVVM"))
.env("BUILDDIR", &temp_dir())
.arg("lib")
.status()
.expect("Failed to make");
Ok(())
}
fn cleanup_build() {
}
fn main() {
let lib = temp_dir().as_os_str().to_str().unwrap().to_string();
clone_and_build().expect("Failed to clone and build");
println!("cargo:rerun-if-changed=RVVM/src/rvvmlib.h");
println!("cargo:rustc-link-search=native={}", lib);
println!("cargo:rustc-link-lib=dylib=rvvm",);
let bindings = bindgen::Builder::default()
.header("./RVVM/src/rvvmlib.h")
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
.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!");
cleanup_build();
}