-
Notifications
You must be signed in to change notification settings - Fork 59
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
Clarify / define Node.js story #250
Comments
I think probably the biggest reason is that on the server you can just use native Rust, no need for wasm at all. And native Rust is excellent on the server: it has great performance, features, and convenience. Trying to use Node is clunky and slow by comparison. With native Rust you get to use the same types and algorithms on both the server and client (using serde to send data back and forth). So unlike the situation with JavaScript, you don't really gain anything with Node. To be clear, I think we should support Node, I just think the above reasons are why it hasn't been as big of a priority as the browser. Of course I can't speak for the entire RustWasm group, but that's just how I see it.
This a lot harder than it seems at first glance. The With Node, we would have to write bindings by hand. That's a lot of work! And maintaining the bindings (to keep up to date with newer Node versions) is also a lot of work. There's absolutely nothing at all stopping anybody from creating a
That sounds like a good idea to me! Could you fill an issue on the wasm-pack repo? |
I don't think this is necessarily true. Node.js TypeScript definitions are pretty precise, and there is already
Sure, but first and foremost I was hoping to see an official positions and support and not just do it on my own (I already lack behind in tracking issues in OSS projects I'm supposed to maintain).
Sure. |
This is all true but there are cases where you want to migrate slowly, and using WASM for Rust + JS is one of the nicest options, as well as there are cases where user is limited to just Node.js by your provider, and even (my case) where you want to use a complex library that exists only on npm but still write the rest of your code in Rust. |
As far as officially-documented positions go, we have: https://github.com/rustwasm/team#3-join-the-rust-and-webassembly-working-group
The focus is on the Web, but we are happy to help elsewhere when we can and it is easy enough to do so. That roughly translates to supporting (but not focusing on) any environment that involves Rust-generated wasm talking to JS, which is what our toolchain can easily support. That includes node! It would be cool to have a Agreed that |
I missed your issue @RReverser, sorry. I opened #204 a lot ago, the bundler team happen to own https://github.com/wasm-tool/node-loader. The nodejs integration seems to be quite related to the bundler one. |
@xtuc Yes, thanks, I saw that issue and that's what I referred to in
in the description (and that's also the reason I sent these PRs to node-loader making it possible to run WASM directly at around same time :) ). As I clarified later though, I'm interested in other parts of it though, which could be already possible even without (experimental) ESM support in Node.js like running WASM via wasm-pack / wasm-bindgen and exposing native APIs. |
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 isweb-sys
with web interfaces for browsers, but I would hope to see something likenode-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 atarget.wasm32-unknown-emscripten.runner
system-wide once and thencargo run
and friends will just work, but running WASM produced withwasm32-unknown-unknown
is currently much more involved and requires:process.argv
to read command-line arguments.wasm_bindgen(start)
and providing conditionally compiled wrappers to use eitherargv
bindings orstd::env::args()
.cargo
(becausewasm-pack
expects onlycdylib
as 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.runner
and would automate all or most of these things above.The text was updated successfully, but these errors were encountered: