Giter Club home page Giter Club logo

embedded-wasm-apps's Introduction

SWUbanner

embedded-wasm-apps

Run native, statically-compiled apps on any platform, using WebAssembly.
Examples include AssemblyScript, Rust, C/C++, TinyGo, Zig, etc.

How it works

This does not use Wasm3 engine. The approach is similar to WasmBoxC or RLBox:

  1. Compile source code to wasm
  2. Translate wasm to C using wasm2c
  3. Compile produced C, link with a thin runtime implementation using the native platform toolchain

How it works

Benefits

  • Language/toolchain decoupling
  • Resilience against attacks (RCE, Control-flow hijacking)
  • Sandboxing / SFI (Software Fault Isolation)
  • Enables wasm transformations, like instrumentation or gas metering
  • Software-based memory virtualization
  • Moderate runtime overhead (mostly depends on the source language/runtime)
    • Small performance hit (~50% slowdown)
    • Moderate binary size increase
  • Highly portable

Example

$ make APP=rust
    Finished release [optimized] target(s) in 0.00s
$ pio run -e esp32 -t upload
$ pio device monitor
Initializing WebAssembly...
๐Ÿฆ€ Rust is running!

$ make APP=assemblyscript
    > npm run asbuild:optimized
$ pio run -e esp32 -t upload
$ pio device monitor
Initializing WebAssembly...
๐Ÿš€ AssemblyScript is running!

$ make APP=tinygo
$ pio run -e esp32 -t upload
$ pio device monitor
Initializing WebAssembly...
๐Ÿค– TinyGo is running!

Building WASM apps

Ensure WABT and Binaryen tools are in your PATH.

# AssemblyScript (needs Node.js)
cd apps/assemblyscript
npm install
cd ../..
make APP=assemblyscript

# Rust
rustup target add wasm32-unknown-unknown
make APP=rust

# C/C++ (needs wasienv)
make APP=cpp

# TinyGo (needs TinyGo v0.21.0 and Go v1.17.3)
make APP=tinygo

# Zig (needs Zig v0.9.0)
make APP=zig

Building and running with PlatformIO

# For ESP32:
pio run -e esp32 -t upload

# For ESP8266:
pio run -e esp8266 -t upload

# For Raspberry Pi Pico:
pio run -e rpi-pico -t upload

# Open serial monitor
pio device monitor --quiet

Building and running with Particle

Requires particle-cli. Should work on all Particle devices i.e. Spark Core, Photon, Electron, Argon, Boron:

particle flash MyDevice ./src/

# Open serial monitor
particle serial monitor --follow

License

This project is released under The MIT License (MIT)

embedded-wasm-apps's People

Contributors

vshymanskyy avatar kripken 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.