tanishiking / scala-wasm

Experimental WasmGC backend for Scala.js | merging into the upstream Scala.js repo https://github.com/scala-js/scala-js/pull/4988
40 stars 3 forks source link
scala scalajs wasmgc webassembly

Experimental Scala.js linker backend for WasmGC

CI

Prerequisites

This project requires Node.js >= 22 to get enough support of WasmGC.

If you are using NVM, you can instal Node.js 22 as follows:

# Install Node.js v22
$ nvm install 22
# Switch to Node.js 22
$ nvm use 22

Setup

Before doing anything else, run npm install.

Run the sample

In sample/src/main/scala/Sample.scala you can find a sandbox to play around.

You can build and run it like any other Scala.js project from sbt:

You may want to look at the output in sample/target/scala-2.12/sample-fastopt/ to convince yourself that it was compiled to WebAssembly.

In that directory, you will also find a main.wat file, which is not used for execution. It contains the WebAsembly Text Format representation of main.wasm, for exploratory and debugging purposes. This is only true by default for the sample.

:warning: If you modify the linker code, you need to reload and sample/clean for your changes to take effect on the sample.

You can also use the run.mjs script to play with @JSExportTopLevel exports.

If you encounter the Invalid opcode 0x1f error with Node.js, you need to use a Node.js >= 22.

Unit test suite

Run the unit test suite with tests/test.

By default, .wat files are not generated, as they are quite big (several hundreds of KB for most of the tests). You can enable them by adding withPrettyPrint(true) to the linker configuration in tests/src/test/scala/tests/CoreTests.scala.

Scala.js integration test suite

Run the entire Scala.js test suite, linked with the WebAssembly backend, with:

> scalajs-test-suite/test

When you modify the linker, you need to reload and scalajs-test-suite/clean for your changes to take effect. Since recompiling the test suite from scratch every time is slow, you can replace the clean by manually removing only the linker output with:

$ rm -r scalajs-test-suite/target/scala-2.12/scalajs-test-suite-test-fastopt/

By default, .wat files are not generated for the Scala.js test suite, as they are very big (they exceed 100 MB). It is usually easier to minimize an issue in sample/test, but if you really want the big .wat file for the Scala.js test suite, you can enable it with

> set `scalajs-test-suite`/scalaJSLinkerConfig ~= { _.withPrettyPrint(true) }

Debugging tools