wasm-bindgen
wasm-bindgen copied to clipboard
add emscripten support
Adds --target emscripten option, which will output JS that Emscripten can consume and integrate into its own JS.
This is still a work-in-progress, but it's getting kind of beefy, so I thought it would be best to start review on this soon. There's still feature work to be done (i.e. I don't think futures work). My preference would be to submit this with only the current set of supporting features, mark --target emscripten as experimental, and then send smaller PRs to add more support.
Also adds a basic test. This test builds some rust code and links it with Emscripten, but the test runner invokes wasm-bindgen. It then tests to make sure the output looks reasonable. Normally, the wasm-bindgen cli tool is invoked by Emscripten at link time. Because cargo does not support binary dependencies, and because wasm-bindgen is effectively being used as a dependency of Emscripten, it's very difficult to do end-to-end testing in the wasm-bindgen repository. I'd like to add more comprehensive testing, but I think it's more appropriate to either Emscripten or to a new repository separate from wasm-bindgen and Emscripten that can depend on both of those repositories at HEAD.
It turns out wasm-bindgen also does not support Emscripten exceptions or PIC, so we've disabled both of those compiler options. This is mostly due to lack of features in the interpreter. Exception support is something I'd like to eventually add. PIC appears to be off by default for wasm32-unknown-unknown and on by default for wasm32-unknown-emscripten. PIC can be supported through changes to wasm-bindgen's interpreter, but that seemed a bit out of scope for this PR.
I've also made a corresponding PR to Emscripten: https://github.com/emscripten-core/emscripten/pull/23493
I've also made a PR to wasm-pack: https://github.com/rustwasm/wasm-pack/pull/1469. However, there has been no activity in wasm-pack by maintainers for ~4 months, and I suspect it's unlikely to get attention in the near future. The purpose of the wasm-pack PR is to provide a more straightforward workflow for Rust users already familiar with targeting Wasm.