WebAssembly on Motor OS
The developer image includes Javy 9.1.0 and Wasmi 1.1.0. Compile JavaScript into WebAssembly and run it inside the VM, with no downloads.
Javy produces a WebAssembly module containing the QuickJS runtime. Wasmi interprets that module using the Motor port's WASI Preview 1 support.
Installed files
| Path | Contents |
|---|---|
/devtools/bin/javy | JavaScript-to-WebAssembly compiler. |
/devtools/bin/wasmi | WebAssembly interpreter and command runner. |
/devtools/javy/plugins/default.wasm | Default QuickJS plugin for explicit plugin selection and dynamic modules; also embedded in Javy. |
/devtools/javy/sources.txt, SHA256SUMS | Build provenance, source revisions, and staged-file checksums. |
/devtools/src/wasm/ | hello.js and a README with compile/run instructions. |
/devtools/www/wasm.html | This guide. |
make dev.img BUILD=release produces motor-os-dev.qcow2.
The smaller wasm.img also includes the tools and their data
directories. The example and HTML documentation are part of dev.img.
Run the example
In the developer VM's shell:
cd /devtools/src/wasm
MOTOR_OS_CAPS=0x200 /devtools/bin/javy build hello.js -o /none/tmp/hello.wasm
MOTOR_OS_CAPS=0 /devtools/bin/wasmi /none/tmp/hello.wasm
Expected output:
Hello from WebAssembly on Motor OS!
{"squares":[1,4,9,16],"total":30}
The masks launch the tools with role None: 0x200 grants Javy
filesystem write access for its output, while Wasmi needs no capabilities for this
example. /none/tmp is writable by role None. The default plugin is
embedded, and the example runs offline. Edit hello.js and repeat the
commands to try changes.
See Building Motor OS for image construction and
Capabilities for the masks. The host-side
src/tests/test-wasm.sh checks the installed tools;
src/tests/full-test-dev.sh --release includes those checks.