22 releases (14 stable)

new 1.6.0 May 25, 2023
1.5.0 Mar 23, 2023
1.3.2 Nov 22, 2022
1.0.1 Jun 25, 2022
0.0.2 Oct 27, 2020

#71 in WebAssembly

Download history 652/week @ 2023-02-04 190/week @ 2023-02-11 327/week @ 2023-02-18 608/week @ 2023-02-25 516/week @ 2023-03-04 434/week @ 2023-03-11 478/week @ 2023-03-18 263/week @ 2023-03-25 343/week @ 2023-04-01 426/week @ 2023-04-08 509/week @ 2023-04-15 110/week @ 2023-04-22 153/week @ 2023-04-29 208/week @ 2023-05-06 75/week @ 2023-05-13 195/week @ 2023-05-20

649 downloads per month
Used in 3 crates (2 directly)

Apache-2.0

38KB
820 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::WasmtimeEngineProvider;
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 = WasmtimeEngineProvider::new(&module_bytes, None)?;
  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

~14–22MB
~446K SLoC