-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
Motivation
Exported mutable globals were not a thing in MVP WebAssembly, but are now part of the spec.
Since version 0.2.66
, wasm-bindgen
has generated WebAssembly that uses mutable globals, but not all WebAssembly engines in the wild support the mutable globals part of the spec:
e.g. iOS 12
by virtue of shipping WebKit with OS updates (so every iPhone <= iPhone 6), Firefox ESR 60,
and Node.js 10
all don't support mutable globals. They run binaries made with wasm-bindgen
<= 0.2.65
without mutable globals perfectly fine.
This means that you'll never be able to run WebAssembly binaries compiled with recent and future versions of wasm-bindgen
on those platforms.
My company would like to support the iPhone 6, and I know that we're not the only ones using Rust that would like to run WebAssembly binaries on engines without the mutable globals feature, and thus being forced to pin to wasm-bindgen
version 0.2.65
:
zotero/citeproc-rs@e0a3bdd
cloudflare/rustwasm-worker-template@fe5ce45
chitalian/wasm-pack-template@46f988e
zakhenry/mesh-to-svg@9597aec
Emurgo/cardano-serialization-lib@02432d5
p2panda/p2panda@43d81b3
Proposed Solution
Add a flag --disable-mutable-globals
to explicitly disable emitting mutable globals. If wasm-bindgen
needs to export a variable in a way that's globally writable, wasm-bindgen
should emit a setter instead.
At least one other project outside the Rust ecosystem implemented a similar workaround (emitting setters instead of mutable globals) to maintain backwards compatibility with older implementations of the WebAssembly spec:
AssemblyScript/assemblyscript@e03b71d
Alternatives
The only alternative to implementing this feature, if we want to keep supporting the aforementioned WebAssembly engines, seems to be pinning wasm-bindgen
's version to =0.2.65
. This is really not great, since we're then stuck on that version indefinitely.