|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: Announcing Scala.js 1.17.0 |
| 4 | +category: news |
| 5 | +tags: [releases] |
| 6 | +permalink: /news/2024/09/28/announcing-scalajs-1.17.0/ |
| 7 | +--- |
| 8 | + |
| 9 | + |
| 10 | +We are excited to announce the release of Scala.js 1.17.0! |
| 11 | + |
| 12 | +This release comes with a brand new, shiny, experimental WebAssembly backend. |
| 13 | +You can now, under certain conditions, take your existing Scala.js application and compile it to WebAssembly instead. |
| 14 | + |
| 15 | +There were also some bug fixes. |
| 16 | +Despite the abnormally long release cycle (v1.16.0 was released 6 months ago), the only external bug report came in 3 weeks ago. |
| 17 | +As far as we can tell, nobody was blocked waiting for a bugfix for this long. |
| 18 | + |
| 19 | +Read on for more details. |
| 20 | + |
| 21 | +<!--more--> |
| 22 | + |
| 23 | +## Getting started |
| 24 | + |
| 25 | +If you are new to Scala.js, head over to [the tutorial]({{ BASE_PATH }}/tutorial/). |
| 26 | + |
| 27 | +If you need help with anything related to Scala.js, you may find our community [in `#scala-js` on Discord](https://discord.com/invite/scala) and [on Stack Overflow](https://stackoverflow.com/questions/tagged/scala.js). |
| 28 | + |
| 29 | +Bug reports can be filed [on GitHub](https://github.com/scala-js/scala-js/issues). |
| 30 | + |
| 31 | +## Release notes |
| 32 | + |
| 33 | +If upgrading from Scala.js 0.6.x, make sure to read [the release notes of Scala.js 1.0.0]({{ BASE_PATH }}/news/2020/02/25/announcing-scalajs-1.0.0/) first, as they contain a host of important information, including breaking changes. |
| 34 | + |
| 35 | +This is a **minor** release: |
| 36 | + |
| 37 | +* It is backward binary compatible with all earlier versions in the 1.x series: libraries compiled with 1.0.x through 1.16.x can be used with 1.17.0 without change. |
| 38 | +* It is *not* forward binary compatible with 1.16.x: libraries compiled with 1.17.0 cannot be used with 1.16.x or earlier. |
| 39 | +* It is *not* entirely backward source compatible: it is not guaranteed that a codebase will compile *as is* when upgrading from 1.16.x (in particular in the presence of `-Xfatal-warnings`). |
| 40 | + |
| 41 | +As a reminder, libraries compiled with 0.6.x cannot be used with Scala.js 1.x; they must be republished with 1.x first. |
| 42 | + |
| 43 | +## Enhancements with compatibility concerns |
| 44 | + |
| 45 | +### Changes to the IR and linker APIs |
| 46 | + |
| 47 | +For tooling authors who directly manipulate the IR and linker APIs, there have been some breaking changes in that area. |
| 48 | +This is in line with our version policy for the linker APIs. |
| 49 | + |
| 50 | +The most likely changes you may hit are: |
| 51 | + |
| 52 | +* The reference types in the IR, such as `ClassType` and `ArrayType`, now have a `nullable: Boolean` flag. |
| 53 | + There is also a new type `AnyNotNullType`. |
| 54 | +* The `NewArray` node does not accept multiple dimensions anymore. |
| 55 | + If you want to emit a multi-dimensional array creation, emit a call to `java.lang.reflect.Array.newInstance` instead. |
| 56 | + |
| 57 | +## Enhancements |
| 58 | + |
| 59 | +### Experimental WebAssembly backend |
| 60 | + |
| 61 | +Starting with this release, Scala.js ships with an *experimental* WebAssembly backend. |
| 62 | +Under some conditions, you may use it as a drop-in replacement for the usual JavaScript backend. |
| 63 | + |
| 64 | +#### Minimal setup |
| 65 | + |
| 66 | +You can set it up as follows: |
| 67 | + |
| 68 | +{% highlight scala %} |
| 69 | +// Emit ES modules with the Wasm backend |
| 70 | +scalaJSLinkerConfig := { |
| 71 | + scalaJSLinkerConfig.value |
| 72 | + .withExperimentalUseWebAssembly(true) // use the Wasm backend |
| 73 | + .withModuleKind(ModuleKind.ESModule) // required by the Wasm backend |
| 74 | +}, |
| 75 | + |
| 76 | +// Configure Node.js (at least v22) to support the required Wasm features |
| 77 | +jsEnv := { |
| 78 | + val config = NodeJSEnv.Config() |
| 79 | + .withArgs(List( |
| 80 | + "--experimental-wasm-exnref", // required |
| 81 | + "--experimental-wasm-imported-strings", // optional (good for performance) |
| 82 | + "--turboshaft-wasm", // optional, but significantly increases stability |
| 83 | + )) |
| 84 | + new NodeJSEnv(config) |
| 85 | +}, |
| 86 | +{% endhighlight %} |
| 87 | + |
| 88 | +Make sure `node -v` reports at least v22.0.0. |
| 89 | +If not, install a newer version. |
| 90 | + |
| 91 | +You are then set up to `run` and `test` your codebase with the WebAssembly backend from sbt. |
| 92 | + |
| 93 | +#### Limitations |
| 94 | + |
| 95 | +Note that the WebAssembly backend *silently ignores* all the `@JSExport` and `@JSExportAll` annotations. |
| 96 | +It is never possible to call methods of Scala classes from JavaScript, which includes `toString()`, even through string concatenation. |
| 97 | +JavaScript code may still call all public members of JavaScript classes (classes that inherit from `js.Any`). |
| 98 | +Moreover, `@JSExportTopLevel` is supported, as well as all the other `@JS...` annotations. |
| 99 | + |
| 100 | +The WebAssembly backend does not yet support emitting multiple modules. |
| 101 | +The module split style must be set to `ModuleSplitStyle.FewestModules` (which is the default). |
| 102 | +Moreover, the codebase must not contain any feature that require emitting multiple modules: `@JSExportToplevel` annotations with several module names, or `js.dynamicImport`. |
| 103 | +We expect to lift that limitation in the future. |
| 104 | + |
| 105 | +Other than that, we expect the WebAssembly backend to support all Scala.js semantics. |
| 106 | +Please report any issues you may find. |
| 107 | + |
| 108 | +Stack traces are currently suboptimal. |
| 109 | + |
| 110 | +#### Use in browsers |
| 111 | + |
| 112 | +If you want to use it in browsers, you will need: |
| 113 | + |
| 114 | +* For Firefox: in `about:config`, enable `javascript.options.wasm_exnref`. |
| 115 | + Also make sure to *disable* `javascript.options.wasm_js_string_builtins`: Firefox has two issues with it that break Scala.js ([1919901](https://bugzilla.mozilla.org/show_bug.cgi?id=1919901) and [1920337](https://bugzilla.mozilla.org/show_bug.cgi?id=1920337)) |
| 116 | +* For Chrome: in `chrome://flags/`, enable ["Experimental WebAssembly"](chrome://flags/#enable-experimental-webassembly-features). |
| 117 | + |
| 118 | +#### More information |
| 119 | + |
| 120 | +Read more detailed information about [the WebAssembly backend in the docs]({{ BASE_PATH }}/doc/project/webassembly.html). |
| 121 | + |
| 122 | +## Miscellaneous |
| 123 | + |
| 124 | +### New JDK APIs |
| 125 | + |
| 126 | +This release adds support for the following JDK methods: |
| 127 | + |
| 128 | +* In `java.lang.Character`: `codePointAt`, `codePointBefore`, `codePointCount` and `offsetByCodePoints` |
| 129 | +* In `java.util.concurrent.ConcurrentHashMap`: `forEach`, `forEachKey` and `forEachValue` |
| 130 | + |
| 131 | +### Unicode version |
| 132 | + |
| 133 | +The Unicode database used by the methods of `java.lang.Character` was updated to Unicode v15.0. |
| 134 | + |
| 135 | +## Bug fixes |
| 136 | + |
| 137 | +Among others, the following bugs have been fixed in 1.17.0: |
| 138 | + |
| 139 | +* [#5026](https://github.com/scala-js/scala-js/issues/5026) Output .js file names can be too long on Windows, esp. for non-ASCII class names. |
| 140 | +* [#5044](https://github.com/scala-js/scala-js/issues/5044) `jl.reflect.Array.newInstance()` does not throw the `IllegalArgumentException`s it is supposed to. |
| 141 | + |
| 142 | +You can find the full list [on GitHub](https://github.com/scala-js/scala-js/issues?q=is%3Aissue+milestone%3Av1.17.0+is%3Aclosed). |
0 commit comments