Run statically-compiled WebAssembly apps on any embedded platform

Overview

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:

  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
  • Moderate runtime overhead (mostly depends on the source language/runtime)
  • Enables wasm transformations, like instrumentation or gas metering
  • Sandboxing / SFI (Software Fault Isolation)
  • Software-based memory virtualization

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
You might also like...
Simple, fast, JIT-compiled scripting language for game engines.
Simple, fast, JIT-compiled scripting language for game engines.

Aftel Aftel (acronym for «A Far Too Easy Language») is a programming language, primarily intended to serve as an embeddable scripting language for gam

StarkScript - or the Stark programming language - is a compiled C-based programming language that aims to offer the same usability as that of JavaScript's and TypeScript's

StarkScript StarkScript - or the Stark programming language - is a compiled C-based programming language that aims to offer the same usability as that

Pre-compiled builds for CVE-2021-4034

CVE-2021-4034 Precompiled builds for CVE-2021-4034. Of course you shouldn't trust precompiled builds :) This release works slightly different: first a

WebAssembly from Scratch: From FizzBuzz to DooM.

WebAssembly from Scratch: From FizzBuzz to DooM Exploring WebAssembly from scratch from a backend-person-point-of-view. A story in four acts. Welcome

Translates WebAssembly modules to C

w2c2 Translates WebAssembly modules to C. Inspired by wabt's wasm2c. Features Implements the WebAssembly Core Specification 1.0 Passes 99.9% of the We

Snake in C++ for WebAssembly

Snake-wasm Snake in C++ for WebAssembly This is a primitive greedy snake game demo in C++(ish) to test WebAssembly Getting Started Install emscripten

Minimal C# WebAssembly WebGL Example
Minimal C# WebAssembly WebGL Example

Minimal C# WebAssembly WebGL Example a minimal example of C# wasm WebGL app based on dotnet/runtimelab/NativeAOT-LLVM WebAssembly This example is port

An app that allows you to edit/create apps in Dash

AppAdder On Ubuntu, have you ever run a program or AppImage and the app not had an icon? This is a personal pet peeve. I've used AppImageLauncher to i

A set of very empty header files that can be used when building apps with Cosmopolitan

cosmo-include A set of very empty header files that can be used when building apps with Cosmopolitan Why? When you build an application with Cosmopoli

Comments
  • Importance of zstack-size

    Importance of zstack-size

    I'm trying to understand what zstack-size does and why it's important.

    Reason I'm trying to investigate his is that I'm almost certain that it causes a stack overflow in my code but I can't say for sure. I've taken the wasm module and run it in the browser I'm getting Maximum call stack size exceeded error. If I'm removing zstack-size then in the browser it runs to infinity but on arduino/wasm3 it doesn't even start.

    Any pointers would be greatly appreciated!

    opened by MendyBerger 0
Owner
Wasm3 Labs
Wasm3 Labs
Template for C++ GUI apps that can run in the browser

GGWeb Template for making a GUI app with C++ / Dear ImGui / SDL / OpenGL / Emscripten that can run both natively and in the browser. Example: https://

Georgi Gerganov 24 Nov 29, 2022
Run-time program generator embedded in C++

Run-time program generator embedded in C++

Z Guan 25 Aug 5, 2022
A place to collaborate on code for the Embedded.fm book club. Currently reading "STM32 ARM Programming for Embedded Systems".

Welcome to the Book Club Code site! This is a place for the Embedded.fm book club to collaborate and learn together. Repo Structure Guide Top-level fo

Peter Griffin 11 Jul 21, 2022
Embedded Flutter runtime targeting Embedded Linux with Wayland

ivi-homescreen IVI Homescreen for Wayland Strongly Typed (C++) Lightweight Clang 11 Release Stripped = 151k GCC 9.3 Release Stripped = 168k Source run

null 170 Dec 1, 2022
SDK for building cross-platform desktop apps in ANSI-C

NAppGUI Cross-Platform C SDK. Build portable desktop applications for Windows, macOS and Linux, using just C. Quick start in Windows Prerequisites Vis

Francisco García Collado 238 Dec 1, 2022
An embedded CAN bus sniffer which is able to monitor any of the vehicle internal CAN bus and perform some action by triggering new CAN messages.

An embedded CAN bus sniffer which is able to monitor any of the vehicle internal CAN bus and perform some action by triggering new CAN messages. In this way certain vehicle functionality can be triggered by responding to custom steering wheel button events, or use the vehicle virtual cockpit to display OBD-PIDs values instead of relying on an external display to present new information to the user

null 16 Nov 13, 2022
Loads a signed kernel driver which allows you to map any driver to kernel mode without any traces of the signed / mapped driver.

CosMapper Loads a signed kernel driver (signed with leaked cert) which allows you to map any driver to kernel mode without any traces of the signed /

null 154 Nov 25, 2022
Automatically load dlls into any executables without replacing any files!

Automatically loaded dll using xinput9_1_0 proxy. Please put the modified xinput9_1_0.dll in the executable's directory.

null 13 Nov 25, 2022
Create a calculator of any kind in any language, create a pr.

calculators Create a calculator of any kind in any language, create a pr. Create a calculator of any type using the programming language of your choic

Akshay Gautam 2 Oct 21, 2022