#wasm-interpreter #interpreter #vm #virtualization

sys no-std wasmi_c_api_impl

C bindings for the Wasmi WebAssembly interpreter

13 releases (4 breaking)

0.40.0 Nov 27, 2024
0.39.1 Nov 6, 2024
0.38.0 Oct 6, 2024
0.37.2 Oct 4, 2024
0.36.0 Jul 24, 2024

#1480 in WebAssembly

Download history 499/week @ 2024-09-26 592/week @ 2024-10-03 813/week @ 2024-10-10 1424/week @ 2024-10-17 1273/week @ 2024-10-24 1050/week @ 2024-10-31 889/week @ 2024-11-07 584/week @ 2024-11-14 657/week @ 2024-11-21 421/week @ 2024-11-28 1036/week @ 2024-12-05 490/week @ 2024-12-12 168/week @ 2024-12-19 61/week @ 2024-12-26 433/week @ 2025-01-02 546/week @ 2025-01-09

1,243 downloads per month
Used in 2 crates (via wasmer)

MIT/Apache

2MB
51K SLoC

Wasmi C-API

Usage in a C Project

If you have a C project with which you want to use Wasmi, you can interface with Wasmi's C API:

Prerequisites

From the root of the Wasmi repository, run the following commands:

cmake -S crates/c_api -B target/c_api --install-prefix "$(pwd)/artifacts" &&
cmake --build target/c_api --target install

These commands will produce the following files:

  • artifacts/lib/libwasmi.{a,lib}: The static Wasmi library.
  • artifacts/lib/libwasmi.{so,dylib,dll}: The dynamic (or shared) Wasmi library.
  • artifacts/include/**.h: The header files for interfacing with Wasmi from C or C++.

Usage in a Rust Project

If you have a Rust crate that uses a C or C++ library that uses Wasmi, you can link to the Wasmi C API as follows:

  1. Add a dependency on the wasmi_c_api_impl crate to your Cargo.toml. Note that package name differs from the library name.
[dependencies]
wasmi_c_api = { version = "0.35.0", package = "wasmi_c_api_impl" }
  1. In your build.rs file, when compiling your C/C++ source code, add the C wasmi_c_api headers to the include path:
fn main() {
    let mut cfg = cc::Build::new();
    // Add the Wasmi and standard Wasm C-API headers to the include path.
    cfg
        .include(std::env::var("DEP_WASMI_C_API_INCLUDE").unwrap());
        .include(std::env::var("DEP_WASMI_C_API_WASM_INCLUDE").unwrap());
    // Compile your C code.
    cfg
        .file("src/your_c_code.c")
        .compile("your_library");
}

Dependencies

~3MB
~54K SLoC