Skip to content

Commit

Permalink
feat(runtime-c-api) Generate the C header file in OUT_DIR.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Hywan committed Mar 6, 2019
1 parent 28bb264 commit 7c56d89
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/runtime-c-api/build.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#[cfg(feature = "generate-c-api-headers")]
extern crate cbindgen;

use std::env;
use std::{env, path::Path};

static CAPI_ENV_VAR: &str = "WASM_EMSCRIPTEN_GENERATE_C_API_HEADERS";

Expand All @@ -14,6 +14,12 @@ fn main() {
#[cfg(feature = "generate-c-api-headers")]
fn build() {
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;
cbindgen::Builder::new()
Expand All @@ -22,15 +28,15 @@ fn build() {
.with_include_guard("WASMER_H")
.generate()
.expect("Unable to generate C bindings")
.write_to_file("wasmer.h");
.write_to_file(wasmer_h);

cbindgen::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(wasmer_hh);
}

#[cfg(not(feature = "generate-c-api-headers"))]
Expand Down

0 comments on commit 7c56d89

Please sign in to comment.