async-std
async-std copied to clipboard
Support wasm32-wasi compilation target - fix net2 dependency
This is not directly related with this crate's source code, rather some dependencies.
Though when compiling to WASI for instance there are lots of errors from net2 which should be fixable as os::wasi has implementation for missing values/methods:
error[E0425]: cannot find value `SOL_SOCKET` in this scope
--> /Users/max/.cargo/registry/src/github.com-1ecc6299db9ec823/net2-0.2.33/src/ext.rs:993:33
|
993 | get_opt(self.as_sock(), SOL_SOCKET, SO_BROADCAST)
| ^^^^^^^^^^ not found in this scope
It appears some issues were fixed in net2:master with https://github.com/rust-lang-nursery/net2-rs/pull/84 though net2 version was not released.
Adding direct git target to Cargo.toml does not fix it yet
[patch.crates-io]
net2 = { git="https://github.com/rust-lang-nursery/net2-rs" }
it seems there are more issues now, due to wasi implementation changes:
Compiling net2 v0.2.33 (https://github.com/rust-lang-nursery/net2-rs#eda403f0)
error[E0432]: unresolved import `libc::__wasi_fd_t`
--> /Users/max/.cargo/git/checkouts/net2-rs-4b5319289a3d25c1/eda403f/src/sys/wasi/mod.rs:12:25
|
12 | use libc::{self, c_int, __wasi_fd_t};
| ^^^^^^^^^^^ no `__wasi_fd_t` in the root
error[E0432]: unresolved import `sys::c::__wasi_fd_t`
--> /Users/max/.cargo/git/checkouts/net2-rs-4b5319289a3d25c1/eda403f/src/sys/wasi/impls.rs:5:17
|
5 | use sys::{self, c::__wasi_fd_t};
| ^^^^^^^^^^^^^^ no `__wasi_fd_t` in `sys::c`
it seems that net2 is replaced with socket2 but socket2 doesn't support WASI either.
async-io is already excluded on wasm32-unknown-unknown target, using a very weird way:
https://github.com/async-rs/async-std/blob/f4b8c7a108a962fb6a9b686bbfacab37f829b556/Cargo.toml#L85-L89
This exclusion should apply to wasm32-wasi target as well. (How?)
Never mind, it's a lot more complicated than that.
wasm32-wasi is just a very different target compared to wasm32-unknown-unknown.
Among other things, wasm-bindgen does not support the wasm32-wasi target:
- https://github.com/rustwasm/wasm-bindgen/issues/2554#issuecomment-840774170
- https://github.com/bytecodealliance/cargo-wasi/issues/110#issuecomment-946003634
I was able to get async-std to build for the wasm32-wasi target with some simple search and replace, but what's the point if everything is not working?
Shouldn't local spawning work on wasm32-wasi same way as wasm32-unknown-unknown?
Looking to understand how wasm32-wasi is different in regards to async-std