Giter Club home page Giter Club logo

resource-demo's Introduction

A demo showing WASM component model resources in various environments

Prerequisites

Rust target wasm32-wasi:

rustup target add wasm32-wasi

CMake

cpetig/wit-bindgen:

git clone https://github.com/cpetig/wit-bindgen.git
cd wit-bindgen
cargo install --path .

Working

Guest Host
C โœ… wit-bindgen see below1
C++ ๐Ÿšง cpetig/wit-bindgen ๐Ÿšง cpetig/wit-bindgen + WAMR
Rust โœ… wit-bindgen โœ… wasmtime 2
JavaScript ๐Ÿšง 3 โœ… jco 2
Go โ˜๏ธ 4 ?
Python ๐Ÿšง 5 ๐Ÿšง 5

Compiling and Running

cd guest-rust
cargo build --target wasm32-wasi --release

cd ../host-wamr
./generate.sh
mkdir build
cd build
cmake ..
make
./executor

Expected Output:

drop with value 34

C guest

Prerequisite: wasi-SDK

cd guest-c
./generate.sh
make
cd ..
ln -sf guest-c/guest-c.wasm guest.wasm 

Wasmtime host

You need a preview1 adapter matching the wasmtime version, see https://github.com/bytecodealliance/wasmtime/releases for the command adapter downloads.

But most likely you will need to check out the exact same wasmtime used for the host and build the adapter:

cd wasmtime/crates/wasi-preview1-component-adapter
cargo build -p wasi-preview1-component-adapter --target wasm32-unknown-unknown --release --features command --no-default-features
cp ../../target/wasm32-unknown-unknown/release/wasi_snapshot_preview1.wasm โ€ฆ/resource-demo/host-wasmtime

Jco host

Sorry, jco is currently broken until I figure out to compile typescript (shouldn't be that difficult to do).

Please use the adapter built from the wasmtime source (see above)

cargo install simple-http-server
./generate.sh
simple-http-server --cors --coop --coep --nocache -i html

Other environments

Host languages

  • Rust:

    Wasmer bindgen only supports the old witx, not the newer wit format. You could write a host binding generator within wit-bindgen though.

WASI preview2 adapter

The wasmtime host requires wasi_snapshot_preview1.wasm from (the dev branch) (WASI has recently migrated to resources)

JCO's preview2 browser shim still needs the older adapter

Guest languages

JavaScript: https://github.com/bytecodealliance/javy is potentially smaller than spidermonkey embedded by jco, you will need another tool to generate guest bindings for imported functions, IIRC. A path using C bindings with yet to be written JavaScript wrapping should be viable.

Footnotes

  1. Currently I generate C++ host bindings for WAMR, C would be feasible. โ†ฉ

  2. JCO and wasmtime currently need a different preview1 to preview2 adapter version โ†ฉ โ†ฉ2

  3. Jco likely needs the unfinished https://github.com/bytecodealliance/componentize-js/tree/resources for resource support in guests โ†ฉ

  4. Go: WIT bindgen support is being worked on โ†ฉ

  5. Python: https://pypi.org/project/componentize-py/ recently gained resource support โ†ฉ โ†ฉ2

resource-demo's People

Contributors

cpetig avatar yamt avatar

Stargazers

 avatar Karel Hrkal avatar  avatar Gordon Smith avatar Dan Gohman avatar  avatar Moaz bin Mokhtar avatar Tiemoko Ballo avatar

Watchers

 avatar

Forkers

yamt avrabe

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.