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
Before doing anything else, run npm install
.
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:
sample/fastLinkJS
compiles and links the project with the WebAssembly backend.sample/run
runs the sample linked to WebAssembly withnode
.
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
.
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.
- Run from the command line with
node --experimental-wasm-exnref run.mjs
. - Run from the command line with
DENO_V8_FLAGS=--experimental-wasm-exnref deno run --allow-read run.mjs
. - Run from the browser by starting an HTTP server (e.g.,
python -m http.server
) and navigate totestrun.html
.
If you encounter the Invalid opcode 0x1f
error with Node.js, you need to use a Node.js >= 22.
Run the unit test suite with tests/test
.
tests/test
will- Link every test suite from
testSuite
with the WebAssembly backend - Run the produced WebAssembly module and check for any uncaught error
- Link every test suite from
- Each Scala program in
test-suite
should have adef main(): Unit
function. The test passes if the function successfully executes without throwing. - When you add a test,
- Add a file under
test-suite
- Add a test case to
tests/src/test/scala/tests/TestSuites.scala
- Add a file under
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
.
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) }
- The WasmGC reference interpreter can be used to validate and convert between the binary and text form: