[GH-ISSUE #530] [Question] Wasm / Node.js support #338

Closed
opened 2026-02-27 19:30:05 +03:00 by kerem · 2 comments
Owner

Originally created by @codetheweb on GitHub (Oct 11, 2020).
Original GitHub issue: https://github.com/librespot-org/librespot/issues/530

I'm new to Rust, and I was wondering how hard it would be to compile this into WebAssembly for usage with Node.js / browsers. I tried briefly using wasm-pack build (after adding crate-type = ["cdylib"] to Cargo.toml) and it just spit out a bunch of errors. I'm not experience enough to know whether this is relatively easy with a little bit more configuration or if it would require rewriting code.

Any feedback / help is appreciated.

Originally created by @codetheweb on GitHub (Oct 11, 2020). Original GitHub issue: https://github.com/librespot-org/librespot/issues/530 I'm new to Rust, and I was wondering how hard it would be to compile this into WebAssembly for usage with Node.js / browsers. I tried briefly using `wasm-pack build` (after adding `crate-type = ["cdylib"]` to Cargo.toml) and it just spit out a bunch of errors. I'm not experience enough to know whether this is relatively easy with a little bit more configuration or if it would require rewriting code. Any feedback / help is appreciated.
kerem closed this issue 2026-02-27 19:30:06 +03:00
Author
Owner

@codetheweb commented on GitHub (Oct 13, 2020):

After some more investigation, it seems that the main blocker on this is the fact that raw TCP sockets are used (which are supported in Node.js but not the browser).

If you want to run it in a browser, it might be possible to use Emcripten which polyfills sockets to web sockets. You'd also then need something like websockify on a server.

In theory it should be possible to run on Node.js using network calls from WASI but I'm not sure if WASM compilers work with that yet. This is a very rapidly changing space.

So TL;DR is that if you want Node.js support it looks like it might be easiest to just re-implement in JS.

<!-- gh-comment-id:708046561 --> @codetheweb commented on GitHub (Oct 13, 2020): After some more investigation, it seems that the main blocker on this is the fact that raw TCP sockets are used (which are supported in Node.js but not the browser). If you want to run it in a browser, it might be possible to use Emcripten which polyfills sockets to web sockets. You'd also then need something like [websockify](https://github.com/novnc/websockify) on a server. In theory it should be possible to run on Node.js using network calls from [WASI](https://github.com/WebAssembly/WASI) but I'm not sure if WASM compilers work with that yet. This is a very rapidly changing space. So TL;DR is that if you want Node.js support it looks like it might be easiest to just re-implement in JS.
Author
Owner

@schickling commented on GitHub (Jun 24, 2022):

Thanks for sharing your investigations @codetheweb.

Looks like there's some ongoing work on bringing socket support to Wasi.

<!-- gh-comment-id:1165842816 --> @schickling commented on GitHub (Jun 24, 2022): Thanks for sharing your investigations @codetheweb. Looks like there's some ongoing work on bringing [socket support to Wasi](https://github.com/WebAssembly/WASI/pull/312).
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/librespot#338
No description provided.