Right now all the helper functions are generated inline in the JS that wasm-bindgen generates, but this can be a problem if you have multiple wasm-bindgen-generated wasm files throughout your dependency graph in a larger JS application. Each wasm-bindgen-generated project would duplicate the shims (that probably look the same) and so there's not as much code sharing happening, bummer!
It'd be pretty slick if all the helper functions were located on npm already in a package that wasm-bindgen generates imports to. That way all the wasm-bindgen-generated projects would import the same glue and it'd make everything smaller.
I think if this were implemented the JS file that we generate is basically then just the bare minimum to wrap the wasm imports/exports of the Rust/C code, and it'd make it a bit smaller!
cc @xtuc
This also is likely to have ramifications on https://github.com/rustwasm/wasm-bindgen/issues/42 and https://github.com/rustwasm/wasm-bindgen/issues/18, generating #[wasm_bindgen] annotations from WebIDL and Typescript. The JS shims for imported functions are gonna look the same regardless of what project you're working in and regardless of what language you're working in, so ideally if two projects import console.log then they're both wired up to the same JS shim.
Awesome. I think I can take this one 馃槉
Ok! One tricky part I think is how this interacts with the no modules mode and how the wasm-bindgen output is not as usable by default, and I'm not sure how to best tackle those issues
Also it has some other advantages:
Note that this would only work with Rollup and Webpack (currently).
I mentioned during the meeting that it _could_ make sense to compile Rust's libstd or libc to wasm and just include IO from JS. Since the bundlers consideres wasm just like JS module the approach here will still be applicable (but not tree-shakeable currently (i'm also working on it)).
This solution avoids porting the libs to JavaScript, which I believe has many limitations (pthread? i64?).
Related to this: would be great to have a --modules-but-not-wasm-as-modules mode :) that would
__exports.my_cool_function) in an ES Moduleimport '*.wasm'function init(wasm_path) from the no-module mode in the moduleI'm gonna close this for now because the shim functions are still in so much churn I'm not sure if it's feasible to extract them to a helper package at this time. Additionally I think it'll be quite some time before this causes bloat in applications, so we can hopefully cross the bridge when we get there!
Most helpful comment
This also is likely to have ramifications on https://github.com/rustwasm/wasm-bindgen/issues/42 and https://github.com/rustwasm/wasm-bindgen/issues/18, generating
#[wasm_bindgen]annotations from WebIDL and Typescript. The JS shims for imported functions are gonna look the same regardless of what project you're working in and regardless of what language you're working in, so ideally if two projects importconsole.logthen they're both wired up to the same JS shim.