11 releases (2 stable)

1.1.0 Mar 6, 2022
1.0.0 Feb 1, 2022
0.5.0 Jan 8, 2022
0.4.1 Jan 8, 2022
0.1.1 Nov 27, 2021

#1081 in WebAssembly

Download history 16/week @ 2023-12-06 25/week @ 2023-12-13 35/week @ 2023-12-20 18/week @ 2023-12-27 13/week @ 2024-01-03 39/week @ 2024-01-10 20/week @ 2024-01-17 12/week @ 2024-01-24 14/week @ 2024-01-31 28/week @ 2024-02-07 37/week @ 2024-02-14 24/week @ 2024-02-21 45/week @ 2024-02-28 50/week @ 2024-03-06 42/week @ 2024-03-13 43/week @ 2024-03-20

187 downloads per month
Used in 12 crates (10 directly)

MIT/Apache

95KB
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/tokera-com/ate/tree/master/tokterm/src/bus

Example API

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

use wasm_bus::macros::*;

#[wasm_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 wasm_bus::macros::*;

#[wasm_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>;
}

#[wasm_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 Tokera Shell

https://tokera.sh

Dependencies

~3.5–5.5MB
~97K SLoC