use std::env;
use std::path::PathBuf;

fn main() {
    let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
    let pxl8_src = PathBuf::from(&manifest_dir).join("../src");

    println!("cargo:rerun-if-changed=../src/net/pxl8_protocol.h");
    println!("cargo:rerun-if-changed=../src/core/pxl8_types.h");

    let bindings = bindgen::Builder::default()
        .header(pxl8_src.join("net/pxl8_protocol.h").to_str().unwrap())
        .clang_arg(format!("-I{}", pxl8_src.join("core").display()))
        .use_core()
        .rustified_enum(".*")
        .generate()
        .expect("Unable to generate bindings");

    let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
    bindings
        .write_to_file(out_path.join("protocol.rs"))
        .expect("Couldn't write bindings");
}
