Git Product home page Git Product logo

wasm3-rs's Introduction

SWUbanner

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)

wasm3-rs's People

Contributors

bacongobbler avatar jacobrosenthal avatar jiayihu avatar jimpo avatar jonas-schievink avatar veykril avatar vshymanskyy avatar wildbook avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.