use std::{env, path::PathBuf};
fn main() {
#[cfg(windows)]
let (zlib_include_dir, mman_include_dir) = {
let zlib = vcpkg::Config::new()
.emit_includes(true)
.find_package("zlib")
.unwrap();
let zlib_include_dir = zlib.include_paths[0].clone();
vcpkg::Config::new().find_package("pthreads").unwrap();
let mman = vcpkg::Config::new().find_package("mman").unwrap();
let mman_base_path = mman.include_paths[0].clone();
let mman_include_dir = mman_base_path.join(PathBuf::from("mman"));
(zlib_include_dir, mman_include_dir)
};
let mut cc_build = cc::Build::new();
cc_build
.files(["csrc/fastlz.c", "csrc/fstapi.c", "csrc/lz4.c"])
.define("FST_WRITER_PARALLEL", None)
.include("csrc")
.flag_if_supported("-Wno-unused-but-set-variable");
#[cfg(windows)]
cc_build
.include(&zlib_include_dir)
.include(&mman_include_dir);
cc_build.compile("fst");
println!("cargo:rerun-if-changed=csrc");
#[cfg(not(windows))]
println!("cargo:rustc-link-lib=z");
let bindgen_builder = bindgen::Builder::default()
.header("csrc/fstapi.h")
.allowlist_type(r#"(fst|FST_)\w+"#)
.allowlist_function(r#"(fst|FST_)\w+"#)
.allowlist_var(r#"(fst|FST_)\w+"#)
.clang_arg("-Icsrc");
#[cfg(windows)]
let bindgen_builder = bindgen_builder.clang_arg(format!("-I{}", zlib_include_dir.display()));
let bindings = bindgen_builder
.generate()
.expect("failed to generate bindings");
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()).join("bindings.rs");
bindings
.write_to_file(out_path)
.expect("failed to write bindings");
}