Skip to content

Add WASM support: --wasm flag with Node.js and Deno runtimes#1

Open
lostflydev wants to merge 146 commits into
mainfrom
scala-wasm-support
Open

Add WASM support: --wasm flag with Node.js and Deno runtimes#1
lostflydev wants to merge 146 commits into
mainfrom
scala-wasm-support

Conversation

@lostflydev

Copy link
Copy Markdown
Owner

Implements scala-cli issue VirtusLab#3316: integrate WebAssembly with Scala CLI.

What's added

  • --wasm CLI flag and //> using wasm directive to enable WASM output
  • --wasm-runtime <runtime> option and //> using wasmRuntime directive Supported values: node (default), deno, wasmtime, wasmedge, wasmer
  • --deno-version, --wasmtime-version, --wasmer-version options and corresponding directives for pinning runtime versions

Runtime support

@lostflydev lostflydev force-pushed the scala-wasm-support branch 5 times, most recently from c6453eb to ddfadbc Compare March 9, 2026 05:51
Gedochao and others added 3 commits March 9, 2026 13:33
…VirtusLab#4173)

Bumps the npm-dependencies group in /website with 1 update: [@algolia/client-search](https://github.com/algolia/algoliasearch-client-javascript).


Updates `@algolia/client-search` from 5.49.1 to 5.49.2
- [Release notes](https://github.com/algolia/algoliasearch-client-javascript/releases)
- [Changelog](https://github.com/algolia/algoliasearch-client-javascript/blob/main/CHANGELOG.md)
- [Commits](algolia/algoliasearch-client-javascript@5.49.1...5.49.2)

---
updated-dependencies:
- dependency-name: "@algolia/client-search"
  dependency-version: 5.49.2
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: npm-dependencies
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps the github-actions group with 4 updates: [docker/login-action](https://github.com/docker/login-action), [docker/metadata-action](https://github.com/docker/metadata-action), [docker/setup-buildx-action](https://github.com/docker/setup-buildx-action) and [docker/build-push-action](https://github.com/docker/build-push-action).


Updates `docker/login-action` from 3 to 4
- [Release notes](https://github.com/docker/login-action/releases)
- [Commits](docker/login-action@v3...v4)

Updates `docker/metadata-action` from 5 to 6
- [Release notes](https://github.com/docker/metadata-action/releases)
- [Commits](docker/metadata-action@v5...v6)

Updates `docker/setup-buildx-action` from 3 to 4
- [Release notes](https://github.com/docker/setup-buildx-action/releases)
- [Commits](docker/setup-buildx-action@v3...v4)

Updates `docker/build-push-action` from 6 to 7
- [Release notes](https://github.com/docker/build-push-action/releases)
- [Commits](docker/build-push-action@v6...v7)

---
updated-dependencies:
- dependency-name: docker/login-action
  dependency-version: '4'
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: github-actions
- dependency-name: docker/metadata-action
  dependency-version: '6'
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: github-actions
- dependency-name: docker/setup-buildx-action
  dependency-version: '4'
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: github-actions
- dependency-name: docker/build-push-action
  dependency-version: '7'
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: github-actions
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Gedochao and others added 16 commits March 12, 2026 11:42
Bumps [undici](https://github.com/nodejs/undici) from 7.18.2 to 7.24.1.
- [Release notes](https://github.com/nodejs/undici/releases)
- [Commits](nodejs/undici@v7.18.2...v7.24.1)

---
updated-dependencies:
- dependency-name: undici
  dependency-version: 7.24.1
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps the github-actions group with 1 update: [webfactory/ssh-agent](https://github.com/webfactory/ssh-agent).


Updates `webfactory/ssh-agent` from 0.9.1 to 0.10.0
- [Release notes](https://github.com/webfactory/ssh-agent/releases)
- [Changelog](https://github.com/webfactory/ssh-agent/blob/master/CHANGELOG.md)
- [Commits](webfactory/ssh-agent@a6f90b1...e838748)

---
updated-dependencies:
- dependency-name: webfactory/ssh-agent
  dependency-version: 0.10.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: github-actions
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps the npm-dependencies group in /website with 1 update: [sass](https://github.com/sass/dart-sass).


Updates `sass` from 1.97.3 to 1.98.0
- [Release notes](https://github.com/sass/dart-sass/releases)
- [Changelog](https://github.com/sass/dart-sass/blob/main/CHANGELOG.md)
- [Commits](sass/dart-sass@1.97.3...1.98.0)

---
updated-dependencies:
- dependency-name: sass
  dependency-version: 1.98.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: npm-dependencies
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Gedochao and others added 26 commits June 1, 2026 19:42
* Bump `jsoup` to 1.22.2 (was 1.22.1)

* Bump `jsoniter-scala` to 2.38.14 (was 2.38.8)

* Bump `scalaMeta` to 4.17.0 (was 4.15.2)

* Bump `asm` to 9.10.1 (was 9.9.1)

* Bump `javaSemanticdb` to 0.12.3 (was 0.10.0)

* Bump `scalafix` to 0.14.6 (was 0.14.5)

* Bump `guava` to 33.6.0-jre (was 33.5.0-jre)

* Bump `jgit` to 7.6.0.202603022253-r (was 7.5.0.202512021534-r)

* Bump `scalaPackager` to 0.2.2 (was 0.2.1)

* Bump `metaconfig-typesafe-config` to 0.18.6 (was 0.18.2)

* Bump `scalajs-env-nodejs` to 1.6.0 (was 1.5.0)

* Bump `pprint` to 0.9.6 (was 0.9.5)

* Bump `sbt` to 1.12.5 (was 1.12.4)

* Bump `mavenScalaCompilerPlugin` to 4.9.10 (was 4.9.1)

* Bump `munit` to 1.3.0 (was 1.2.2)
…#4300)

Bumps the npm-dependencies group in /website with 5 updates:

| Package | From | To |
| --- | --- | --- |
| [@algolia/client-search](https://github.com/algolia/algoliasearch-client-javascript) | `5.52.1` | `5.53.0` |
| [@easyops-cn/docusaurus-search-local](https://github.com/easyops-cn/docusaurus-search-local/tree/HEAD/packages/docusaurus-search-local) | `0.55.1` | `0.55.2` |
| [react](https://github.com/facebook/react/tree/HEAD/packages/react) | `19.2.6` | `19.2.7` |
| [@types/react](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/react) | `19.2.15` | `19.2.16` |
| [react-dom](https://github.com/facebook/react/tree/HEAD/packages/react-dom) | `19.2.6` | `19.2.7` |


Updates `@algolia/client-search` from 5.52.1 to 5.53.0
- [Release notes](https://github.com/algolia/algoliasearch-client-javascript/releases)
- [Changelog](https://github.com/algolia/algoliasearch-client-javascript/blob/main/CHANGELOG.md)
- [Commits](algolia/algoliasearch-client-javascript@5.52.1...5.53.0)

Updates `@easyops-cn/docusaurus-search-local` from 0.55.1 to 0.55.2
- [Release notes](https://github.com/easyops-cn/docusaurus-search-local/releases)
- [Commits](https://github.com/easyops-cn/docusaurus-search-local/commits/v0.55.2/packages/docusaurus-search-local)

Updates `react` from 19.2.6 to 19.2.7
- [Release notes](https://github.com/facebook/react/releases)
- [Changelog](https://github.com/facebook/react/blob/main/CHANGELOG.md)
- [Commits](https://github.com/facebook/react/commits/v19.2.7/packages/react)

Updates `@types/react` from 19.2.15 to 19.2.16
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/react)

Updates `react-dom` from 19.2.6 to 19.2.7
- [Release notes](https://github.com/facebook/react/releases)
- [Changelog](https://github.com/facebook/react/blob/main/CHANGELOG.md)
- [Commits](https://github.com/facebook/react/commits/v19.2.7/packages/react-dom)

---
updated-dependencies:
- dependency-name: "@algolia/client-search"
  dependency-version: 5.53.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: npm-dependencies
- dependency-name: "@easyops-cn/docusaurus-search-local"
  dependency-version: 0.55.2
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: npm-dependencies
- dependency-name: react
  dependency-version: 19.2.7
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: npm-dependencies
- dependency-name: "@types/react"
  dependency-version: 19.2.16
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: npm-dependencies
- dependency-name: react-dom
  dependency-version: 19.2.7
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: npm-dependencies
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Implements scala-cli issue VirtusLab#3316: integrate WebAssembly with Scala CLI.

- `--wasm` CLI flag and `//> using wasm` directive to enable WASM output
- `--wasm-runtime <runtime>` option and `//> using wasmRuntime` directive
  Supported values: node (default), deno
- `--deno-version`, `--wasmtime-version`, `--wasmer-version` options
  and corresponding directives for pinning runtime versions

- **Node.js** (default): runs Scala.js WASM output with
  `--experimental-wasm-exnref` flag, requires Node.js >= 22
- **Deno**: runs Scala.js WASM output
…imes

- Move --wasm flag to dedicated Wasm help group with --help-wasm option
- Simplify wasmOptions parsing with fold/toRight pattern
- Add runtime validation with UnrecognizedWasmRuntimeError in directives
- Auto-enable WASM when wasmRuntime directive is set
- Update reference documentation

Code style: simplify denoNeedsWasmFlag, explicit runtime match cases, clean type annotation, scalfmt
…smRuntime bun)

  - Add BunNotFoundError with install hint
  - Add integration test for Bun (conditional on bun being on PATH)
  - Add actions/setup-node@v6 node-version:24 to all Linux integration test
    jobs: the default Node.js on ubuntu-24.04 runners is too old for Scala.js
    WASM GC (which requires Node.js >= 22). Matches docs-tests job which
    already pins node-version: 24
Node 24 still ships V8 12.x where wasm-exnref is gated behind --experimental-wasm-exnref; the flag only flips to default in V8 13.x (Node 25+). The previous nodeMajorVersion < 24 guard therefore left Node 24 (the version pinned in CI) without the flag, which made any Scala.js WASM code using exception bytecodes, runtime throws, JS interop or Scala 3 @main fail at runtime. Same reasoning applies to Deno (Deno 2.x = V8 12.x).

Until V8 13.x is the default everywhere, just always set the flag, there is no any overhead
…efactor into ScalaJsOptions

- Replace "WASM" with "Wasm" per WebAssembly spec: contraction, not acronym
- Fix nodeNeedsWasmFlag to be version-aware: only pass --experimental-wasm-exnref
  for Node < 25 (V8 12.x); Node 25+ has it enabled by default, Node 26+ may remove it
- Remove Node/Bun pre-flight version checks; let runtime fail naturally on old versions
- Remove else-if-emitWasm branch (not needed)
- Refactor WasmOptions into ScalaJsOptions: jsEmitWasm and wasmRuntime are now fields
  of ScalaJsOptions at both build and CLI layers; CLI flags are now --js-emit-wasm and
  --js-wasm-runtime under the Wasm help group; WasmOptions classes removed
- linkerConfig() now forces ESModule when jsEmitWasm=true
- Update all integration test CLI flags to --js-emit-wasm / --js-wasm-runtime
- Log when --experimental-wasm-exnref is injected in runJs (Node.js < 25)
- Log when Wasm mode enables ES module output in Run.scala
- Improve comment in Wasm.scala directive to reference AmbiguousPlatformError
  for --wasm + --platform native conflict detection
- runDeno: append --experimental-wasm-exnref to existing DENO_V8_FLAGS
  instead of silently replacing user-defined flags; log when flag is set
- ScalaJsOptions.linkerConfig: warn when Wasm overrides user-specified
  --js-module-kind (forced to ESModule by Wasm backend)
Lost during Run.scala restructure for Wasm: restores the original
case _: SbtFile => "" and case null => "" branches so SbtFile inputs
are properly filtered from scala.sources JVM property.
@lostflydev lostflydev force-pushed the scala-wasm-support branch 2 times, most recently from c75c0c8 to d494c98 Compare June 6, 2026 19:11
…e to --js-runtime

- Remove the exnref capability probe and all --experimental-wasm-exnref /
  DENO_V8_FLAGS injection (tanishiking). scala-cli no longer manages V8
  flags; on older runtimes that still gate exnref, users pass it via
  NODE_OPTIONS / DENO_V8_FLAGS. CI runtimes (node 24, deno 2.x, bun) need none.
- Stop forcing ESModule for Wasm; fail fast with WasmModuleKindError when
  --js-module-kind isn't es, instead of silently overriding it. Keeps config
  consistent with Scala.js and future module kinds.
- Rename --js-wasm-runtime -> --js-runtime and //> using wasmRuntime ->
  //> using jsRuntime; selecting a runtime no longer auto-enables Wasm.
- Update integration tests (explicit --js-module-kind es, renamed flag,
  fail-fast test) and the Wasm guide; regenerate reference docs.
@lostflydev lostflydev force-pushed the scala-wasm-support branch from d494c98 to 6c6eb57 Compare June 7, 2026 14:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants