Skip to content
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

Wasm support #87

Open
ghost opened this issue May 5, 2020 · 13 comments
Open

Wasm support #87

ghost opened this issue May 5, 2020 · 13 comments
Labels
enhancement New feature or request help wanted Extra attention is needed request for comments Feedback, thoughts, suggestions, opinions

Comments

@ghost
Copy link

ghost commented May 5, 2020

I'm assuming a browser (javascript) environment. Quick thoughts:

  • Async will be unusable because AsRawFd/AsRawSocket types don't exist on wasm.
  • Timer can be perhaps be implemented by calling setTimeout() in javascript.
  • Instead of running a thread-local or work-stealing executor, just spawn tasks through javascript.
  • Blocking executor should either be normal spawn or panic.
@ghost ghost added enhancement New feature or request help wanted Extra attention is needed request for comments Feedback, thoughts, suggestions, opinions labels May 5, 2020
@FuriouZz
Copy link

FuriouZz commented May 7, 2020

Hello there 👋🏾 I will be glad to help you with this issue!

@ghost
Copy link
Author

ghost commented May 7, 2020

@FuriouZz Thank you, help would be very welcome! :)

@Stupremee
Copy link

Imo blocking executor should just redirect to a normal spawn because it’s easier to convert current code to Wasm. But it should be mentioned in the documentation somewhere.

@ghost
Copy link
Author

ghost commented May 7, 2020

For reference, see wasm support in async-std: async-rs/async-std#757

@ghost
Copy link
Author

ghost commented May 7, 2020

@Stupremee Is the blocking executor even used on wasm? I would assume no since there are no files and no stdin/stdout/stderr on wasm, but I could be wrong?

@huangjj27
Copy link

huangjj27 commented May 9, 2020

I would assume no since there are no files and no stdin/stdout/stderr on wasm, but I could be wrong?

Maybe it's about WASI ? It would be glad to see WASI is also supported

@ghost
Copy link
Author

ghost commented May 9, 2020

@huangjj27 I believe WASI still in development and does not have what we need yet... hopefully soon :)

@jjl jjl mentioned this issue May 9, 2020
@jjl
Copy link

jjl commented May 9, 2020

I've got a WIP PR #99 where i've started to implement this. At the minute, most things are basically commented out with cfg, but I've started some of the basic plumbing to get everything building.

There's plenty left to do, like actually call some javascript apis to spawn the task and work on e.g. Timer, but people seem interested in contributing from this thread, so I thought I'd start making things public early.

@fogti
Copy link
Member

fogti commented Jul 10, 2020

support for emscripten might be useful, too ((maybe) related: https://users.rust-lang.org/t/how-to-get-tcpstream-to-work-in-wasm/13103/6)... althrough I'm not sure how common emscripten usage is, as of today.

@kwek20
Copy link

kwek20 commented Nov 6, 2020

This is still an issue for me @stjepang ; i'm running on windows with rust 1.47:
cargo run --example windows-uds --target wasm32-unknown-unknown
It will fail on nb-connect-1.0.2 which is missing socket imports from async-io-> winapi-rs

Ive given it a look but im lost in dependencies :) , any idea?

@notgull
Copy link
Member

notgull commented Aug 21, 2022

It's going to be difficult to implement this before atomics become stable for WASM runtimes. The main blocker is the parking crate. We could use setTimeout() to implement parking with timeouts, and maybe even some kind of Promise-oriented system where Unpark calls the resolve() callback. However, WASM has a threading proposal that simplifies this and avoids needing to call into JS at all. As a bonus, this would be able to run inside of WASI runtimes like Wasmer, instead of just inside of browsers.

However, both Wasmtime and Wasmer don't have the best support for atomics right now. When I run parking's tests in wasmtime, it complains of an env::memory module not being available. I'm unsure if this is an error with wasmtime or with Rust's code generation. I get even more cryptic errors when I try it in Wasmer.

@notgull
Copy link
Member

notgull commented Nov 26, 2023

With the exception of async-io (smol-rs/async-io#153), every smol crate that can realistically support WASM now supports WASM. I suppose that such WASM support can be exposed in this crate as well.

@smol-rs/admins Thoughts on exposing WASM support in this higher level crate?

@extraymond
Copy link

extraymond commented Mar 15, 2024

It would be nice to use smol in cloudflare worker!
They landed socket support which impl AsyncRead/AsyncWrite. This enables connecting to tokio-postgres, which is pretty cool.
https://github.com/cloudflare/workers-rs/blob/cfaabb5c021121a544c0981d05cf9317e4e03503/worker/src/socket.rs#L141

It would nice to compose futures around smol's local_executor in their wasm runtime, several of the worker-rs api are derived from web_sys and have async api around them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed request for comments Feedback, thoughts, suggestions, opinions
Development

Successfully merging a pull request may close this issue.

8 participants