extern crate bindgen;
extern crate wolfssl_sys;
use std::env;
use std::path::Path;
use std::process::Command;
static LIGHTWAY_VERSION: &str = "lightway-core-1.1";
fn extract_lightway(dest: &str) -> std::io::Result<()> {
Command::new("tar")
.arg("-zxvf")
.arg(format!("vendor/{}.tar.gz", LIGHTWAY_VERSION))
.arg("-C")
.arg(dest)
.status()
.unwrap();
Ok(())
}
fn build_lightway(dest: &str) {
let include_path = Path::new(dest).join(format!("{}/include", LIGHTWAY_VERSION));
let src_path = Path::new(dest).join(format!("{}/src/he", LIGHTWAY_VERSION));
let mut build = cc::Build::new();
let src_paths = [
src_path.join("wolf.c"),
src_path.join("ssl_ctx.c"),
src_path.join("plugin_chain.c"),
src_path.join("msg_handlers.c"),
src_path.join("memory.c"),
src_path.join("flow.c"),
src_path.join("core.c"),
src_path.join("conn.c"),
src_path.join("config.c"),
src_path.join("client.c"),
];
build
.include(include_path)
.files(src_paths)
.static_flag(true);
if let Some(include) = std::env::var_os("DEP_WOLFSSL_INCLUDE") {
build.include(format!("{}/include", include.to_str().unwrap()));
} else {
panic!("No WolfSSL include!");
}
build.compile("helium");
}
fn main() -> std::io::Result<()> {
let outdir_string = env::var("OUT_DIR").unwrap();
extract_lightway(&outdir_string)?;
build_lightway(&outdir_string);
let dst = Path::new(&outdir_string);
let bindings = bindgen::Builder::default()
.header(format!("{}/lightway-core-1.1/public/he.h", outdir_string))
.clang_arg(format!("-I{}/include/", outdir_string))
.rustfmt_bindings(true)
.blocklist_file("/usr/include/features.h")
.blocklist_file("/usr/include/stdc-predef.h")
.blocklist_file("/usr/include/stdbool.h")
.blocklist_file("/usr/include/string.h")
.blocklist_file("/usr/include/stdlib.h")
.blocklist_file("/usr/include/stdint.h")
.generate()
.expect("Unable to generate bindings");
bindings
.write_to_file(dst.join("bindings.rs"))
.expect("Couldn't write bindings!");
println!("cargo:rustc-link-lib=static=helium");
println!("cargo:rustc-link-lib=static=wolfssl");
println!(
"cargo:include={}",
format!("{}/lightway-core-1.1/public/he.h", outdir_string)
);
Ok(())
}