extern crate bindgen;
extern crate metadeps;
use regex::Regex;
use std::env;
use std::fs::File;
use std::io::Write;
use std::path::PathBuf;
use std::vec::Vec;
fn main() {
metadeps::probe().unwrap();
let bindings = bindgen::Builder::default()
.header("wrapper.h")
.allowlist_file(r"(.*/e2p\.h)|(.*/ext2.*\.h)")
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
.generate()
.unwrap();
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings
.write_to_file(out_path.join("bindings.rs"))
.unwrap();
let re = Regex::new(r"(?m)^|\s+pub const ([^: ]+)\s?:").unwrap();
let mut constants = Vec::new();
let binding_code = bindings.to_string();
for cap in re.captures_iter(&binding_code) {
if let Some(m) = cap.get(1) {
constants.push(String::from(m.as_str()))
}
}
let mut f = File::create(out_path.join("constants.rs")).unwrap();
write!(
&mut f,
"\
/// A list of all public constants. Can be used to test for the
/// existence of certain constants in the system's libe2p.
pub const CONSTANTS: [&str; {}] = {:?};",
constants.len(),
constants
)
.unwrap();
}