Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

Web Image

Web Image is an experimental backend for Native Image that produces a WebAssembly module from Java code.

Prerequisites

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 binaryen

Building

To build Web Image, run the mx build command in the web-image suite:

cd /path/to/graal
cd web-image
mx build

Usage

Use 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 ... HelloWorld

This 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 World

WebAssembly Features

The WebAssembly code generated by Web Image makes use of various WebAssembly features from WebAssembly 3.0:

Support for WebAssembly 2.0 is generally assumed.

Contributors

  • Aleksandar Prokopec
  • Christoph Schobesberger
  • David Leopoldseder
  • Fengyun Liu
  • Patrick Ziegler