rust-socketio icon indicating copy to clipboard operation
rust-socketio copied to clipboard

wasm support

Open johanhelsing opened this issue 3 years ago • 9 comments

I'm looking for a socket io client crate that works on both wasm and native. Is this something you'd want to add?

johanhelsing avatar Sep 01 '21 07:09 johanhelsing

What exactly do you mean by working with Wasm? Right now you could compile the crate to Wasm using Emscripten's runtime: cargo build --target wasm32-unknown-emscripten. What you mean is probably interoperability with JS via wasm_bindgen. The problem here is, that you then usually compile to the target wasm32-unknown-unknown, which doesn't compile with stdio things like threads and networking (stuff that this crate uses extensively). A possible solution would be to add #![cfg(target_arch = "wasm32")] flags to those functions and sub it with the bindings from web-sys. I generally would like to see that this crate works with Wasm, also because I think that this would be a use case.

1c3t3a avatar Sep 01 '21 08:09 1c3t3a

Yes, the use case I have is that I want to be able to run the same code without modifications both in the browser and as a native application.

johanhelsing avatar Sep 01 '21 11:09 johanhelsing

Ups sorry! I think in order to get this started one could look at how reqwest (the http library used here) implemented Wasm support (mainly in src/wasm or src/lib.rs). We would also need to somehow factor out the thread that starts the polling cycle and threads that start the callback (currently through the spawn_scoped! macro). Async support before this (see Roadmap.md) would come in handy because async is supported by the browser.

1c3t3a avatar Sep 05 '21 20:09 1c3t3a

If looked further into this and WASI could be an option as well. WASI provides sort of a normal standard library for WebAssembly and is both supported by the browser and the most common runtimes. It is accessible via the wasm32-wasi target. It provides a std implementation, but yields unimplemented!() calls on the functions unavailable in the browser.

1c3t3a avatar Sep 14 '21 17:09 1c3t3a

A build error related to openssl is found while I am trying to use it in an app built on wasm and rust.

piaoger avatar Oct 20 '22 07:10 piaoger

Yes, this is not yet implemented. There is no support for the WASM target yet.

1c3t3a avatar Oct 20 '22 07:10 1c3t3a

Yes, this is not yet implemented. There is no support for the WASM target yet.

Got it :) You have aldeady done great job. It 's nice to see more and more frontend frameworks wrintten in rust.

piaoger avatar Oct 21 '22 02:10 piaoger

any update on this? i would like to use socketio client within leptos but got the same error with wasm

philipp1992 avatar Jan 18 '24 14:01 philipp1992

I am ok if only can compile to wasm only so I can use it with my browser extension.

currently getting error for getrandom crate when compiling with wasm-pack. image

wants to be added js feature image

ulvido avatar Jun 16 '24 07:06 ulvido