Description
Motivation
Right now, all crates must have crate-type = ["cdylib"]
. This causes some issues:
-
Even though you're creating an application, you need to use
src/lib.rs
(which goes against Rust idioms). -
You need to use this...
#[wasm_bindgen(start)] pub fn main_js() {}
...rather than this:
fn main() {}
-
You can't (easily) have multiple binaries, since you can only have one lib per crate.
So that means you need to create multiple crates, link them together with a workspace, then set up a build script to call wasm-pack multiple times (since it can only compile one crate at a time).
This is a pretty big deal: you might want to develop both the client and server in the same crate, but right now that's quite clunky.
Let's compare that with the standard Rust approach, which is to simply make multiple
src/bin/
subfolders.
Proposed Solution
Both wasm-bindgen and wasm-pack should have native support for binaries. You should be able to create a src/main.rs
file, slap a fn main() {}
into it, and have it Just Work(tm).
Similarly, you should be able to create multiple src/bin/
subfolders, and they should also Just Work(tm).
In other words, the user experience should be exactly the same as creating a non-wasm Rust binary.
That means wasm-bindgen and wasm-pack will need to compile multiple binaries at the same time and output them all together into the output folder.
Additional Context
There might be a bit of size bloat caused by using bin crates rather than lib crates. We should investigate what we can do to reduce that.