|
1 | 1 | # Web Image |
2 | 2 |
|
| 3 | +Web Image is an experimental backend for Native Image that produces a |
| 4 | +WebAssembly module from Java code. |
| 5 | + |
| 6 | +## Prerequisites |
| 7 | + |
| 8 | +Being part of Native Image, check out its [Quick Start Guide](../docs/reference-manual/native-image/contribute/DevelopingNativeImage.md) |
| 9 | +for all the prerequisites for building Native Image. |
| 10 | + |
| 11 | +In addition, Web Image also uses `wasm-as` from |
| 12 | +[binaryen](https://github.com/WebAssembly/binaryen) as its assembler. |
| 13 | +Version 119 of `wasm-as` has to be available on your `PATH`. |
| 14 | + |
| 15 | +<details> |
| 16 | +<summary>Installation</summary> |
| 17 | + |
| 18 | +Binaryen provides pre-built releases for all major platforms on |
| 19 | +[GitHub](https://github.com/WebAssembly/binaryen/releases). |
| 20 | + |
| 21 | +On MacOS, it is recommended to install through [Homebrew](https://brew.sh/), as |
| 22 | +the pre-built binaries are not signed and may be quarantined by MacOS. |
| 23 | + |
| 24 | +```bash |
| 25 | +brew install binaryen |
| 26 | +``` |
| 27 | +</details> |
| 28 | + |
3 | 29 | ## Building |
4 | 30 |
|
| 31 | +To build Web Image, run the `mx build` command in the `web-image` suite: |
| 32 | + |
5 | 33 | ```bash |
| 34 | +cd /path/to/graal |
| 35 | +cd web-image |
6 | 36 | mx build |
7 | 37 | ``` |
8 | 38 |
|
9 | 39 | ## Usage |
10 | 40 |
|
11 | | -Use this as you would regular the regular `native-image` tool, but with an |
| 41 | +Use this as you would use the regular `native-image` tool, but with an |
12 | 42 | additional `--tool:svm-wasm` flag to enable the WebAssembly backend: |
13 | 43 |
|
14 | 44 | ```bash |
15 | 45 | mx native-image --tool:svm-wasm -cp ... HelloWorld |
16 | 46 | ``` |
17 | 47 |
|
18 | 48 | This produces `helloworld.js` and `helloworld.js.wasm` in your working |
19 | | -directory. The JavaScript file is a wrapper that loads and runs the WebAssembly |
20 | | -code and can be run with [Node.js](https://nodejs.org/en) 22 or later: |
| 49 | +directory. The `--tool:svm-wasm` flag should be the first argument if possible. |
| 50 | +If any experimental options specific to the Wasm backend are used, they can |
| 51 | +only be added after the `--tool:svm-wasm` flag. |
21 | 52 |
|
22 | | -The `--tool:svm-wasm` flag should be the first argument if possible. If any |
23 | | -experimental options specific to the Wasm backend are used, they can only be |
24 | | -added after the `--tool:svm-wasm` flag. |
| 53 | +The JavaScript file is a wrapper that loads and runs the WebAssembly |
| 54 | +code and can be run with [Node.js](https://nodejs.org/en) 22 or later: |
25 | 55 |
|
26 | 56 | ```bash |
27 | | -$ node helloworld.js |
| 57 | +# --experimental-wasm-exnref is only required for Node versions before 25 |
| 58 | +$ node --experimental-wasm-exnref helloworld.js |
28 | 59 | Hello World |
29 | 60 | ``` |
30 | 61 |
|
| 62 | +## WebAssembly Features |
| 63 | + |
| 64 | +The WebAssembly code generated by Web Image makes use of various WebAssembly |
| 65 | +features from WebAssembly 3.0: |
| 66 | + |
| 67 | +- [Garbage Collection](https://github.com/WebAssembly/gc) |
| 68 | +- [Exception Handling](https://github.com/WebAssembly/exception-handling/blob/master/proposals/exception-handling/Exceptions.md) |
| 69 | +- [Typed Function References](https://github.com/WebAssembly/function-references/blob/main/proposals/function-references/Overview.md) |
| 70 | + |
| 71 | +Support for [WebAssembly 2.0](https://www.w3.org/TR/wasm-core-2/#release-20) is |
| 72 | +generally assumed. |
| 73 | + |
31 | 74 | ## Contributors |
32 | 75 |
|
33 | 76 | - Aleksandar Prokopec |
|
0 commit comments