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

fn main() {
    let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
    let output_file = PathBuf::from(&crate_dir)
        .parent()
        .unwrap()
        .parent()
        .unwrap()
        .join("target")
        .join("entropyk.h");

    let mut config =
        cbindgen::Config::from_file("cbindgen.toml").expect("Failed to read cbindgen.toml");

    config.header = Some("/* Auto-generated by cbindgen. Do not modify. */".to_string());
    config.include_guard = Some("ENTROPYK_H".to_string());
    config.language = cbindgen::Language::C;

    cbindgen::Builder::new()
        .with_crate(&crate_dir)
        .with_config(config)
        .generate()
        .expect("Unable to generate C bindings")
        .write_to_file(&output_file);

    println!("cargo:rerun-if-changed=cbindgen.toml");
    println!("cargo:rerun-if-changed=src/lib.rs");
    println!("cargo:rerun-if-changed=src/error.rs");
    println!("cargo:rerun-if-changed=src/system.rs");
    println!("cargo:rerun-if-changed=src/components.rs");
    println!("cargo:rerun-if-changed=src/solver.rs");
}
