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(wasm): add support for the stable target wasm32-wasip2 #2453

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

brooksmtownsend
Copy link

@brooksmtownsend brooksmtownsend commented Oct 21, 2024

Fixes #2294

Depends on servo/rust-url#983

This PR, in order of commits:

  • Adds target conditionals to separate the compilation of reqwest in the general wasm32 OS and the wasm32-wasip2 target (which is now a tier 2 target and Rust stable in 1.82)
  • Adds .vscode to the .gitignore (I can remove this if it's undesired)
  • Adds wasm32-wasip2 implementations for reqwest so that you can compile WebAssembly components and make outgoing requests that compile down to wasi:http bindings
    - This commit also adds a patch for crates.io that depends on fix: support wasm32-wasip2 on the stable channel servo/rust-url#983, which is why this PR is a draft. There is no significant functionality change upstream to make the wasm32-wasip2 target work for the url crate, just a change to remove an unstable feature flag.
  • Adds an example wasm_component to illustrate how this crate can be used in the context of a wasm32-wasip2 program.

I've attempted to bring over the minimal implementations into the wasm32-wasip2 code, e.g. no multipart support, to keep the review focused and simple to start. If any of these need to be added, I'm happy to add follow-up commits after the review.

Signed-off-by: Brooks Townsend <brooksmtownsend@gmail.com>

refactor(wasm): add wasm mod

Signed-off-by: Brooks Townsend <brooksmtownsend@gmail.com>
Signed-off-by: Brooks Townsend <brooksmtownsend@gmail.com>
@brooksmtownsend brooksmtownsend force-pushed the feat/wasi-p2-component-stable-blocking branch from 1379d90 to 7edd47e Compare October 22, 2024 13:12
Signed-off-by: Brooks Townsend <brooksmtownsend@gmail.com>

cleanup extraneous comment

Signed-off-by: Brooks Townsend <brooksmtownsend@gmail.com>

feat: give back incoming body too

Signed-off-by: Brooks Townsend <brooksmtownsend@gmail.com>

deps(url): remove patch

Signed-off-by: Brooks Townsend <brooksmtownsend@gmail.com>
Signed-off-by: Brooks Townsend <brooksmtownsend@gmail.com>

example cleanup extra blocking feature

Signed-off-by: Brooks Townsend <brooksmtownsend@gmail.com>

use body example

Signed-off-by: Brooks Townsend <brooksmtownsend@gmail.com>

deps(url): remove patch

Signed-off-by: Brooks Townsend <brooksmtownsend@gmail.com>
@brooksmtownsend brooksmtownsend force-pushed the feat/wasi-p2-component-stable-blocking branch from 7edd47e to 3b3c99e Compare November 4, 2024 15:00
@brooksmtownsend
Copy link
Author

brooksmtownsend commented Dec 17, 2024

Apologies for letting this go stale here, I haven't had the time to really shore this one up. I think there's a lot of promise in this approach, and I also don't want to overindex on supporting wasi:http@0.2.0 if we could possibly support it using a combination of the stdlib and tokio in this crate.

I think in the shorter term what would make this PR a candidate for review and merging would either be:

  1. Integration into the async reqwest using a wasm-compatible async runtime (like tokio)
  2. Integration into the blocking reqwest as-is (which I've looked into, and may be more complicated than first meets the eye)

@jlizen
Copy link
Contributor

jlizen commented Dec 30, 2024

Integration into the async reqwest using a wasm-compatible async runtime (like tokio)

Something to call out is that at least some tokio features do break on wasm if naively depended on, ref #2509

Specifically, the use of the tokio timer seems to cause issues. You'll see that there is currently conditional compilation to keep wasm platforms from relying on tokio/time and tower/timeout. Just something to keep in mind if trying to pull wasm support into the async client, it'll take some refactoring.

Perhaps I'm lacking context and wasm32-wasip2 and this isn't an issue for that platform, which is cool if so. Anyway still will need to tweak the conditional compilation accordingly.

@pimeys
Copy link

pimeys commented Feb 18, 2025

The issue with this PR is that you can't really use this version with libraries depending on reqwest: all the IO here is sync and the native reqwest is not.

I've been looking into recently making reqwest to work without extra code in this crate. We can base the IO on mio and tokio, and what I have right now is kind of working reqwest that can connect to http hosts.

The issue is that we miss a TLS implementation we can use with wasip2. Ring or AWS will not link in wasip2, so that ended my exploration with just using modified mio and tokio to drive reqwest as it is today in main.

The question is what is the way forward. We naturally want to start using the async ecosystem in wasip2. And it is hard requirement for many crates that we must use tokio for some reason.

@pimeys
Copy link

pimeys commented Feb 18, 2025

@brooksmtownsend here's my past few days on the wasi async ecosystem written down, you might be interested:

https://gist.github.com/pimeys/856846ff8718247d79f1557ed82d80f7

My version does not do that many modifications in reqwest, most of the changes are in mio.

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.

Support WebAssembly Component bindings, aka wasip2, in addition to javascript bindings
3 participants