-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Hook up std::net to wasi-libc on wasm32-wasip2 target #129638
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @tgross35 (or someone else) some time within the next two weeks. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
Thanks for the PR! The reasoning for these changes makes sense, but why are all the extern interfaces added here? That part of the changes should go into our libc https://github.com/rust-lang/libc/blob/72cb7aaf50bf70b5d360b1a64b0d52d3ed3fbf15/src/wasi.rs. Pinging was[mi] expert @alexcrichton, could you double check the reasoning here? |
More specifically, if these are available on wasi-p2 but not p1 then the libc changes would mean:
|
I was planning to work on bringing those extern interfaces to rust-lang/libc next by doing exactly that. |
It would be better to update libc first so definitions only live in a single place, I would be concerned about things getting out of sync otherwise. Doing that shouldn't be much worse than adding them here - you can probably just do steps 1, 2, and 4 in my list above, skipping step 3 unless it turns out to be a problem. The turnaround is pretty quick getting a new libc version and updating std. |
Also if you have a link to the headers please post them in the libc PR, sometimes it's tough to track down where definitions came from |
Thanks so much for working on this! I'll do a review tomorrow |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you so much for working on this! I've left some comments below with a few thoughts here and there. Mostly I'm hoping we can delegate to libc to return errors where possible instead of explicitly returning errors here since that'll make it easier to support in the future by just changing wasi-libc. Otherwise most of your other changes also makes sense to me, but let me know if you have any more questions.
As for libc
bindings, I agree it'd be great to get these bindings upstream into the libc
crate itself. I can try to take a look at setting that up CI-wise, and/or please feel free to cc me on PRs.
I've started a bit with wasi-libc by submitting rust-lang/libc#3869 to re-enable CI. Once that's ready I'll also submit a new target of wasm32-wasip2 and get that configured/ready too. After that it should be a simpler to add p2-specific constants and such. |
Oh I can also mention, have you been able to test this? For example are you able to run perhaps the |
0ed4afd
to
8988920
Compare
Thanks for the review and starting the work on libc. I'll have a look at moving over the brindings next. Unfortunately, building the standard library test suit for the |
You should be able to filter them with something like |
This is similar to rust-lang#3869 except that it adds tests for `wasm32-wasip2` in addition to `wasm32-wasip1`. This is intended to eventually empower definitions from rust-lang/rust#129638 to move into this repository.
This is similar to rust-lang#3869 except that it adds tests for `wasm32-wasip2` in addition to `wasm32-wasip1`. This is intended to eventually empower definitions from rust-lang/rust#129638 to move into this repository. (backport <rust-lang#3870>) (cherry picked from commit 15f8c44)
This is similar to rust-lang#3869 except that it adds tests for `wasm32-wasip2` in addition to `wasm32-wasip1`. This is intended to eventually empower definitions from rust-lang/rust#129638 to move into this repository. (backport <rust-lang#3870>) (cherry picked from commit 15f8c44)
Ok all looks good to me, thanks again! Before landing though I think it'd be good to run this through its paces with the test suite of the standard library (or another library if you're interested in another library perhaps?). If the standard library's tests don't build at all is it possible to temporarily comment out the pieces that don't build? This won't be run on CI anyway so it's more of a one-time check to make sure things are working. |
Are the bindings able to go into libc? I'm working on rolling a release today, happy to hold off on that. |
I'm working on the bindings right now. If you could hold off on the release, that'd be great. |
No problem! They're pretty quick to do whenever |
They fail to build. Here are the errors I'm getting: error: cannot find macro `error` in this scope
--> std/src/fs/tests.rs:1147:5
|
1147 | error!(blank.create(true).open(&tmpdir.join("f")), invalid_options);
| ^^^^^
error[E0433]: failed to resolve: could not find `unix` in `os`
--> std/src/process/tests.rs:574:16
|
574 | crate::os::unix::process::CommandExt::arg0(&mut command, "exciting-name");
| ^^^^ could not find `unix` in `os`
|
note: found an item that was configured out
--> std/src/os/mod.rs:27:9
|
27 | pub mod unix {}
| ^^^^
note: the item is gated here
--> std/src/os/mod.rs:19:1
|
19 | / #[cfg(all(
20 | | doc,
21 | | any(
22 | | all(target_arch = "wasm32", not(target_os = "wasi")),
23 | | all(target_vendor = "fortanix", target_env = "sgx")
24 | | )
25 | | ))]
| |___^
note: found an item that was configured out
--> std/src/os/mod.rs:65:9
|
65 | pub mod unix;
| ^^^^
note: the item is gated here
--> std/src/os/mod.rs:64:1
|
64 | #[cfg(all(not(target_os = "hermit"), any(unix, doc)))]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0405]: cannot find trait `AsRawFd` in this scope
--> std/src/net/tcp/tests.rs:678:32
|
678 | fn render_inner(addr: &dyn AsRawFd) -> impl fmt::Debug {
| ^^^^^^^ not found in this scope
|
help: consider importing one of these traits
|
1 + use crate::os::fd::AsRawFd;
|
1 + use crate::realstd::os::fd::AsRawFd;
|
error[E0425]: cannot find function `symlink_file` in this scope
--> std/src/fs/tests.rs:76:11
|
76 | match symlink_file(r"nonexisting_target", link) {
| ^^^^^^^^^^^^ not found in this scope
error[E0425]: cannot find function `junction_point` in this scope
--> std/src/fs/tests.rs:595:12
|
595 | check!(junction_point(&d2, &dt.join("d2")));
| ^^^^^^^^^^^^^^ not found in this scope
error[E0425]: cannot find function `symlink_dir` in this scope
--> std/src/fs/tests.rs:702:17
|
702 | let _ = symlink_dir(attack_dest_dir, &victim_del_path);
| ^^^^^^^^^^^ not found in this scope
error[E0425]: cannot find function `env_cmd` in this scope
--> std/src/process/tests.rs:276:19
|
276 | let mut cmd = env_cmd();
| ^^^^^^^ not found in this scope It looks like the standard library test suite expects the
I agree, that would be good! I can't think of a library to thoroughly test this with off the top of my head, but I'll look into getting the test suite to build 👍 |
Should be good to go now 👍 |
@bors: r+ |
Hook up std::net to wasi-libc on wasm32-wasip2 target One of the improvements of the `wasm32-wasip2` target over `wasm32-wasip1` is better support for networking. Right now, p2 is just re-using the `std::net` implementation from p1. This PR adds a new net module for p2 that makes use of net from `sys_common` and calls wasi-libc functions directly. There are currently a few limitations: - Duplicating a socket is not supported by WASIp2 (directly returns an error) - Peeking is not yet implemented in wasi-libc (we could let wasi-libc handle this, but I opted to directly return an error instead) - Vectored reads/writes are not supported by WASIp2 (the necessary functions are available in wasi-libc, but they call WASIp1 functions which do not support sockets, so I opted to directly return an error instead) - Getting/setting `TCP_NODELAY` is faked in wasi-libc (uses the fake implementation instead of returning an error) - Getting/setting `SO_LINGER` is not supported by WASIp2 (directly returns an error) - Setting `SO_REUSEADDR` is faked in wasi-libc (since this is done from `sys_common`, the fake implementation is used instead of returning an error) - Getting/setting `IPV6_V6ONLY` is not supported by WASIp2 and will always be set for IPv6 sockets (since this is done from `sys_common`, wasi-libc will return an error) - UDP broadcast/multicast is not supported by WASIp2 (since this is configured from `sys_common`, wasi-libc will return appropriate errors) - The `MSG_NOSIGNAL` send flag is a no-op because there are no signals in WASIp2 (since explicitly setting this flag would require a change to `sys_common` and the result would be exactly the same, I opted to not set it) Do those decisions make sense? While working on this PR, I noticed that there is a `std::os::wasi::net::TcpListenerExt` trait that adds a `sock_accept()` method to `std::net::TcpListener`. Now that WASIp2 supports standard accept, would it make sense to remove this? cc `@alexcrichton`
💔 Test failed - checks-actions |
@bors retry MSVC spurious issue |
Rollup of 5 pull requests Successful merges: - rust-lang#129638 (Hook up std::net to wasi-libc on wasm32-wasip2 target) - rust-lang#130877 (rustc_target: Add RISC-V atomic-related features) - rust-lang#130914 (Mark some more types as having insignificant dtor) - rust-lang#130961 (Enable `f16` tests on x86 Apple platforms) - rust-lang#130966 (make ptr metadata functions callable from stable const fn) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#129638 - nickrum:wasip2-net, r=alexcrichton Hook up std::net to wasi-libc on wasm32-wasip2 target One of the improvements of the `wasm32-wasip2` target over `wasm32-wasip1` is better support for networking. Right now, p2 is just re-using the `std::net` implementation from p1. This PR adds a new net module for p2 that makes use of net from `sys_common` and calls wasi-libc functions directly. There are currently a few limitations: - Duplicating a socket is not supported by WASIp2 (directly returns an error) - Peeking is not yet implemented in wasi-libc (we could let wasi-libc handle this, but I opted to directly return an error instead) - Vectored reads/writes are not supported by WASIp2 (the necessary functions are available in wasi-libc, but they call WASIp1 functions which do not support sockets, so I opted to directly return an error instead) - Getting/setting `TCP_NODELAY` is faked in wasi-libc (uses the fake implementation instead of returning an error) - Getting/setting `SO_LINGER` is not supported by WASIp2 (directly returns an error) - Setting `SO_REUSEADDR` is faked in wasi-libc (since this is done from `sys_common`, the fake implementation is used instead of returning an error) - Getting/setting `IPV6_V6ONLY` is not supported by WASIp2 and will always be set for IPv6 sockets (since this is done from `sys_common`, wasi-libc will return an error) - UDP broadcast/multicast is not supported by WASIp2 (since this is configured from `sys_common`, wasi-libc will return appropriate errors) - The `MSG_NOSIGNAL` send flag is a no-op because there are no signals in WASIp2 (since explicitly setting this flag would require a change to `sys_common` and the result would be exactly the same, I opted to not set it) Do those decisions make sense? While working on this PR, I noticed that there is a `std::os::wasi::net::TcpListenerExt` trait that adds a `sock_accept()` method to `std::net::TcpListener`. Now that WASIp2 supports standard accept, would it make sense to remove this? cc `@alexcrichton`
…alexcrichton Decouple WASIp2 sockets from WasiFd This is a follow up to rust-lang#129638, decoupling WASIp2's socket implementation from WASIp1's `WasiFd` as discussed with `@alexcrichton.` Quite a few trait implementations in `std::os::fd` rely on the fact that there is an additional layer of abstraction between `Socket` and `OwnedFd`. I thus had to add a thin `WasiSocket` wrapper struct that just "forwards" to `OwnedFd`. Alternatively, I could have added a lot of conditional compilation to `std::os::fd`, which feels even worse. Since `WasiFd::sock_accept` is no longer accessible from `TcpListener` and since WASIp2 has proper support for accepting sockets through `Socket::accept`, the `std::os::wasi::net` module has been removed from WASIp2, which only contains a single `TcpListenerExt` trait with a `sock_accept` method as well as an implementation for `TcpListener`. Let me know if this is an acceptable solution.
Rollup merge of rust-lang#131449 - nickrum:wasip2-net-decouple-fd, r=alexcrichton Decouple WASIp2 sockets from WasiFd This is a follow up to rust-lang#129638, decoupling WASIp2's socket implementation from WASIp1's `WasiFd` as discussed with `@alexcrichton.` Quite a few trait implementations in `std::os::fd` rely on the fact that there is an additional layer of abstraction between `Socket` and `OwnedFd`. I thus had to add a thin `WasiSocket` wrapper struct that just "forwards" to `OwnedFd`. Alternatively, I could have added a lot of conditional compilation to `std::os::fd`, which feels even worse. Since `WasiFd::sock_accept` is no longer accessible from `TcpListener` and since WASIp2 has proper support for accepting sockets through `Socket::accept`, the `std::os::wasi::net` module has been removed from WASIp2, which only contains a single `TcpListenerExt` trait with a `sock_accept` method as well as an implementation for `TcpListener`. Let me know if this is an acceptable solution.
One of the improvements of the
wasm32-wasip2
target overwasm32-wasip1
is better support for networking. Right now, p2 is just re-using thestd::net
implementation from p1. This PR adds a new net module for p2 that makes use of net fromsys_common
and calls wasi-libc functions directly.There are currently a few limitations:
TCP_NODELAY
is faked in wasi-libc (uses the fake implementation instead of returning an error)SO_LINGER
is not supported by WASIp2 (directly returns an error)SO_REUSEADDR
is faked in wasi-libc (since this is done fromsys_common
, the fake implementation is used instead of returning an error)IPV6_V6ONLY
is not supported by WASIp2 and will always be set for IPv6 sockets (since this is done fromsys_common
, wasi-libc will return an error)sys_common
, wasi-libc will return appropriate errors)MSG_NOSIGNAL
send flag is a no-op because there are no signals in WASIp2 (since explicitly setting this flag would require a change tosys_common
and the result would be exactly the same, I opted to not set it)Do those decisions make sense?
While working on this PR, I noticed that there is a
std::os::wasi::net::TcpListenerExt
trait that adds asock_accept()
method tostd::net::TcpListener
. Now that WASIp2 supports standard accept, would it make sense to remove this?cc @alexcrichton