extern crate bindgen;
extern crate cc;
use std::env;
use std::path::PathBuf;
fn main() {
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
let clips_core_dir = PathBuf::from("CLIPS/core");
let files =
std::fs::read_dir(&clips_core_dir)
.expect("CLIPS core dir not found")
.map(|entry| entry.expect("not a valid entry"))
.filter(|entry| {
!entry.file_type().expect("not a valid filetype").is_dir()
})
.map(|entry| PathBuf::from(entry.path()))
.filter(|path| match path.extension() {
None => false,
Some(extension) => extension == "c",
})
.filter(|path| cfg!(feature = "developer") || !path.ends_with("developr.c"));
eprintln!("{:?}", files);
let mut build = cc::Build::new();
build
.files(files)
.include(&clips_core_dir)
.out_dir(&out_dir)
.flag("-Wno-unused-parameter")
.flag("-Wno-missing-field-initializers");
if cfg!(feature = "developer") {
build.define("DEVELOPER", "1");
}
build
.compile("clips");
let _res = std::fs::copy(PathBuf::from("wrapper.h"), &out_dir.join("wrapper.h"));
println!("cargo:rustc-link-lib=static=clips");
println!("cargo:rustc-link-search={}", &out_dir.join("CLIPS/core").display());
let out_path = out_dir.join("bindings.rs");
if !out_path.exists() {
let bindings = bindgen::Builder::default()
.header("CLIPS/core/clips.h")
.derive_debug(true)
.impl_debug(true)
.derive_default(true)
.generate()
.expect("Unable to generate bindings");
bindings
.write_to_file(out_path)
.expect("Couldn't write bindings!");
}
}