-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
meta: Stabilize WASI support #4827
Comments
|
This adds initial, unstable, support for the wasm32-wasi target. Not all of Tokio's features are supported yet as WASI's non-blocking APIs are still limited. Refs: #4827
For missing APIs like TcpStream and TcpListener, I tried to replace std with wasmedge_wasi_socket and it works. |
Since WASM Threads are already support by Rust Std (although in nightly with build std) would it be possible to bring the multi thread runtime to WASM? |
I'm sure we will support it eventually, but it is not a priority right now. |
@umgefahren Do you have a link to the PR where this was implemented in std? |
There is some code for Wasm threads, but most of it is empty or unsupported: wasm/atomics/thread.rs. The same is true for Wasi, wasi/thread.rs. There has been some progress on Wasi threads, the Wasi-Libc project has some pthread functions https://github.com/WebAssembly/wasi-libc/search?q=pthread, but most seem to be in the musl library. Even if Rust or C had code for Wasi threads, this still requires a Wasi runtime to be able to use it, and I don't think we're there yet. |
has anyone tried somehow replacing threads with web workers? intuitively that seems like it would work. I don't know enough about Tokio or Rust to say for certain, but it seems like a natural fit considering that "the I searched for "wasm threads web workers" which led to some prior work with emscripten (e.g. https://github.com/boyanio/wasm-workers). Looks interesting. Also gregbuchholz/threads looks promising, claiming successful multi-threading in the I also found the Is the idea to basically implement This sounds feasible, at least in terms of the features available to Web Workers, like |
FYI: Wasmtime just recently landed thread support: bytecodealliance/wasmtime#5484 (not yet in any release) |
"Announcing wasi-threads" (proposal) |
I wonder if WASIX would also be worth supporting? It looks like they also have their own forked version of tokio for this https://github.com/wasix-org/tokio/tree/wasix-1.24.2 Edit: |
« WASI threads, implementation of wasm32-wasi-preview1-threads target This PR adds a target proposed in rust-lang/compiler-team#574 by @abrown and implementation of |
See also the open issue about supporting WasmEdge, which seems to be a similar situation: both have their own Tokio fork, but presumably would like to have support upstream in Tokio so they don't need to tell their users to put in an override. I anticipate that some of the hunger for runtime-vendor-specific extensions from end users of Tokio will fade as WASI Preview 2 comes together later this year, but I definitely don't understand the space well enough to say for sure, or if the vendors themselves would still hope for some upstream support. E.g. if a vendor adds a special IO primitive to their runtime that is faster than what's in WASI by accepting a more relaxed security posture, they might want their users to be able to opt in to using that. So I guess the question on my mind is one of policy: would the Tokio project want to carry vendor-specific patches? For small things only? For "support WASI Preview 1 long term even after Preview 2 ships"? Yes, but only until WASI itself hits 1.0? |
That will be great, hopefully it will end this vendor-specific extension. |
We already have unstable support for wasi, and I don't mind PRs with updates to our unstable support as long as they aren't too complicated. |
I don't think this is going to go away entirely, and it's not clear to me what additional support in Wasm for vendor extensions would look like beyond what is already afforded by the WebAssembly Component Model. I suspect there will always be demand for compilers to support vendor-specific extensions, or something equivalent. E.g. Wasmer's WASIX provides POSIX-compatible APIs so that you can compile existing code bases (without invasive modifications) to Wasm, and then run them anywhere. To achieve this today, they have their own I wonder if this situation could be simplified by the Rust project itself owning a WIT world that defines what Unless/until we ended up with a single standard "full OS" world (presumably) defined under the umbrella of the WebAssembly project you might still have a world defined by each language toolchain that's interested in this sort of thing (e.g. Zig, Nim, etc.) but an adapter component is a lot lighter-weight than managing an entire fork of Slight tangent: POSIX / "full OS" compatibility might be an anti-goal or at least orthogonal to the goals of a lot of people working in the WebAssembly space (the ambition goes a long way beyond "cross platform bytecode for POSIX"), but there is clearly demand, so it might be best to embrace that. I could even imagine it being a "gateway drug" towards WASI adoption. |
I think there are few things that should be changed in tracking issue and taken into consideration
|
It's nice that wasi is working towards more socket options, but you say that they are still proposals, so it doesn't sound like there is anything for us to do yet? |
I just wanted to drop in as one of the folks working on Wasi Preview 2 through the Bytecode Alliance. Hopefully I can clarify what the state of Wasi is, and what we, in the Bytecode Alliance, hope to accomplish in the medium term. Preview 2 (perhaps despite the name) is not merely a proposal, but is the official next evolution of Wasi (what has been known until now as Wasi has been retroactively renamed to Preview 1) and has been officially adopted by the Wasi Subgroup which is an official subgroup of the WebAssembly Community Group of the W3C. Preview 2 is meant to hint towards the fact that the evolution will continue towards a Preview 3 before ultimately a 1.0. Even though the Wasi subgroup has chosen to not give this version of Wasi the 1.0 version, Preview 2 is meant as an "island of stability" around which the rest of ecosystem can grow. This means there is a commitment to support Preview 2 well beyond the introduction of Preview 3 and any other versions (on the order of magnitude of years) much like Preview 1 support has not suddenly ended with the introduction of Preview 2. Beyond this, there is significant interest in the Bytecode Alliance to see adoption of Preview 2 within the community which can help inform changes that will need to happen in future evolutions of Wasi. Members of the Bytecode Alliance have already begun implementing Preview 2 support in Tokio and dependent crates such as mio, and we hope that we'll be able to open pull requests soon and work with the Tokio maintainers on landing these changes. Preview 2 should have the required API support to implement everything Tokio needs for single threaded executors. It is true that Preview 3 will likely have large impacts on the implementation details on Tokio support for Wasi (due to the introduction of first class async in the Component Model), but of course, there will be significant resources to help move Tokio over to Preview 3 when that times comes (which is probably earliest 1 year from now but may be longer). |
FYI, I have created temporary forks of both |
They're not just proposals. The One more fun tidbit: we've updated CPython as well, and got all the relevant |
Propasal I was talking about is Also all Preview 3 stuff was mentioned as a separate point becouse it's introducing stuff related to handling async |
Thank you for clarifying. I have opened #6323 to track support for preview 2. |
Can you elaborate what part of WASI support that is not part of WASI Preview 2 support |
@banocean There are two aspects of this:
This issue tracks the first aspect, the other issue tracks the second aspect. |
Now I'm kinda confused, is there any outline when a feature is put under |
I don't know what you mean by "outline". Putting things under |
Oh, I through that wasi support under tokio_unstable feature flag was base on the fact that introducing it normally won't comply with the 6 moths MSRV requirement |
Some projects have this as a blocker for supporting WASM. What are the remaining issues before merge? |
It's not gonna break stuff since wasix has forked tokio and all wasix implementations are based on using that crate instead of the official tokio one |
Supporting wasm in Tokio would require that someone who cares about wasm gets involved with Tokio and does the work to make it happen. To my knowledge, there are no blockers to supporting wasi preview 2 other than someone taking the time to implement whatever is missing. But I'm not going to do it — the wasm world is not something I have any involvement in, and we need someone who does have that knowledge to do it. (Note that the above talks about things like wasi that look like the platforms we support today. Non-web-worker browser wasm is a different story, and is out of scope for the foreseeable future.) |
Now that rust-lang/rust#129638 has been merged, I can start working on |
The blocker was rust waiting for wasi-libc preview 2 support, looks like it started moving. Only things that could stand in a way on tokio side is previous wasm compatibility or some system apis not getting covered by wasi preview 2 standard. |
Ah, I see. I did not know that it was blocked on adding support for things in std. |
This tracks outstanding issues to stabilize WASI support for Tokio.
Initial PR: #4716
Known issues:
tokio::time
can be stabilized.target_family = "wasm"
once MSRV becomes 1.54. Current workaround: #4865TcpStream::connect
TcpListener::bind
Refs: #1597
The text was updated successfully, but these errors were encountered: