#![allow(unreachable_code)]
#![allow(unused_assignments)]
#![allow(unused_variables)]
#![allow(unused_mut)]
use std::env;
use std::fs::File;
use std::io::prelude::*;
use std::path::PathBuf;
#[cfg(not(any(feature = "fdb-6_3", feature = "fdb-7_1")))]
const INCLUDE_PATH: &str = "";
#[cfg(feature = "fdb-6_3")]
const INCLUDE_PATH: &str = "-I./include/630";
#[cfg(feature = "fdb-7_1")]
const INCLUDE_PATH: &str = "-I./include/710";
fn main() {
println!("cargo:rustc-link-lib=dylib=fdb_c");
if let Ok(link_search) = env::var("RUSTC_LINK_SEARCH_FDB_CLIENT_LIB") {
println!("cargo:rustc-link-search=native={}", link_search);
}
let out_path = PathBuf::from(env::var("OUT_DIR").expect("OUT_DIR is not defined!"));
let mut api_version = 0;
#[cfg(not(any(feature = "fdb-6_3", feature = "fdb-7_1")))]
panic!("Please specify fdb-<major>_<minor> feature");
#[cfg(feature = "fdb-6_3")]
{
api_version = 630;
}
#[cfg(feature = "fdb-7_1")]
{
api_version = 710;
}
let wpath = out_path.join("wrapper.h");
let wrapper_path = wpath
.to_str()
.expect("couldn't convert wrapper PathBuf to String!");
let mut wrapper = File::create(wrapper_path).expect("couldn't create wrapper.h!");
wrapper
.write_all(
format!(
"// This is used as `header_version` in\n\
// `fdb_select_api_version_impl`\n\
#define FDB_API_VERSION {}\n",
api_version
)
.as_bytes(),
)
.expect("couldn't write wrapper.h!");
wrapper
.write_all(b"#include <fdb_c.h>\n")
.expect("couldn't write wrapper.h!");
drop(wrapper);
let bindings = bindgen::Builder::default()
.clang_arg(INCLUDE_PATH)
.header(wrapper_path)
.generate_comments(true)
.generate()
.expect("Unable to generate FoundationDB bindings");
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");
}