7 releases

0.3.1 Sep 19, 2021
0.3.0 Sep 6, 2021
0.2.0 Aug 19, 2021
0.1.3 Sep 22, 2020
0.1.1 May 22, 2020

#333 in WebAssembly

Download history 72/week @ 2023-10-26 63/week @ 2023-11-02 77/week @ 2023-11-09 68/week @ 2023-11-16 91/week @ 2023-11-23 47/week @ 2023-11-30 62/week @ 2023-12-07 62/week @ 2023-12-14 72/week @ 2023-12-21 38/week @ 2023-12-28 71/week @ 2024-01-04 59/week @ 2024-01-11 59/week @ 2024-01-18 67/week @ 2024-01-25 57/week @ 2024-02-01 59/week @ 2024-02-08

258 downloads per month
Used in 9 crates (5 directly)

MIT license

320KB
7K SLoC

C 5.5K SLoC // 0.1% comments Rust 1.5K SLoC // 0.0% comments Python 12 SLoC

wasm3-rs

Build Crates.io Docs.rs Tokei

> wasm3-rs is looking for a maintainer <

Rust wrapper for WASM3.

This is currently work in progress and may or may not be entirely sound.

Sample

A simple example that loads a wasm module and executes an exported function to add two i64s together.

use wasm3::Environment;
use wasm3::Module;

fn main() {
    let env = Environment::new().expect("Unable to create environment");
    let rt = env
        .create_runtime(1024)
        .expect("Unable to create runtime");
    let module = Module::parse(&env, &include_bytes!("wasm/wasm_add/wasm_add.wasm")[..])
        .expect("Unable to parse module");

    let module = rt.load_module(module).expect("Unable to load module");
    let func = module
        .find_function::<(i64, i64), i64>("add")
        .expect("Unable to find function");
    println!("Wasm says that 3 + 6 is {}", func.call(3, 6).unwrap())
}

Building

This crate currently does not make use of the cmake project of wasm3, meaning cmake is not required to built this for the time being. It does however require Clang 9 to be installed as well as Bindgen, should the build-bindgen feature not be set.

The wasm3 c source is included via a submodule, so before building the submodule has to be initialized, this can be done via:

git submodule update --init

Then to build the project run:

cargo install bindgen
cargo build --release

# or:
cargo build --release --features build-bindgen

# or, enable only specific features:
cargo build --release --no-default-features --features build-bindgen,std,use-32bit-slots,wasi

Build and run examples

rustup target add wasm32-unknown-unknown

python wasm_bin_builder.py ./examples/wasm/wasm_add
cargo run --example call_wasm

python wasm_bin_builder.py ./examples/wasm/wasm_print
cargo run --example wasm_print

License

Licensed under the MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)

Dependencies

~7–260KB