Skip to content
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-proto): Make compilable in wasm32-unknown-unknown and run wasm tests in CI #1996

Merged
merged 1 commit into from
Nov 8, 2024

Conversation

matheus23
Copy link
Contributor

@matheus23 matheus23 commented Sep 26, 2024

Summary of Changes

  • Use web_time dependency instead of std::time & re-export Instant, Duration, SystemTime and UNIX_EPOCH in lib.rs so imports are simpler
  • Adjust imports to use crate::{Instant, Duration, ...} instead of std::time::{Instant, Duration, ...}
  • Added wasm-bindgen-test to enable running tests from a Wasm build
  • Added a CI task to test quinn-proto tests in Wasm with node.js

Running quinn-proto tests in Wasm

# install wasm-bindgen-test-runner
$ cargo install wasm-bindgen-cli
# run tests
$ cargo test -p quinn-proto --target wasm32-unknown-unknown
Old open questions, now resolved
  • Should the added code/dependencies additionally be feature-gated?

    I personally don't think so. As far as I know, there's practically no one asking for wasm32-unknown-unknown compilability who isn't targeting nodejs/browsers/cloudflare workers/etc. and in all of these cases wasm-bindgen is the de-facto standard.
    There's also targeting wasmtime and other runtimes, but IMO those needs are met by wasm32-wasi-* targets, not wasm32-unknown-unknown.

    That said, for my intents and purposes that's mostly a cosmetic question, I don't mind having to enable another feature flag. Other concerns could be "what non-web wasm32-unknown-unknown becomes a thing and we need to break compatibility by introducing features?".

  • Should the Duration, Instant, etc. re-exports live in lib.rs?

    They're pub(crate) only, so I don't think it matters much. I can move them into a file if you want, or we keep them here.

  • Should we just depend on web_time instead of std::time everywhere instead of cfg-gating & re-exporting?

    web_time itself already multiplexes between std::time and a web-based implementation. So in a way, we're doing it twice here. What we gain is not depending on web_time most of the time.
    However, once we work on Wasm support for e.g. quinn itself, we'd need to do this whole re-export dance, again. So perhaps it'd be better to just depend on web_time everywhere?

Copy link
Member

@djc djc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this looks like a reasonable direction!

Please squash all the changes into a single commit, as these commits are not conceptually separate.

Cargo.toml Outdated Show resolved Hide resolved
quinn-proto/Cargo.toml Outdated Show resolved Hide resolved
.github/workflows/rust.yml Outdated Show resolved Hide resolved
.github/workflows/rust.yml Show resolved Hide resolved
@matheus23 matheus23 force-pushed the matheus23/quinn-proto-wasm branch 2 times, most recently from 0fb3ba0 to 2d5dfde Compare October 1, 2024 08:50
Copy link
Member

@djc djc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking pretty good!

quinn-proto/src/tests/mod.rs Outdated Show resolved Hide resolved
@matheus23
Copy link
Contributor Author

Thanks for the review. Thoughts on this open question?

Should we just depend on web_time instead of std::time everywhere instead of cfg-gating & re-exporting?

I'm on the fence. I think it may be better to depend on web_time on all targets. Otherwise I'll be repeating the same lib.rs changes in quinn itself (to avoid having quinn_proto::Duration be a public reexport).

@djc
Copy link
Member

djc commented Oct 15, 2024

Should we just depend on web_time instead of std::time everywhere instead of cfg-gating & re-exporting?

I'm on the fence. I think it may be better to depend on web_time on all targets. Otherwise I'll be repeating the same lib.rs changes in quinn itself (to avoid having quinn_proto::Duration be a public reexport).

I'm inclined to stick with depending on web_time only for WASM targets. IMO mainstream platforms should not bear the cost of niche platforms even if the overhead is small. @Ralith any thoughts?

@matheus23
Copy link
Contributor Author

@djc @Ralith what's left to do here to get this over the finish line?
I'd love to also contribute quinn wasm32-unknown-unknown support after this.

Copy link
Member

@djc djc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, please squash the commits?

@djc djc requested a review from Ralith October 25, 2024 09:21
@Ralith
Copy link
Collaborator

Ralith commented Oct 25, 2024

I'm inclined to stick with depending on web_time only for WASM targets. IMO mainstream platforms should not bear the cost of niche platforms even if the overhead is small. @Ralith any thoughts?

Given that the amount of extra code is pretty trivial, this stance seems reasonable to me. I know I'd be a bit confused as a non-web user to see a web crate show up in my environment.

Copy link
Collaborator

@Ralith Ralith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The wasm_bindgen_test churn is unfortunate, but I guess there's nothing for it.

@djc
Copy link
Member

djc commented Oct 25, 2024

@matheus23 this is currently failing the WASM test, I guess that's not supposed to be intentional?

@Ralith Ralith mentioned this pull request Oct 25, 2024
@matheus23 matheus23 force-pushed the matheus23/quinn-proto-wasm branch 3 times, most recently from dc4dcb2 to 7b2af82 Compare October 26, 2024 20:57
@matheus23
Copy link
Contributor Author

Seems like there's potentially some ring issues with wasm32.
Investigating this. Also need to make sure that main doesn't have any commits added that regress wasm32 support (So I need to merge in main continuously).

@matheus23
Copy link
Contributor Author

matheus23 commented Nov 5, 2024

Okay, got to somewhat of the bottom on this. The stacktraces you saw were v8 crashing for some reason.
Updating nodejs from 18 to 20 fixes the issue.
Will update the PR now. There's also some tricks I learned along the way that make the diff nicer and the workflow faster.

@matheus23
Copy link
Contributor Author

Also seems like cc version 1.1.32 broke the ring Wasm build (but in github actions only?).
I've submitted an upstream issue and forced version 1.1.31 in CI for now.

@matheus23 matheus23 force-pushed the matheus23/quinn-proto-wasm branch 3 times, most recently from aa9559d to 75a1b3c Compare November 6, 2024 12:59
@matheus23
Copy link
Contributor Author

FWIW, this PR is ready from my perspective. Is there anything left to do? Do you want to re-review?

@djc djc added this pull request to the merge queue Nov 8, 2024
@djc
Copy link
Member

djc commented Nov 8, 2024

Thanks, this is looking good!

Merged via the queue into quinn-rs:main with commit a0d8985 Nov 8, 2024
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants