wasmer/lib/runtime-c-api/build.rs

38 lines
999 B
Rust
Raw Normal View History

#[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;
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)
.generate()
2019-02-05 01:54:12 +00:00
.expect("Unable to generate C bindings")
.write_to_file("wasmer.h");
2019-02-05 01:54:12 +00:00
cbindgen::Builder::new()
.with_crate(crate_dir)
.with_language(Language::Cxx)
.generate()
.expect("Unable to generate C++ bindings")
.write_to_file("wasmer.hh");
}
#[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")
}