Stream: rust-toolchain

Topic: WASI 0.2 support for `socket2`


view this post on Zulip Yoshua Wuyts (Sep 06 2024 at 15:44):

@Alex Crichton hey I saw you were helping out with TCP support in the Rust stdlib. Am I remembering it correctly that you also originally authored the socket2 crate?

I'm not going to ask you to do any work here. But I was wondering if say, hypothetically I was interested in updating socket2. Do we need an updated version of wasi-libc for that? Or do we think this is something that we can do with just the wasi crate?

The BSD socket stuff seems pretty involved, so my gut feeling says that we'd be reimplementing a lot of wasi-libc if we did it directly. But I figured I should ask!

view this post on Zulip Alex Crichton (Sep 06 2024 at 15:45):

I'd probably recommend using wasi-libc APIs, so for this I'd recommend waiting for libc to update with https://github.com/rust-lang/libc/pull/3892 and then adding the build target to the crate from there

This moves the bindings necessary for rust-lang/rust#129638 to libc. Unfortunately, I wasn't able to test this with the standard library due to #3789. Is there any workaround for that issue? He...

view this post on Zulip Yoshua Wuyts (Sep 06 2024 at 15:46):

okkkk, that's good to know - thank you for confirming!

view this post on Zulip Alex Crichton (Sep 06 2024 at 15:46):

but if you'd like I'm more than happy to be cc'd on a PR for support, this is something that I'd like to double-check what the needs from the standard library are

view this post on Zulip Alex Crichton (Sep 06 2024 at 15:46):

the standard library exposes a few fd-related things which need to be updated

view this post on Zulip Alex Crichton (Sep 06 2024 at 15:46):

(possibly in a breaking way, which also reminds me that I should go do it now)

view this post on Zulip Yoshua Wuyts (Sep 06 2024 at 15:46):

oh wait, right - does the stdlib depend on socket2?

view this post on Zulip Alex Crichton (Sep 06 2024 at 15:47):

it doesn't, but socket2 may rely on extensions the standard library provides in std::os::wasi, and that's an outdated module on the p2 target

view this post on Zulip Yoshua Wuyts (Sep 06 2024 at 15:48):

by the way, to add context to what I'm doing: I'm currently mapping out what is needed to enable the smol async runtime to work with WASI 0.2. socket2 seems to be in the critical path for that.

view this post on Zulip Yoshua Wuyts (Sep 06 2024 at 15:48):

Alex Crichton said:

it doesn't, but socket2 may rely on extensions the standard library provides in std::os::wasi, and that's an outdated module on the p2 target

ahhh, i see! - that makes sense!

view this post on Zulip Alex Crichton (Sep 06 2024 at 15:48):

Alex Crichton said:

it doesn't, but socket2 may rely on extensions the standard library provides in std::os::wasi, and that's an outdated module on the p2 target

ok scratch this, std::os::wasip2 is stable, but empty, and std::os::wasi is unstable on the wasip2 target, as intended, so everything is working as expected there

view this post on Zulip Joel Dice (Sep 06 2024 at 15:53):

@Yoshua Wuyts I don't know if it's helpful, but I created enough of a fake socket2 library to get tokio-postgres working as part of my wasi-sockets-tests experiments, for which I created experimental forks of Rust, mio, tokio, and rust-postgres: https://github.com/sfackler/rust-postgres/compare/master...dicej:rust-postgres:wasi-sockets

Test harness for prototyping support for wasi-sockets in the Rust std library and wasi-libc - dicej/wasi-sockets-tests
Native PostgreSQL driver for the Rust programming language - Comparing sfackler:master...dicej:wasi-sockets · sfackler/rust-postgres

view this post on Zulip Yoshua Wuyts (Sep 06 2024 at 15:55):

ohhh, that's so sick!

view this post on Zulip Yoshua Wuyts (Sep 06 2024 at 15:55):

ty for sharing!


Last updated: Nov 22 2024 at 17:03 UTC