Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add emscripten support #4443

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from
Draft

Conversation

walkingeyerobot
Copy link

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: emscripten-core/emscripten#23493

I've also made a PR to wasm-pack: rustwasm/wasm-pack#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.

walkingeyerobot and others added 12 commits February 12, 2025 12:13
Merge the two generated .js into one library_bindgen.js.
Notably, to work with emscripten, the emitted js has explicit
dependencies listed for the imports.
Expand emscripten support to supporting JS imported closures.
Because the generated .js file when targeting emscripten in wasm-bindgen is meant to be
consumed by emscripten rather than a standalone executable, we need some
custom testing logic for emscripten.
Add the necessary emscripten test mode.
@google-yfyang google-yfyang force-pushed the main branch 2 times, most recently from e02edbe to 79c884a Compare March 4, 2025 20:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants