Skip to content

Support WebAssembly Component bindings, aka wasip2, in addition to javascript bindings #2294

@brooksmtownsend

Description

@brooksmtownsend

The current wasm implementation supports compiling to wasm with wasm_bindgen, which is meant to provide bindings for usage from JavaScript in the browser. This aligns with many of the concepts from wasi_preview_1 and uses the browser's fetch() API to actually make the request. This works great for the browser, now there's tons of applications that want to use a higher level API for making requests from Wasm and run them on the server. The next iteration of WASI, wasi_preview_2, is the perfect basis for this.

WASI Preview 2 released earlier this year WebAssembly/WASI#577 with a common set of standard interfaces, including wasi-http which provides an interface both for incoming and outgoing HTTP requests. What I would love is for reqwest to support binding to wasi:http/outgoing-handler which would let Rust devs compile reqwest directly to a Wasm component targeting p2. I am a maintainer of wasmCloud which uses wasi-http for it's requests and, as you can see in this sample, using a higher level library in Rust greatly simplifies the code.

I opened #2290 to start implementing this but I think there's a couple of questions to answer:

  1. How do we want to gate compiling for the browser v.s. compiling to a component? Is it feature flags, and if so, which one is the default? (It's worth noting there is a specific target for components, wasm32-wasip2, however this is a new target and doesn't properly denote the difference between "browser" wasm and a component)
  2. Does feat(wasm): add support for wasip2, aka webassembly components, using wasi-http #2290 look reasonable or should we approach the problem differently? Most of the logic happens in the client's fetch function, and you can see the translation from the reqwest::Request and the wasi::http::OutgoingRequest.
  3. Do we like the file organization in feat(wasm): add support for wasip2, aka webassembly components, using wasi-http #2290 with the refactor or prefer for components to be a new folder? WASI Http module #1956 contains a reference implementation with slightly old bindings with a different file structure

This PR is essentially a duplicate of #1956, I just promised to open another issue so we can dedup as necessary.

I think this PR is related to #1977 but it might not entirely supercede it since there's a deeper discussion on abstraction.

Thanks @seanmonstar for being receptive to the issue + change. Looking forward to the discussion!

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-wasmArea: WASM.B-rfcBlocked: Request for comments. More discussion would help move this along.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions