Crates.io | wasm3 |
lib.rs | wasm3 |
version | 0.3.1 |
source | src |
created_at | 2020-05-22 20:56:47.831285 |
updated_at | 2021-09-19 12:14:14.946544 |
description | Rust bindings for wasm3 |
homepage | https://github.com/wasm3/wasm3-rs |
repository | https://github.com/wasm3/wasm3-rs |
max_upload_size | |
id | 244704 |
size | 72,494 |
Rust wrapper for WASM3.
This is currently work in progress and may or may not be entirely sound.
A simple example that loads a wasm module and executes an exported function to add two i64
s 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())
}
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
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
Licensed under the MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)