Apologies if this was discussed before, but I haven't found any relevant references so far (aside from ESM integration) and felt it's worth discussing publicly.
While I like wasm-pack, wasm-bindgen and companion bindings libraries, I feel that they focus almost solely on the browser side of things.
At the same time, Node.js story doesn't seem to be currently covered very well (neither in prototypes nor plans), despite it being a popular and an interesting platform for running all sorts of mixed JS+Rust executables without resorting to native modules.
First issue is that there exists js-sys for generic JS runtime bindings and there is web-sys with web interfaces for browsers, but I would hope to see something like node-sys for predefined bindings for Node.js built-in modules and objects - process, fs, http just to name a few that would be useful from Rust side.
Second issue is that on the actual execution side there is currently no easy way to actually run them from command-like.
With Emscripten you can simply preconfigure node as a target.wasm32-unknown-emscripten.runner system-wide once and then cargo run and friends will just work, but running WASM produced with wasm32-unknown-unknown is currently much more involved and requires:
- Manually defining required bindings to e.g.
process.argv to read command-line arguments.
- Adding
wasm_bindgen(start) and providing conditionally compiled wrappers to use either argv bindings or std::env::args().
- Compiling WASM manually using
cargo (because wasm-pack expects only cdylib as a crate type).
- Finding the produced filename (it might be easy for binaries, but examples and such also include hashes so you need to look this up manually).
- Running
wasm-bindgen --nodejs ... on the result.
- Finally, running the result.
- On every iteration, repeat from step 3.
For this one, I would hope to see something like wasm-pack run ... that could be used as a target.wasm32-unknown-unknown.runner and would automate all or most of these things above.
Apologies if this was discussed before, but I haven't found any relevant references so far (aside from ESM integration) and felt it's worth discussing publicly.
While I like wasm-pack, wasm-bindgen and companion bindings libraries, I feel that they focus almost solely on the browser side of things.
At the same time, Node.js story doesn't seem to be currently covered very well (neither in prototypes nor plans), despite it being a popular and an interesting platform for running all sorts of mixed JS+Rust executables without resorting to native modules.
First issue is that there exists
js-sysfor generic JS runtime bindings and there isweb-syswith web interfaces for browsers, but I would hope to see something likenode-sysfor predefined bindings for Node.js built-in modules and objects -process,fs,httpjust to name a few that would be useful from Rust side.Second issue is that on the actual execution side there is currently no easy way to actually run them from command-like.
With Emscripten you can simply preconfigure
nodeas atarget.wasm32-unknown-emscripten.runnersystem-wide once and thencargo runand friends will just work, but running WASM produced withwasm32-unknown-unknownis currently much more involved and requires:process.argvto read command-line arguments.wasm_bindgen(start)and providing conditionally compiled wrappers to use eitherargvbindings orstd::env::args().cargo(becausewasm-packexpects onlycdylibas a crate type).wasm-bindgen --nodejs ...on the result.For this one, I would hope to see something like
wasm-pack run ...that could be used as atarget.wasm32-unknown-unknown.runnerand would automate all or most of these things above.