2019-02-02 00:52:22 +00:00
|
|
|
#[cfg(feature = "generate-c-api-headers")]
|
|
|
|
extern crate cbindgen;
|
|
|
|
|
|
|
|
use std::env;
|
|
|
|
|
|
|
|
static CAPI_ENV_VAR: &str = "WASM_EMSCRIPTEN_GENERATE_C_API_HEADERS";
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
if env::var(CAPI_ENV_VAR).unwrap_or("0".to_string()) == "1" {
|
|
|
|
build();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(feature = "generate-c-api-headers")]
|
|
|
|
fn build() {
|
|
|
|
let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
|
|
|
|
|
2019-02-02 04:10:36 +00:00
|
|
|
use cbindgen::Language;
|
2019-02-02 00:52:22 +00:00
|
|
|
cbindgen::Builder::new()
|
2019-02-05 01:54:12 +00:00
|
|
|
.with_crate(crate_dir.clone())
|
2019-02-02 04:10:36 +00:00
|
|
|
.with_language(Language::C)
|
2019-02-10 00:07:05 +00:00
|
|
|
.with_include_guard("WASMER_H")
|
2019-02-02 00:52:22 +00:00
|
|
|
.generate()
|
2019-02-05 01:54:12 +00:00
|
|
|
.expect("Unable to generate C bindings")
|
2019-02-02 00:52:22 +00:00
|
|
|
.write_to_file("wasmer.h");
|
2019-02-05 01:54:12 +00:00
|
|
|
|
|
|
|
cbindgen::Builder::new()
|
|
|
|
.with_crate(crate_dir)
|
|
|
|
.with_language(Language::Cxx)
|
2019-02-10 00:07:05 +00:00
|
|
|
.with_include_guard("WASMER_H")
|
2019-02-05 01:54:12 +00:00
|
|
|
.generate()
|
|
|
|
.expect("Unable to generate C++ bindings")
|
|
|
|
.write_to_file("wasmer.hh");
|
2019-02-02 00:52:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(not(feature = "generate-c-api-headers"))]
|
|
|
|
fn build() {
|
|
|
|
panic!("environment var set to generate wasmer c API headers but generate-c-api-headers feature not enabled")
|
|
|
|
}
|