#sdk #wapc #webassembly #wasm #wasmtime

wasmtime-provider

A wasmtime engine provider for the waPC host

3 releases

new 0.0.3 Apr 18, 2021
0.0.2 Oct 27, 2020
0.0.1 Sep 23, 2020

#361 in WebAssembly

Download history 94/week @ 2021-01-01 209/week @ 2021-01-08 119/week @ 2021-01-15 156/week @ 2021-01-22 194/week @ 2021-01-29 86/week @ 2021-02-05 168/week @ 2021-02-12 37/week @ 2021-02-19 28/week @ 2021-02-26 108/week @ 2021-03-05 155/week @ 2021-03-12 232/week @ 2021-03-19 204/week @ 2021-03-26 95/week @ 2021-04-02 243/week @ 2021-04-09 152/week @ 2021-04-16

597 downloads per month
Used in 4 crates (2 directly)

Apache-2.0

22KB
437 lines

Wasmtime Engine Provider

This is a pluggable engine provider for the waPC RPC exchange protocol. This engine encapsulates the Bytecode Alliance wasmtime WebAssembly runtime.

To run the demo:

cargo run --example demo -- ./.assets/hello.wasm test

An example of using this engine provider:

pub fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
    env_logger::init();
    
    let module_bytes = load_file(&std::env::args().skip(1).next().unwrap());
    let engine = WasmtimeEngineProvider::new(&module_bytes, None);
    let host = WapcHost::new(Box::new(engine), host_callback)?;
    let func = std::env::args().skip(2).next().unwrap();

    let _res = host.call(&func, b"this is a test")?;
    Ok(())
}

fn host_callback(
    id: u64,
    bd: &str,
    ns: &str,
    op: &str,
    payload: &[u8],
) -> Result<Vec<u8>, Box<dyn std::error::Error + Send + Sync>> {
    println!(
        "Guest {} invoked '{}->{}:{}' with payload of {}",
        id,
        bd,
        ns,
        op,
        ::std::str::from_utf8(payload).unwrap()
    );
    Ok(vec![])
}

Dependencies

~19MB
~388K SLoC