extern crate cbindgen;
use std::env;
fn main() {
#[cfg(feature = "ipasir")]
{
}
let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
cbindgen::Builder::new()
.with_config(
cbindgen::Config::from_file(format!("{}/cbindgen.toml", crate_dir))
.expect("could not read cbindgen.toml"),
)
.with_crate(crate_dir)
.generate()
.expect("Unable to generate bindings")
.write_to_file("rustsat.h");
println!("cargo:rerun-if-changed=cbindgen.toml");
println!("cargo:rerun-if-changed=src/capi.rs");
let include_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let ld_dir = target_dir().unwrap();
println!(
"cargo:rustc-env=INLINE_C_RS_CFLAGS=-I{I} -L{L} -lrustsat -D_DEBUG -D_CRT_SECURE_NO_WARNINGS",
I = include_dir,
L = ld_dir.to_string_lossy()
);
println!(
"cargo:rustc-env=INLINE_C_RS_LDFLAGS={L}/librustsat.a",
L = ld_dir.to_string_lossy()
);
}
fn target_dir() -> Result<std::path::PathBuf, Box<dyn std::error::Error>> {
let out_dir = std::path::PathBuf::from(std::env::var("OUT_DIR")?);
let profile = std::env::var("PROFILE")?;
let mut target_dir = None;
let mut sub_path = out_dir.as_path();
while let Some(parent) = sub_path.parent() {
if parent.ends_with(&profile) {
target_dir = Some(parent);
break;
}
sub_path = parent;
}
let target_dir = target_dir.ok_or("not found")?;
Ok(target_dir.to_path_buf())
}