-
-
Notifications
You must be signed in to change notification settings - Fork 404
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
feat(quinn,quinn-udp): Avoid socket2
and std::net::UdpSocket
dependencies in wasm32-unknown-unknown
target
#2037
base: main
Are you sure you want to change the base?
Conversation
4fa89dd
to
a934ab4
Compare
I realized this PR is missing some rationale, so I'm writing this on the top level for better visibility:
This was one of the first things I was thinking initially, too. The only definitions that The fundamental problem IMO is that The solution would be to separate out the type definitions of
Yes, there's no way of using The alternative would be integrating with |
a12a85a
to
8b20acd
Compare
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.
Okay, I think this all makes sense. Thanks!
@Ralith ping? |
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.
I understand the rational above for importing quinn-udp
in a WASM context.
That said, for what my opinion is worth here, I can't judge whether it is worth the complexity it introduces. Will defer to the actual Quinn maintainers.
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.
Instead of the many cfg(feature = "net")
, wouldn't something along the following be simpler?
#[cfg(feature = "net")]
use net::*;
#[cfg(feature = "net")]
mod net {
// Everything that was previously feature flagged behind net.
}
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.
I've got a version where I've experimented with that.
It's a much more invasive change, I'm not sure if it's much better?
I can add it to this PR if other people agree: n0-computer@d06b71b
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.
Thanks for the commit. I didn't think of the fact that unix.rs
and windows.rs
would need to be under the net/
module.
At this point I don't have a better idea, nor a preference for the options listed here.
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.
couldnt windows and unix stuff be stuffed under a "system" "sys" or something like that.
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.
The newest version that avoids the feature in favor of a cfg alias wasm_browser
makes lots of these cfgs simpler, as that cfg is exclusive with unix and windows cfgs.
Please take a look at the latest diff @mxinden I think you'll like it more.
You mentioned that you also considered gating on target instead of a cargo feature. Can you elaborate on why you went with the feature instead? I think exposing a subset API on some targets is less hazardous than a cargo feature, particularly as this is technically a semver break affecting users who have |
Main reason was that I noticed this was similar to e.g. tokio's #[cfg(all(not(all(target_family = "wasm", target_os = "unknown")), unix))]
use std::os::unix::io::AsFd; But I see that you have cfg-aliases enabled for quinn-udp, so I'll try it with that. |
38cec54
to
a9a0128
Compare
I've updated the PR to use a cfg alias |
The CI failed with:
|
Indeed... Re-running it, it would be convenient if it's spurious but exciting if it's not. |
@matheus23 I know you saw this on Discord, but could you add this commit to the PR by whatever means you find most convenient to make the CI pass? |
net
feature to allow disabling socket2
and std::net::UdpSocket
dependenciessocket2
and std::net::UdpSocket
dependencies in wasm32-unknown-unknown
target
To be honest, I'm not sure this feature gating approach is the best solution. I find it hard to follow, and I worry about our ability to remember why it is that way and what we need to do to keep respecting the needs of the WASM environment in the same way in the future. If the problem is that a user might need to depend on these items that are used in both
@Ralith @djc @mxinden thoughts on either of these suggestions? |
IMO the feature gating approach is okay even if it's not the cleanest. Personally, I feel like both alternatives (splitting out yet another smaller crate, or duplicating Would be good to get another round of @Ralith's review. |
Changes
cfg_alias
wasm_browser
forall(target_family = "wasm", target_os = "unknown")
(matchingwasm*-*-unknown
)socket2
a target-dependent dependencystd::net::UdpSocket
(e.g.Runtime::wrap_udp_socket
orEndpoint::rebind
) becomes gated asnot(wasm_browser)
web_time
as target-dependent dependency inquinn
to replacestd::time::{Instant, Duration}
, which panic in Wasm otherwise.Testing
Runtime
implementation in the browser and nodejs.I'm not contributing this test (yet?) as discussed.
(import "env" ...)
in thequinn
.wasm
file when built.This is a good, even if not quite sufficient effort in making sure the Wasm build doesn't break.