From ca28025e134fe82b7d98de9109dccac4d7f54798 Mon Sep 17 00:00:00 2001 From: Scott Andrews Date: Fri, 4 Dec 2026 00:13:25 +0000 Subject: [PATCH] Revert client component to wasm32-unknown-unknown We don't actually need component model threading or wasip3. Signed-off-by: Scott Andrews --- Cargo.lock | 2 +- components/client/Cargo.toml | 8 +------- components/client/src/lib.rs | 37 +++++++++++++++--------------------- 3 files changed, 17 insertions(+), 30 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e60ba5a..a82e551 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -136,7 +136,6 @@ dependencies = [ "test-harness", "tokio", "url", - "wasip3-rt", "wasmtime", "wit-bindgen", ] @@ -2600,6 +2599,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b85a987ab61d365382d25c7d47e26edd48941b3bf6e3fbf76eff918bc71dab06" dependencies = [ "bitflags", + "futures", "wit-bindgen-rust-macro", ] diff --git a/components/client/Cargo.toml b/components/client/Cargo.toml index acdc5cf..501eabc 100644 --- a/components/client/Cargo.toml +++ b/components/client/Cargo.toml @@ -9,15 +9,9 @@ crate-type = ["cdylib"] [dependencies] url = { version = "2.5", default-features = false } -# without std, see crates/wasip3-rt -wasip3-rt = { workspace = true } -wit-bindgen = { version = "0.63.0", default-features = false, features = ["macros", "realloc", "async"] } +wit-bindgen = { workspace = true, features = ["async-spawn"] } [dev-dependencies] test-harness = { workspace = true } tokio = { workspace = true } wasmtime = { workspace = true } - -[package.metadata.componentized] -# built for wasm32-wasip3, see build/components.mk -target = "wasm32-wasip3" diff --git a/components/client/src/lib.rs b/components/client/src/lib.rs index 0d3c920..81fd2f3 100644 --- a/components/client/src/lib.rs +++ b/components/client/src/lib.rs @@ -1,14 +1,4 @@ -//! Without std, see crates/wasip3-rt. - -#![no_std] - -extern crate alloc; - -use alloc::format; -use alloc::string::{String, ToString}; -use alloc::vec::Vec; use url::Url; -use wasip3_rt as _; wit_bindgen::generate!({ path: "../wit", @@ -311,21 +301,25 @@ fn read_fields(fields: &Fields) -> Vec<(String, String)> { .collect() } +/// The trailers of a response, as a future that resolves once the caller has read the body. +/// +/// The WASI trailers resolve after the body is consumed, which the caller does after the response +/// is returned, so they're mapped in a task spawned into the export's task, which keeps running +/// after the export returns. fn map_trailers( wasi: FutureReader, WasiErrorCode>>, ) -> FutureReader, TrailersErrorCode>> { let (tx, rx) = wit_future::new(|| Ok(Vec::new())); - wasip3_rt::spawn(move || { - wit_bindgen::block_on(async move { - let resolved = match wasi.await { - Ok(Some(t)) => Ok(read_fields(&t)), - Ok(None) => Ok(Vec::new()), - Err(e) => Err(TrailersErrorCode::Other(Some(format!( - "wasi:http error: {e:?}" - )))), - }; - tx.write(resolved); - }) + wit_bindgen::spawn_local(async move { + let resolved = match wasi.await { + Ok(Some(t)) => Ok(read_fields(&t)), + Ok(None) => Ok(Vec::new()), + Err(e) => Err(TrailersErrorCode::Other(Some(format!( + "wasi:http error: {e:?}" + )))), + }; + // the caller dropped the trailers when the write fails, nothing is waiting for them + let _ = tx.write(resolved).await; }); rx } @@ -458,7 +452,6 @@ export!(HttpClient); #[cfg(test)] mod tests { use super::*; - use alloc::vec; fn location(value: &str) -> Vec<(String, String)> { vec![("Location".to_string(), value.to_string())]