#wasm-module #wapc #sdk #api-bindings #waxosuit

wapc-guest

Guest SDK for building waPC-compliant WebAssembly Modules

11 releases (3 stable)

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

#621 in WebAssembly

Download history 848/week @ 2024-07-20 1107/week @ 2024-07-27 1118/week @ 2024-08-03 1326/week @ 2024-08-10 865/week @ 2024-08-17 864/week @ 2024-08-24 1088/week @ 2024-08-31 987/week @ 2024-09-07 810/week @ 2024-09-14 1239/week @ 2024-09-21 1154/week @ 2024-09-28 956/week @ 2024-10-05 475/week @ 2024-10-12 1295/week @ 2024-10-19 746/week @ 2024-10-26 907/week @ 2024-11-02

3,626 downloads per month
Used in 22 crates (18 directly)

Apache-2.0

12KB
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–5MB
~15K SLoC