Giter Site home page Giter Site logo

wasmer-assemblyscript-example's Introduction

wasmer-assemblyscript-example

An example of using Wasmer to run Assemblyscript generated Webassembly inside a Rust program.

How to Run

You'll need Rust and Node installed on your machine.

Build the WASM

To build the WASM, which we'll run inside the host program:

cd wasm

npm run asbuild:optimized

This will compile the Assemblyscript module down to WASM, resulting in a build/optimized.wasm file.

Build the Host

Now we've built the WASM, we need to build our Rust host. In the repo root run:

cargo build

This will install the Wasmer library (WASM runtime) and build our WASM executor.

Run it

./target/debug/wasmer-assemblyscript-example

๐Ÿš€ You should see our WASM code logging 'Hello, World!' then exiting happily.

Extending it

This is a blueprint for embedding a WASM interpreter in your program. It doesn't do anything interesting yet, but it's an easy starting point for your WASM based projects.

  • Replace Rust: Wasmer supports a whole heap of host languages, so you can run WASM with whatever program/language you want
  • Replace Assemblyscript: As we compile our module down to WASM to run it, you can write your module in any language with a WASM backend (which is most of them by now ...)
  • Extend imports: Right now our host exposes just a couple of functions to the loaded WASM, so we can't do much very interesting work. Add extra functions to the import_object variable to let your WASM do something more interesting.

For brevity & simplicity, the generated WASM is currently statically linked to the host at build time (using include_bytes!). So every time you change your WASM you'll need to re-build it and re-build the host. Which isn't ideal. You'll likely want to replace that with a file loader before you get too far.

wasmer-assemblyscript-example's People

Contributors

dmfutcher avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

wasmer-assemblyscript-example's Issues

Nitpick

Replace Assemblyscript: As we compile our module down to WASM to run it, you can write your module in any language with a WASM backend (which is most of them by now ...)

WASM does not equal WASM. Some WASM is freestanding/standalone, and some is targeting WASI. Which one did you mean?

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.