extern crate bindgen;
extern crate cmake;
use cmake::Config;
use std::env;
use std::path::PathBuf;
fn main() {
let dst = Config::new("fizzy").define("FIZZY_TESTING", "OFF").build();
println!("cargo:rustc-link-lib=static=fizzy");
println!("cargo:rustc-link-search=native={}/lib", dst.display());
if let Some(cpp_stdlib) = get_cpp_stdlib() {
println!("cargo:rustc-link-lib={}", cpp_stdlib);
}
let bindings = bindgen::Builder::default()
.header("fizzy/include/fizzy/fizzy.h")
.generate_comments(true)
.whitelist_function("fizzy_.*")
.whitelist_var("Fizzy.*")
.whitelist_type("Fizzy.*")
.size_t_is_usize(true)
.generate()
.expect("Unable to generate bindings");
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Could not write bindings");
}
fn get_cpp_stdlib() -> Option<String> {
env::var("TARGET").ok().and_then(|target| {
if target.contains("msvc") {
None
} else if target.contains("darwin") || target.contains("freebsd") {
Some("c++".to_string())
} else if target.contains("musl") {
Some("static=stdc++".to_string())
} else {
Some("stdc++".to_string())
}
})
}