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

One generated wasm to rule them all #2265

Open
jordy25519 opened this issue Jul 30, 2020 · 2 comments
Open

One generated wasm to rule them all #2265

jordy25519 opened this issue Jul 30, 2020 · 2 comments

Comments

@jordy25519
Copy link

jordy25519 commented Jul 30, 2020

Motivation

Create a single, isomorphic JS package using wasm-bindgen and tooling.

Proposed Solution

Generate the wasm import table in a consistent or configurable way so that the wasm binary may be used by any JS target runtime.

Maybe there is a way to provide a core wasm file with the main logic and generate only "glue" wasm files for each target which provide the right import shims.

Alternatives

It is possible to do this using wasm-pack or manual build scripts and other glue code the downside of this, in my understanding, is it requires multiple wasm binaries, one for each target, which unnecessarily bloats the final package size.

Additional Context

Idea came from the observation that the generated wasm for --target=node and --target=browser produce
the same binary apart from imports table (converted to wat):
Screen Shot 2020-07-31 at 10 14 11 AM

I don't know dark js arts so maybe there's any easier way to do this from js glue code only but I could not find / comprehend that during my research into this.

@alexcrichton
Copy link
Contributor

This is theoretically possible but not a lot of effort has gone into this. There's various subtle interactions with how the target and the generated JS affects the resulting wasm module, for example precisely what intrinsics are exported and not. Currently there's not a pass in wasm-bindgen that attempts to export everything it would need for all targets, so support would need to be added for that.

@torfmaster
Copy link

FYI: I created a draft PR here which might touch this issue: #4065

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants