6 releases (2 stable)

new 1.1.0 Mar 23, 2023
1.0.0 Feb 10, 2022
1.0.0-alpha.0 Jan 21, 2022
0.0.3 Oct 12, 2021
0.0.1 Sep 23, 2020

#726 in WebAssembly

Download history 23/week @ 2022-12-06 19/week @ 2022-12-13 18/week @ 2022-12-20 20/week @ 2022-12-27 4/week @ 2023-01-03 15/week @ 2023-01-10 20/week @ 2023-01-17 35/week @ 2023-01-24 26/week @ 2023-01-31 37/week @ 2023-02-07 35/week @ 2023-02-14 21/week @ 2023-02-21 39/week @ 2023-02-28 15/week @ 2023-03-07 11/week @ 2023-03-14 30/week @ 2023-03-21

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

Apache-2.0

16KB
349 lines

Wasm3 Engine Provider

crates.io license

This is a pluggable engine provider for the waPC RPC exchange protocol. This engine implements WebAssemblyEngineProvider for the wasm3 C-based, interpreted WebAssembly runtime.

Running the demo

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

Example

use wasm3_provider::Wasm3EngineProvider;
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 = Wasm3EngineProvider::new(&module_bytes);
  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

~1.4–5.5MB
~99K SLoC