mirror of
https://github.com/fluencelabs/wasmer
synced 2025-07-31 23:32:04 +00:00
feat(runtime-c-api) Generate the C header file in OUT_DIR
.
This patch changes the directory where the C header files are generated, from `CARGO_MANIFEST_DIR` to `OUT_DIR`. The goal is: When `wasm-runtime-c-api` is used as a dependency of another Rust project, then the C header files are accessible in the `target/` directory (i.e. the `OUT_DIR`). Also, since `rustc` has a `--out-dir` directory, it increases the flexibility of this approach: The user can generate the C header files where she wants.
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
#[cfg(feature = "generate-c-api-headers")]
|
#[cfg(feature = "generate-c-api-headers")]
|
||||||
extern crate cbindgen;
|
extern crate cbindgen;
|
||||||
|
|
||||||
use std::env;
|
use std::{env, path::Path};
|
||||||
|
|
||||||
static CAPI_ENV_VAR: &str = "WASM_EMSCRIPTEN_GENERATE_C_API_HEADERS";
|
static CAPI_ENV_VAR: &str = "WASM_EMSCRIPTEN_GENERATE_C_API_HEADERS";
|
||||||
|
|
||||||
@@ -14,6 +14,12 @@ fn main() {
|
|||||||
#[cfg(feature = "generate-c-api-headers")]
|
#[cfg(feature = "generate-c-api-headers")]
|
||||||
fn build() {
|
fn build() {
|
||||||
let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
|
let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
|
||||||
|
let out_dir = env::var("OUT_DIR").unwrap();
|
||||||
|
let out_path = Path::new(&out_dir);
|
||||||
|
let mut wasmer_h = out_path.to_path_buf();
|
||||||
|
wasmer_h.push("wasmer.h");
|
||||||
|
let mut wasmer_hh = out_path.to_path_buf();
|
||||||
|
wasmer_hh.push("wasmer.hh");
|
||||||
|
|
||||||
use cbindgen::Language;
|
use cbindgen::Language;
|
||||||
cbindgen::Builder::new()
|
cbindgen::Builder::new()
|
||||||
@@ -22,7 +28,7 @@ fn build() {
|
|||||||
.with_include_guard("WASMER_H")
|
.with_include_guard("WASMER_H")
|
||||||
.generate()
|
.generate()
|
||||||
.expect("Unable to generate C bindings")
|
.expect("Unable to generate C bindings")
|
||||||
.write_to_file("wasmer.h");
|
.write_to_file(wasmer_h);
|
||||||
|
|
||||||
cbindgen::Builder::new()
|
cbindgen::Builder::new()
|
||||||
.with_crate(crate_dir)
|
.with_crate(crate_dir)
|
||||||
@@ -30,7 +36,7 @@ fn build() {
|
|||||||
.with_include_guard("WASMER_H")
|
.with_include_guard("WASMER_H")
|
||||||
.generate()
|
.generate()
|
||||||
.expect("Unable to generate C++ bindings")
|
.expect("Unable to generate C++ bindings")
|
||||||
.write_to_file("wasmer.hh");
|
.write_to_file(wasmer_hh);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "generate-c-api-headers"))]
|
#[cfg(not(feature = "generate-c-api-headers"))]
|
||||||
|
Reference in New Issue
Block a user