Home

Awesome

SWUbanner

embedded-wasm-apps

Run native, statically-compiled apps on any platform, using WebAssembly.
Examples include <img src="https://cdn.rawgit.com/simple-icons/simple-icons/develop/icons/assemblyscript.svg" width="18" height="18" /> AssemblyScript, <img src="https://cdn.rawgit.com/simple-icons/simple-icons/develop/icons/rust.svg" width="18" height="18" /> Rust, <img src="https://cdn.rawgit.com/simple-icons/simple-icons/develop/icons/cplusplus.svg" width="18" height="18" /> C/C++, <img src="https://cdn.rawgit.com/simple-icons/simple-icons/develop/icons/go.svg" width="18" height="18" /> TinyGo, <img src="https://cdn.rawgit.com/simple-icons/simple-icons/develop/icons/zig.svg" width="18" height="18" /> Zig, Virgil, WAT, 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

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 the required tools are in your PATH:

# AssemblyScript v0.27 (needs Node.js)
make APP=assemblyscript

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

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

# C99 Coremark (needs Clang)
make APP=coremark

# TinyGo v0.33.0 + Go v1.23.0
make APP=tinygo

# Zig v0.13.0
make APP=zig

# Virgil (Aeneas III-7.1632)
make APP=virgil

# WAT
make APP=wat

Resulting WASM file comparison:

ASC/C++CoremarkRustTinyGoVirgilWATZig
3951864108001226412273152231057

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, P2 / Photon2:

particle flash MyDevice ./src/*

# Open serial monitor
particle serial monitor --follow

License

This project is released under The MIT License (MIT)