#sdk #wapc #webassembly #wasm #waxosuit

wapc-guest

Guest SDK for building waPC-compliant WebAssembly Modules

11 releases (3 stable)

new 1.1.0 Mar 23, 2023
1.0.0 Feb 10, 2022
0.4.0 Oct 15, 2020
0.3.1 Apr 14, 2020
0.1.1 Sep 19, 2019

#198 in WebAssembly

Download history 659/week @ 2022-12-03 634/week @ 2022-12-10 1115/week @ 2022-12-17 197/week @ 2022-12-24 431/week @ 2022-12-31 955/week @ 2023-01-07 1505/week @ 2023-01-14 768/week @ 2023-01-21 262/week @ 2023-01-28 909/week @ 2023-02-04 474/week @ 2023-02-11 645/week @ 2023-02-18 788/week @ 2023-02-25 754/week @ 2023-03-04 905/week @ 2023-03-11 1589/week @ 2023-03-18

4,077 downloads per month
Used in 20 crates (17 directly)

Apache-2.0

11KB
228 lines

waPC Guest SDK

crates.io license

The wapc-guest library is an implementation of the guest-side of the waPC WebAssembly protocol. wapc-guest gives Rust developers the pieces necessary to easily compile WebAssembly modules that you can load in waPC hosts. Each guest module registers function handlers with [register_function()]. Each handler should return a [CallResult] (a Result<Vec<u8>,Box<dyn Error + Sync + Send>>) with the function's return value.

It's typically used by code generated by the wapc CLI.

Example

use wapc_guest as wapc;

#[no_mangle]
pub fn wapc_init() {
  wapc::register_function("ping", ping);
}

fn ping(msg: &[u8]) -> wapc::CallResult {
  wapc::console_log(&format!(
    "IN_WASM: Received request for `ping` operation with payload : {}",
    std::str::from_utf8(msg).unwrap()
  ));
  let _res = wapc::host_call("binding", "sample:namespace", "pong", msg)?;
  Ok(msg.to_vec())
}

Building

This crate is meant for projects targeting wasm32-unknown-unknown or wasm32-wasi.

Dependencies

~0.4–4.5MB
~67K SLoC