Web Image is an experimental backend for Native Image that produces a WebAssembly module from Java code.
Being part of Native Image, see the Quick Start Guide for all the prerequisites for building Native Image.
In addition, Web Image also uses wasm-as from
binaryen as its assembler.
Version 119 of wasm-as has to be available on your PATH.
Installation
Binaryen provides pre-built releases for all major platforms on GitHub.
On MacOS, it is recommended to install through Homebrew, as the pre-built binaries are not signed and may be quarantined by MacOS.
brew install binaryenTo build Web Image, run the mx build command in the web-image suite:
cd /path/to/graal
cd web-image
mx buildUse this as you would use the regular native-image tool, but with an
additional --tool:svm-wasm flag to enable the WebAssembly backend:
mx native-image --tool:svm-wasm -cp ... HelloWorldThis produces helloworld.js and helloworld.js.wasm in your working
directory. The --tool:svm-wasm flag should be the first argument if possible.
If any experimental options specific to the Wasm backend are used, they can
only be added after the --tool:svm-wasm flag.
The JavaScript file is a wrapper that loads and runs the WebAssembly code and can be run with Node.js 22 or later:
# --experimental-wasm-exnref is only required for Node versions before 25
$ node --experimental-wasm-exnref helloworld.js
Hello WorldThe WebAssembly code generated by Web Image makes use of various WebAssembly features from WebAssembly 3.0:
Support for WebAssembly 2.0 is generally assumed.
- Aleksandar Prokopec
- Christoph Schobesberger
- David Leopoldseder
- Fengyun Liu
- Patrick Ziegler