use std::{ env, fs::File, path::{Path, PathBuf}, }; use tar::Archive; fn main() { let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap()); let bindings = bindgen::Builder::default() .header("c_api.h") .rustfmt_bindings(true) .generate() .expect("Unable to generate bindings."); bindings .write_to_file(out_dir.join("bindings.rs")) .expect("Couldn't write bindings."); extract_libraries(&out_dir); println!("cargo:rustc-link-search={}/libs", out_dir.display()); println!("cargo:rustc-link-lib=dylib=catboostmodel"); } fn extract_libraries(out_dir: &Path) -> Result<(), Box> { let out_dir = out_dir.join("libs"); std::fs::create_dir(&out_dir)?; let libs_path = format!("{}/libs.tar", env!("CARGO_MANIFEST_DIR")); let libs = File::open(libs_path)?; let libs = zstd::Decoder::new(libs)?; let mut archive = Archive::new(libs); for file in archive.entries()? { let mut file = file?; let out_file = out_dir.join(file.path()?); file.unpack(out_file)?; } Ok(()) }