#bus #wasi

wasmer-bus

Invocation bus for web assembly modules

1 stable release

1.1.0 Aug 8, 2022

#1544 in WebAssembly

Download history 20/week @ 2024-06-23 4/week @ 2024-06-30 12/week @ 2024-07-07 24/week @ 2024-07-14 12/week @ 2024-07-21 37/week @ 2024-07-28 10/week @ 2024-08-04 9/week @ 2024-08-11 7/week @ 2024-08-18 21/week @ 2024-08-25 18/week @ 2024-09-01 10/week @ 2024-09-08 10/week @ 2024-09-15 26/week @ 2024-09-22 24/week @ 2024-09-29 1/week @ 2024-10-06

63 downloads per month
Used in 12 crates (6 directly)

MIT/Apache

94KB
2.5K SLoC

WASM General Purpose Bus

The WASM Genernal Purpose Bus implements a standard syscall interface for WebAssembly libraries and executables to use to invoke and receive calls between WASM modules and/or operating system functions.

Currently the WASM Bus is supported by the following runtimes:

Functionality supported by this BUS includes

  • Web Socket connections
  • HTTP and HTTPS calls
  • Spawning sub-processes
  • Thread sleeping and timeouts
  • Asynchronous Runtime Engine
  • Client side invocation of WASM modules

TODO

  • Spawning threads
  • Multi-threaded Runtime Engine
  • Universal Logging
  • Server side invocation of WASM modules

Backend Implementations

In order to implment this BUS on your runtime one needs to chain to the ABI exposed in this library and implement the functions.

For a reference implementation see below:

https://github.com/wasmerio/ate/tree/master/wasmer_term/src/bus

Example API

Below is a simple example of how to emit the helper classes and serialization objects for a specific API

use wasmer_bus::macros::*;

#[wasmer_bus(format = "json")]
pub trait Time {
    async fn sleep(&self, duration_ms: u128);
}

Relative Objects

It is also possible to emit a series of sub-apis that carry with them some specific context

use serde::*;
use std::sync::Arc;
use wasmer_bus::macros::*;

#[wasmer_bus(format = "bincode")]
pub trait SocketBuilder {
    async fn connect(
        &self,
        url: String,
        state_change: impl Fn(SocketState),
        receive: impl Fn(Vec<u8>),
    ) -> Arc<dyn WebSocket>;
}

#[wasmer_bus(format = "bincode")]
pub trait WebSocket {
    async fn send(&self, data: Vec<u8>) -> SendResult;
}

Testing

You can test your WASI program by uploading it to wapm.io and then heading over to the Wasmer Shell

https://wasmer.sh

Dependencies

~5–11MB
~119K SLoC