use std::env;
use std::path::PathBuf;
fn main() {
let mut vec_flags = vec![];
{
match env::var("JAVA_HOME") {
Ok(val) => {
vec_flags.push(format!("-I{}/include", val));
if cfg!(target_os = "linux") {
vec_flags.push(format!("-I{}/include/linux", val));
} else if cfg!(target_os = "macos") {
vec_flags.push(format!("-I{}/include/darwin", val));
}
println!("cargo:rustc-link-search=native={}/jre/lib/server", val);
println!("cargo:rustc-link-lib=jvm");
}
Err(e) => {
panic!("JAVA_HOME shell environment must be set: {}", e);
}
}
match env::var("HADOOP_HOME") {
Ok(val) => {
println!("cargo:rustc-link-search=native={}/lib/native", val);
println!("cargo:rustc-link-lib=hdfs");
vec_flags.push(format!("-I{}/include", val));
}
Err(e) => {
panic!("HADOOP_HOME shell environment must be set: {}", e);
}
}
}
{
let c_file = "c_src/libminidfs/native_mini_dfs.c";
println!("cargo:rerun-if-changed={}", c_file);
let mut builder = cc::Build::new();
builder.file(c_file);
for flag in &vec_flags {
builder.flag(flag.as_str());
}
builder.compile("minidfs");
}
{
let (header, output) = ("c_src/wrapper.h", "hdfs-native.rs");
println!("cargo:rerun-if-changed={}", header);
println!("cargo:rerun-if-changed={}", "c_src/libhdfs/hdfs.h");
println!(
"cargo:rerun-if-changed={}",
"c_src/libminidfs/native_mini_dfs.h"
);
let bindings = bindgen::Builder::default()
.header(header)
.allowlist_function("nmd.*")
.allowlist_function("hdfs.*")
.allowlist_function("hadoop.*")
.clang_args(vec_flags)
.rustified_enum("tObjectKind")
.generate()
.expect("Unable to generate bindings");
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings
.write_to_file(out_path.join(output))
.expect("Couldn't write bindings!");
}
}