Stream: general

Topic: Adding wasi-http support in the AWS Rust SDK


view this post on Zulip Landon James (Feb 02 2024 at 19:49):

Hello, I'm with AWS and on a sister team with the AWS Rust SDK. I'm working with them to get this PR adding wasi support merged (authored by @Eduardo Rodrigues ). Have a few questions since it seems like preview2 is finalized and published now:

Motivation and Context #2087 This is a continuation of PR #2254, it will replace the mocked HTTP client with one based on the WASI HTTP proposal. Description A separate crate called aws-smithy-wasm...

view this post on Zulip Alex Crichton (Feb 02 2024 at 20:10):

I'm working to update the wasi crate on crates.io to 0.12.0 in which is intended to be an "official" place to pull in generated bindings from

When the preview2 target is published how does this strategy change?

Publication is probably going to Rust 1.78 if everything goes according to plan (watch for updates here).

That won't change what you write in crates but it'll change your build process. Today where you use wasm32-wasi then wasm-tools component new tomorrow you'd just build with the wasi 0.2 target and a component would pop out.

Do we no longer need to explicitly pull in the http_client from that crate because it is compiled in with the wasi-sdk?

I'm not 100% sure what you mean by the http_client crate, but I think the answer to your question is "you'd write the same code" and your build process would be the main thing to change

This is a complete redesign of the crate for #71. This commit removes the old wasi_snapshot_preview1 interfaces (still available in the 0.11.x release track of this crate of course) and uses wit-bi...
This is the initial implementation of the MCP rust-lang/compiler-team#694 creating a new tier 3 target wasm32-wasi-preview2. That MCP has been seconded and will most likely be approved in a little ...

view this post on Zulip Alex Crichton (Feb 02 2024 at 20:11):

I'll note that the wasi 0.2 target in rustc is intended to be tier 3 to start while we develop it, so if you want to rely on something I'd stick to the wasi 0.1 ("preview1") target for the time being

view this post on Zulip Eduardo Rodrigues (Feb 02 2024 at 21:21):

@Landon James The original http_client feature is located here (but not up-to-date with WASI v0.2.0 as you noted):
https://github.com/bytecodealliance/preview2-prototyping/blob/main/wasi/src/http_client.rs

view this post on Zulip Eduardo Rodrigues (Feb 02 2024 at 21:25):

I would stick with the suggestion provided by Alex (using the binding from the wasi crate). You can take the example from the previously implemented crate (to convert from wasi shapes to the rust http) and from the tests at wastime here: https://github.com/bytecodealliance/wasmtime/blob/main/crates/wasi-http/tests/all/main.rs

view this post on Zulip Landon James (Feb 05 2024 at 19:57):

Awesome, thank you both for the pointers! I'll get started on it once the changes to the wasi crate are published.

view this post on Zulip Landon James (Feb 13 2024 at 03:43):

Alright, updated questions. I'm almost done with this and am just updating the tests. I've updated the wasmtime dependency to 17.0.0 and custom test runner to :

[target.wasm32-wasi]
runner = [
    "wasmtime",
    "-C", "cache=n",
    "-S", "preview2=y",
    "-S", "http=y"
]

Which does attempt to run the binary with wasmtime, but this fails with Error: Cannot enable wasi-http for core wasm modules and that makes sense because nothing in the cargo test pipeline runs wasm-tools component new on the resulting core wasm module. Seems like this will be fixed with wasm32-wasi-preview2 which will by default output a component.

Until that is ready does anyone know of a good way of getting the componentization into a cargo test pipeline without doing too much custom work?

Also, just want to check my assumption that since I am consuming the wasi::http module via the wasi crate I no longer need to manually include the wasi:http wit files directly in my project?

view this post on Zulip Peter Huene (Feb 13 2024 at 04:44):

cargo-component supports a test subcommand; I can't say if that's suitable for what you need or not

view this post on Zulip Landon James (Feb 13 2024 at 20:02):

Ahh perfect, cargo-component did exactly what I need, thank you!


Last updated: Dec 23 2024 at 12:05 UTC