mirror of
https://github.com/encounter/wasmtime.git
synced 2026-03-30 11:42:15 -07:00
8f03b22e07
* Remove wasm-c-api submodule
This submodule hasn't been updated in ~3 years at this point and we
additionally don't need most of the submodule. Instead add a script to
copy the files we need and verify in CI that the files are up-to-date.
This also makes using the C API a bit nicer where you don't have to have
two `include` directories with a Wasmtime source tree, just one
suffices.
* Don't format wasm.h{,h} vendored files
Wasmtime's C API
For more information you can find the documentation for this library online.
Using in a C Project
To use Wasmtime from a C or C++ project, you can use Cargo to build the Wasmtime C bindings. From the root of the Wasmtime repository, run the following command:
cargo build --release wasmtime-c-api
This will create static and dynamic libraries called libwasmtime in the target/release directory.
Using in a Rust Project
If you have a Rust crate that contains bindings to a C or C++ library that uses Wasmtime, you can link the Wasmtime C API using Cargo.
- Add a dependency on the
wasmtime-c-api-implcrate to yourCargo.toml. Note that package name differs from the library name.
[dependencies]
wasmtime-c-api = { version = "16.0.0", package = "wasmtime-c-api-impl" }
- In your
build.rsfile, when compiling your C/C++ source code, add the Cwasmtime-c-apiheaders to the include path:
fn main() {
let mut cfg = cc::Build::new();
// Add to the include path the wasmtime headers and the standard
// Wasm C API headers.
cfg
.include(std::env::var("DEP_WASMTIME_C_API_INCLUDE").unwrap());
.include(std::env::var("DEP_WASMTIME_C_API_WASM_INCLUDE").unwrap());
// Compile your C code.
cfg
.file("src/your_c_code.c")
.compile("your_library");
}