#[cfg(any(target_os = "windows", target_os = "macos", target_os = "linux"))]
extern crate bindgen;
extern crate reqwest;
use std::{
env,
path::{Path, PathBuf},
};
fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("cargo:rerun-if-env-changed=DELIGHT");
let (include_path, lib_path) = match &env::var("DELIGHT") {
Err(_) => {
eprintln!("Building against 3Delight 2.1.2");
let lib_path = PathBuf::from(&env::var("OUT_DIR")?);
#[cfg(feature = "download_3delight_lib")]
{
use std::io::Write;
#[cfg(target_os = "windows")]
let lib = "https://www.dropbox.com/s/9iavkggor0ecc1x/3Delight.dll";
#[cfg(target_os = "macos")]
let lib = "https://www.dropbox.com/s/7vle92kcqbbyn8o/lib3delight.dylib";
#[cfg(target_os = "linux")]
let lib = "https://www.dropbox.com/s/hr62te8yg1d2e36/lib3delight.so";
let lib_file_path = lib_path.join(Path::new(lib).file_name().unwrap());
if !lib_file_path.exists() {
(|| {
let lib_data = reqwest::blocking::get(lib).ok()?.bytes().ok()?;
std::fs::File::create(lib_file_path)
.ok()?
.write_all(&lib_data)
.ok()?;
Some(())
})();
}
}
(
PathBuf::from(&env::var("CARGO_MANIFEST_DIR").unwrap()).join("include"),
lib_path,
)
}
Ok(path) => {
eprintln!("Building against locally installed 3Delight @ {}", &path);
let delight = Path::new(&path);
(delight.join("include"), delight.join("lib"))
}
};
eprintln!("include: {}", include_path.display());
eprintln!("lib: {}", lib_path.display());
println!("cargo:rustc-link-search={}", lib_path.display());
println!("cargo:rustc-link-lib=dylib=3delight");
let bindings = bindgen::Builder::default()
.header("include/wrapper.hpp")
.clang_arg(format!("-I{}", include_path.display()))
.clang_arg("-xc++")
.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.");
Ok(())
}