mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-03-16 10:10:52 +00:00
This commit adds support to `wasm-bindgen` to be a drop-in polyfill for the WebIDL bindings proposal. Lots of internal refactoring has happened previously to `wasm-bindgen` to make this possible, so this actually ends up being a very small PR! Most of `wasm-bindgen` is geared towards Rust-specific types and Rust-specific support, but with the advent of WebIDL bindings this is a standard way for a WebAssembly module to communicate its intended interface in terms of higher level types. This PR allows `wasm-bindgen` to be a polyfill for any WebAssembly module that has a valid WebIDL bindings section, regardless of its producer. A standard WebIDL bindings section is recognized in any input wasm module and that is slurped up into wasm-bindgen's own internal data structures to get processed in the same way that all Rust imports/exports are already processed. The workflow for `wasm-bindgen` looks the same way that it does in Rust today. You'd execute `wasm-bindgen path/to/foo.wasm --out-dir .` which would output a new wasm file and a JS shim with the desired interface, and the new wasm file would be suitable for loading in MVP implementations of WebAssembly. Note that this isn't super thoroughly tested, so there's likely still some lingering assumptions that `wasm-bindgen` makes (such as `__wbindgen_malloc` and others) which will need to be patched in the future, but the intention of this commit is to start us down a road of becoming a drop-in polyfill for WebIDL bindings, regardless of the source. Also note that there's not actually any producer (AFAIK) of a WebIDL bindings custom section, so it'd be that much harder to write tests to do so!