extern crate cc;
extern crate bindgen;
use std::env;
use std::path::PathBuf;
fn main() {
if cfg!(feature = "guest") {
build_guest();
} else {
build_host();
}
}
fn build_guest() {
println!("cargo:rustc-cfg=guest");
let bindings = bindgen::Builder::default()
.header("vendor/cr.h")
.rustified_enum("cr_op")
.whitelist_type("cr_op")
.rustified_enum("cr_failure")
.whitelist_type("cr_failure")
.whitelist_type("cr_plugin")
.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("Couldn't write bindings!");
cc::Build::new()
.file("src/guest.c")
.flag("-Wno-unused-parameter")
.flag("-Wno-unknown-pragmas")
.compile("cr");
}
fn build_host() {
let bindings = bindgen::Builder::default()
.header("src/host.cpp")
.clang_arg("-x")
.clang_arg("c++")
.whitelist_function("cr_plugin_load")
.whitelist_function("rust_cr_plugin_reload_fix")
.whitelist_function("rust_cr_plugin_update_fix")
.whitelist_function("cr_plugin_close")
.whitelist_function("wrap_cr_set_temporary_path")
.rustified_enum("cr_op")
.whitelist_type("cr_op")
.rustified_enum("cr_failure")
.whitelist_type("cr_failure")
.whitelist_type("cr_plugin")
.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("Couldn't write bindings!");
cc::Build::new()
.cpp(true)
.file("src/host.cpp")
.flag("-Wno-unused-parameter")
.compile("cr");
}