# Edge WASM

> Build linear-memory WebAssembly from Java or Kotlin with Elide: bundle sizes, host requirements, and which runtimes run the output.

A [WebImage](https://elide.help/docs/toolchain/jvm/webimage) artifact with `backend = "wasm-lm"` compiles Java or Kotlin to WebAssembly for
JavaScript hosts that compile WebAssembly at runtime. The module keeps its heap and garbage collector in linear memory,
so the host needs no WasmGC support. Like the [browser build](https://elide.help/docs/toolchain/web/wasm), it starts through its JavaScript
loader; it is not a WASI module or component, and it does not deploy to Cloudflare Workers.

## Build

Prerequisites match the [browser build](https://elide.help/docs/toolchain/web/wasm#prerequisites): Binaryen's `wasm-as` on `PATH`, and code
that meets the [Native Image requirements](https://elide.help/docs/toolchain/jvm/native-image).

```pkl
amends "elide:project.pkl"
import "elide:Jvm.pkl" as jvm
import "elide:NativeImage.pkl" as nativeImage

name = "hello-edge"

artifacts {
  ["app-jar"] = new jvm.Jar {
    sources { "main" }
  }
  ["edge"] = new nativeImage.WebImage {
    from { "app-jar" }
    name = "hello"
    entrypoint = "Hello"
    backend = "wasm-lm"
    runtime = "node"
  }
}
```

```bash
elide build
node .dev/artifacts/native-image/hello.js
```

Without a manifest:

```bash
elide javac -- -d classes Hello.java
elide native-image -- --tool:wasm-lm -cp classes -o hello Hello
```

| Property | Edge value |
| --- | --- |
| `backend` | `"wasm-lm"`. |
| `runtime` | `"node"` for Node-compatible APIs; `"generic"` also detects browser APIs. |
| `autoRun` | `true` (default) runs `main` when `hello.js` loads. |

## Output and size

| File | Deploy | Hello-world size |
| --- | --- | --- |
| `hello.js` | Yes: the loader. | 42 KB |
| `hello.js.wasm` | Yes: the module. | 2.1 MB (660 KB gzipped) |
| `hello.js.wat` | No: text form, for inspection. | 38 MB |
| `hello.js.map` | Optional: emitted with `sourceMap = true`. | |

A linear-memory module is larger than the [WasmGC build](https://elide.help/docs/toolchain/web/wasm) of the same program, which uses the
host's garbage collector.

## Host requirements

| Requirement | Reason |
| --- | --- |
| WebAssembly exception handling with `exnref` | The module uses it. |
| Compiling WebAssembly from bytes at runtime | The loader reads `hello.js.wasm` and compiles it on start. |
| Node `fs` or `fetch` | The loader reads the module through one of them. |

| Host | Runs the bundle |
| --- | --- |
| Node.js 25+ | Yes: `node hello.js`. |
| Bun | Yes: `bun hello.js`. |
| Cloudflare Workers | No: Workers compile only modules bundled at deploy time and reject the loader's runtime compile with `Wasm code generation disallowed by embedder`. |
| WASI hosts (Fastly Compute, Wasmtime) | No: the module imports from its JavaScript loader, not WASI. |
