use std::env;
use std::fs;
use std::path::PathBuf;
use cbindgen::{Config};
fn main() {
println!("cargo:rustc-link-search=native=C:\\Program Files\\PostgreSQL\\17\\lib");
println!("cargo:rustc-link-lib=static=pq");
let out_dir = if cfg!(debug_assertions) {
PathBuf::from(env::var("CARGO_TARGET_DIR").unwrap_or_else(|_| "target".into())).join("debug")
} else {
PathBuf::from(env::var("CARGO_TARGET_DIR").unwrap_or_else(|_| "target".into())).join("release")
};
println!("The OUT_DIR is: {}", out_dir.display());
let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("Could not find Cargo manifest directory");
let config = match Config::from_file("cbindgen.toml") {
Ok(cfg) => cfg,
Err(e) => panic!("Unable to load cbindgen.toml configuration: {:?}", e),
};
match cbindgen::generate_with_config(&crate_dir, config) {
Ok(bindings) => {
if let Some(parent) = out_dir.parent() {
fs::create_dir_all(parent).expect("Unable to create parent directories for output file");
}
bindings.write_to_file(out_dir.join("lib_tool.h"));
println!("Successfully generated lib_tool.h in {}", out_dir.display());
}
Err(e) => {
eprintln!("Failed to generate bindings: {:?}", e);
std::process::exit(1);
}
}
}