15 stable releases (5 major)

new 23.0.1 Jul 22, 2024
22.0.0 Jun 20, 2024
21.0.1 May 22, 2024
20.0.2 May 7, 2024
18.0.3 Mar 12, 2024

#293 in WebAssembly

Download history 1434/week @ 2024-04-01 2044/week @ 2024-04-08 1864/week @ 2024-04-15 3223/week @ 2024-04-22 2896/week @ 2024-04-29 3972/week @ 2024-05-06 2520/week @ 2024-05-13 2877/week @ 2024-05-20 2504/week @ 2024-05-27 2465/week @ 2024-06-03 2746/week @ 2024-06-10 3117/week @ 2024-06-17 3009/week @ 2024-06-24 2456/week @ 2024-07-01 4995/week @ 2024-07-08 2944/week @ 2024-07-15

13,784 downloads per month
Used in 4 crates (2 directly)

Apache-2.0 WITH LLVM-exception

3MB
46K SLoC

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.

  1. Add a dependency on the wasmtime-c-api-impl crate to your Cargo.toml. Note that package name differs from the library name.
[dependencies]
wasmtime-c-api = { version = "16.0.0", package = "wasmtime-c-api-impl" }
  1. In your build.rs file, when compiling your C/C++ source code, add the C wasmtime-c-api headers 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");
}

Dependencies

~17–32MB
~558K SLoC