rvvm-sys 0.2.1

RVVM raw C bindings
use std::env;
use std::path::PathBuf;
use std::error::Error;
use std::process::Command;
use std::fs::remove_dir_all;
use std::env::temp_dir;

fn clone_and_build() -> Result<(), Box<dyn Error>> {
    let target_dir: PathBuf = temp_dir();

    Command::new("git")
           .current_dir(&target_dir)
           .arg("clone")
           .arg("https://github.com/LekKit/RVVM")
           .arg("-b")
           .arg("api-refactor")
           .status()
           .expect("Failed to clone github rvvm repository");
    Command::new("make")
           .current_dir(&target_dir.join("RVVM"))
           .arg("lib")
           .status()
           .expect("Failed to make");
    Ok(())
}

fn cleanup_build() {
    remove_dir_all(temp_dir().join("RVVM")).expect("Failed to clean up rvvm repository");
}

fn main() {
    #[cfg(feature = "embeddable")]
    { clone_and_build().expect("Failed to clone and build"); }

    // Tell cargo to invalidate the built crate whenever the wrapper changes
    println!("cargo:rerun-if-changed=rvvmlib.h");
    println!("cargo:rustc-link-search=./RVVM/");

    // The bindgen::Builder is the main entry point
    // to bindgen, and lets you build up options for
    // the resulting bindings.
    let bindings = bindgen::Builder::default()
        // The input header we would like to generate
        // bindings for.
        .header("rvvmlib.h")
        // Tell cargo to invalidate the built crate whenever any of the
        // included header files changed.
        .parse_callbacks(Box::new(bindgen::CargoCallbacks))
        // Finish the builder and generate the bindings.
        .generate()
        // Unwrap the Result and panic on failure.
        .expect("Unable to generate bindings");

    // Write the bindings to the $OUT_DIR/bindings.rs file.
    let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
    bindings
        .write_to_file(out_path.join("bindings.rs"))
        .expect("Couldn't write bindings!");
    #[cfg(feature = "embeddable")]
    { cleanup_build(); }
}