forked from wasmerio/wasmer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request wasmerio#238 from Hywan/feat-runtime-c-api-headers…
…-in-out-dir feat(runtime-c-api) Generate the C/C++ header files in `OUT_DIR` (+ copy in `CARGO_MANIFEST_DIR`).
- Loading branch information
Showing
7 changed files
with
50 additions
and
38 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
[package] | ||
name = "wasmer-runtime-c-api" | ||
version = "0.2.1" | ||
description = "Wasmer c-api library" | ||
description = "Wasmer C API library" | ||
license = "MIT" | ||
authors = ["The Wasmer Engineering Team <[email protected]>"] | ||
repository = "https://github.com/wasmerio/wasmer" | ||
|
@@ -14,12 +14,7 @@ wasmer-runtime-core = { path = "../runtime-core", version = "0.2.1" } | |
libc = "0.2" | ||
|
||
[lib] | ||
crate-type = ["cdylib"] | ||
crate-type = ["cdylib", "rlib"] | ||
|
||
[build-dependencies] | ||
cbindgen = { version = "0.8", optional = true } | ||
|
||
[features] | ||
generate-c-api-headers = ["cbindgen"] | ||
|
||
|
||
cbindgen = "0.8" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,52 @@ | ||
#[cfg(feature = "generate-c-api-headers")] | ||
extern crate cbindgen; | ||
|
||
use std::env; | ||
|
||
static CAPI_ENV_VAR: &str = "WASM_EMSCRIPTEN_GENERATE_C_API_HEADERS"; | ||
use cbindgen::{Builder, Language}; | ||
use std::{env, fs, path::PathBuf}; | ||
|
||
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(); | ||
let mut crate_wasmer_header_file = PathBuf::from(&crate_dir); | ||
crate_wasmer_header_file.push("wasmer"); | ||
|
||
use cbindgen::Language; | ||
cbindgen::Builder::new() | ||
let out_dir = env::var("OUT_DIR").unwrap(); | ||
let mut out_wasmer_header_file = PathBuf::from(&out_dir); | ||
out_wasmer_header_file.push("wasmer"); | ||
|
||
// Generate the C bindings in the `OUT_DIR`. | ||
out_wasmer_header_file.set_extension("h"); | ||
Builder::new() | ||
.with_crate(crate_dir.clone()) | ||
.with_language(Language::C) | ||
.with_include_guard("WASMER_H") | ||
.generate() | ||
.expect("Unable to generate C bindings") | ||
.write_to_file("wasmer.h"); | ||
.write_to_file(out_wasmer_header_file.as_path()); | ||
|
||
cbindgen::Builder::new() | ||
// Generate the C++ bindings in the `OUT_DIR`. | ||
out_wasmer_header_file.set_extension("hh"); | ||
Builder::new() | ||
.with_crate(crate_dir) | ||
.with_language(Language::Cxx) | ||
.with_include_guard("WASMER_H") | ||
.generate() | ||
.expect("Unable to generate C++ bindings") | ||
.write_to_file("wasmer.hh"); | ||
} | ||
.write_to_file(out_wasmer_header_file.as_path()); | ||
|
||
// Copy the generated C bindings from `OUT_DIR` to | ||
// `CARGO_MANIFEST_DIR`. | ||
crate_wasmer_header_file.set_extension("h"); | ||
out_wasmer_header_file.set_extension("h"); | ||
fs::copy( | ||
out_wasmer_header_file.as_path(), | ||
crate_wasmer_header_file.as_path(), | ||
) | ||
.expect("Unable to copy the generated C bindings"); | ||
|
||
#[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") | ||
// Copy the generated C++ bindings from `OUT_DIR` to | ||
// `CARGO_MANIFEST_DIR`. | ||
crate_wasmer_header_file.set_extension("h"); | ||
crate_wasmer_header_file.set_extension("hh"); | ||
out_wasmer_header_file.set_extension("hh"); | ||
fs::copy(out_wasmer_header_file, crate_wasmer_header_file) | ||
.expect("Unable to copy the generated C++ bindings"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters