extern crate cc;
extern crate cmake;
#[cfg(windows)]
extern crate glob;
use std::env;
fn main() {
let dst = cmake::Config::new("wabt")
.define("BUILD_TESTS", "OFF")
.define("BUILD_TOOLS", "OFF")
.no_build_target(true)
.build();
let mut out_build_dir = dst;
out_build_dir.push("build");
println!("cargo:rustc-link-search=native={}", out_build_dir.display());
#[cfg(windows)]
{
let pattern = format!("{}/*/wabt.lib", out_build_dir.display());
for entry in glob::glob(&pattern).unwrap() {
if let Ok(path) = entry {
let out_lib_dir = path.parent().unwrap().to_path_buf();
println!("cargo:rustc-link-search=native={}", out_lib_dir.display());
break;
}
}
}
println!("cargo:rustc-link-lib=static=wabt");
if let Some(cpp_stdlib) = get_cpp_stdlib() {
println!("cargo:rustc-link-lib={}", cpp_stdlib);
}
let mut cfg = cc::Build::new();
cfg.file("wabt/src/emscripten-helpers.cc")
.file("wabt_shim.cc")
.include("wabt")
.include(out_build_dir)
.cpp_link_stdlib(None)
.warnings(false)
.cpp(true)
.flag("-std=c++11")
.compile("wabt_shim");
}
fn get_cpp_stdlib() -> Option<String> {
env::var("TARGET").ok().and_then(|target| {
if target.contains("msvc") {
None
} else if target.contains("darwin") {
Some("c++".to_string())
} else if target.contains("freebsd") {
Some("c++".to_string())
} else if target.contains("musl") {
Some("static=stdc++".to_string())
} else {
Some("stdc++".to_string())
}
})
}