47 stable releases

new 2.15.0 Jan 8, 2026
2.14.0 Nov 25, 2025
2.13.0 Oct 21, 2025
2.10.0 Jul 24, 2025
0.0.2 Oct 27, 2020

#36 in WebAssembly

Download history 1000/week @ 2025-09-17 1267/week @ 2025-09-24 1030/week @ 2025-10-01 776/week @ 2025-10-08 644/week @ 2025-10-15 2106/week @ 2025-10-22 1047/week @ 2025-10-29 462/week @ 2025-11-05 950/week @ 2025-11-12 1295/week @ 2025-11-19 653/week @ 2025-11-26 522/week @ 2025-12-03 596/week @ 2025-12-10 610/week @ 2025-12-17 614/week @ 2025-12-24 429/week @ 2025-12-31

2,267 downloads per month
Used in 2 crates (via wascc-host)

Apache-2.0

70KB
1.5K SLoC

Wasmtime Engine Provider

crates.io license

This is a pluggable engine provider for the waPC RPC exchange protocol. This engine implements WebAssemblyEngineProvider for the the Bytecode Alliance's wasmtime WebAssembly runtime.

Usage

use wasmtime_provider::WasmtimeEngineProviderBuilder;
use wapc::WapcHost;
use std::error::Error;

pub fn main() -> Result<(), Box<dyn Error>> {

  // Sample host callback that prints the operation a WASM module requested.
  let host_callback = |id: u64, bd: &str, ns: &str, op: &str, payload: &[u8]| {
    println!("Guest {} invoked '{}->{}:{}' with a {} byte payload",
    id, bd, ns, op, payload.len());
    // Return success with zero-byte payload.
    Ok(vec![])
  };

  let file = "../../wasm/crates/wasm-basic/build/wasm_basic.wasm";
  let module_bytes = std::fs::read(file)?;

  let engine = WasmtimeEngineProviderBuilder::new()
    .module_bytes(&module_bytes)
    .build()?;
  let host = WapcHost::new(Box::new(engine), Some(Box::new(host_callback)))?;

  let res = host.call("ping", b"payload bytes")?;
  assert_eq!(res, b"payload bytes");

  Ok(())
}

async Support

The async feature enables the usage of this provider inside of an async context.

Note: this feature relies on the tokio runtime.

Check the WasmtimeEngineProviderAsync for more details.

Creating a new instance

The WasmtimeEngineProviderBuilder is used to create new instances of WasmtimeEngineProvider and WasmtimeEngineProviderAsync.

Fresh instances of the engines can be created by using pre-initialized instances like WasmtimeEngineProviderPre and WasmtimeEngineProviderAsyncPre.

Examples

Running ping demo

cargo run -p wasmtime-provider \
    --example wasmtime-demo \
    ./wasm/crates/wasm-basic/build/wasm_basic.wasm \
    ping "hi"

Running codec and module hotswapping demo

cargo run -p wasmtime-provider \
    --example wasmtime-hash-mreplace \
    AlexName

See also

Dependencies

~41–61MB
~1M SLoC