32 releases (stable)

1.15.0 Feb 29, 2024
1.13.0 Jan 9, 2024
1.12.0 Nov 25, 2023
1.8.0 Jul 24, 2023
0.0.2 Oct 27, 2020

#26 in WebAssembly

Download history 307/week @ 2023-11-24 141/week @ 2023-12-01 115/week @ 2023-12-08 74/week @ 2023-12-15 32/week @ 2023-12-22 62/week @ 2023-12-29 346/week @ 2024-01-05 503/week @ 2024-01-12 381/week @ 2024-01-19 409/week @ 2024-01-26 545/week @ 2024-02-02 321/week @ 2024-02-09 495/week @ 2024-02-16 630/week @ 2024-02-23 808/week @ 2024-03-01 400/week @ 2024-03-08

2,387 downloads per month
Used in 3 crates (2 directly)

Apache-2.0

39KB
816 lines

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.

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 

Example

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(())
}

See also

Dependencies

~10–22MB
~323K SLoC