diff --git a/Cargo.lock b/Cargo.lock index 2c8d00dd..e30e0502 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -192,7 +192,7 @@ dependencies = [ "thiserror 1.0.68", "time", "tokio", - "tokio-rustls", + "tokio-rustls 0.26.0", "tokio-util", "tracing", "tryhard", @@ -226,7 +226,7 @@ dependencies = [ "thiserror 1.0.68", "time", "tokio", - "tokio-rustls", + "tokio-rustls 0.26.0", "tokio-util", "tracing", "tryhard", @@ -1371,7 +1371,7 @@ version = "0.1.0" dependencies = [ "anyhow", "clap", - "rustls", + "rustls 0.23.17", "tokio", "tracing-subscriber", "url", @@ -1389,7 +1389,7 @@ dependencies = [ "clap", "futures", "rcgen", - "rustls", + "rustls 0.23.17", "tokio", "tracing", "tracing-subscriber", @@ -1539,6 +1539,7 @@ dependencies = [ "pin-project-lite", "smallvec", "tokio", + "want", ] [[package]] @@ -2307,7 +2308,7 @@ dependencies = [ "quinn-proto", "quinn-udp", "rustc-hash", - "rustls", + "rustls 0.23.17", "socket2", "thiserror 2.0.3", "tokio", @@ -2325,7 +2326,7 @@ dependencies = [ "rand", "ring", "rustc-hash", - "rustls", + "rustls 0.23.17", "rustls-pki-types", "rustls-platform-verifier", "slab", @@ -2630,6 +2631,20 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "rustls" +version = "0.22.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf4ef73721ac7bcd79b2b315da7779d8fc09718c6b3d2d1b2d94850eb8c18432" +dependencies = [ + "log", + "ring", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + [[package]] name = "rustls" version = "0.23.17" @@ -2700,7 +2715,7 @@ dependencies = [ "jni", "log", "once_cell", - "rustls", + "rustls 0.23.17", "rustls-native-certs 0.7.3", "rustls-platform-verifier-android", "rustls-webpki", @@ -3329,13 +3344,24 @@ dependencies = [ "tokio", ] +[[package]] +name = "tokio-rustls" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "775e0c0f0adb3a2f22a00c4745d728b479985fc15ee7ca6a2608388c5569860f" +dependencies = [ + "rustls 0.22.4", + "rustls-pki-types", + "tokio", +] + [[package]] name = "tokio-rustls" version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" dependencies = [ - "rustls", + "rustls 0.23.17", "rustls-pki-types", "tokio", ] @@ -3720,7 +3746,7 @@ dependencies = [ "futures", "quinn", "rcgen", - "rustls", + "rustls 0.23.17", "tokio", "tracing", "tracing-subscriber", @@ -3787,7 +3813,7 @@ dependencies = [ "clap", "futures", "quinn", - "rustls", + "rustls 0.23.17", "tokio", "tower", "tower-http", @@ -4225,6 +4251,29 @@ dependencies = [ "windows-sys 0.59.0", ] +[[package]] +name = "wasmtime-wasi-http" +version = "26.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97b78cd40008a9b190625a23961e0cd1aff496bda5eda303d969f20e7bf2e33d" +dependencies = [ + "anyhow", + "async-trait", + "bytes", + "futures", + "http 1.1.0", + "http-body 1.0.1", + "http-body-util", + "hyper 1.5.0", + "rustls 0.22.4", + "tokio", + "tokio-rustls 0.25.0", + "tracing", + "wasmtime", + "wasmtime-wasi", + "webpki-roots", +] + [[package]] name = "wasmtime-winch" version = "26.0.1" @@ -4305,6 +4354,15 @@ dependencies = [ "rustls-pki-types", ] +[[package]] +name = "webpki-roots" +version = "0.26.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d642ff16b7e79272ae451b7322067cdc17cadf68c23264be9d94a32319efe7e" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "winapi" version = "0.3.9" @@ -4824,7 +4882,7 @@ dependencies = [ "async-nats 0.37.0", "quinn", "rcgen", - "rustls", + "rustls 0.23.17", "tokio", "tracing", "wrpc-cli", @@ -4951,6 +5009,7 @@ dependencies = [ "wasmparser 0.219.1", "wasmtime", "wasmtime-wasi", + "wasmtime-wasi-http", "wit-component", "wrpc-cli", "wrpc-runtime-wasmtime", @@ -4968,7 +5027,7 @@ dependencies = [ "pem", "quinn", "rcgen", - "rustls", + "rustls 0.23.17", "rustls-native-certs 0.8.0", "rustls-pemfile", "rustls-pki-types", diff --git a/Cargo.toml b/Cargo.toml index 568cfd45..95f23603 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -162,6 +162,7 @@ wasmparser = { version = "0.219", default-features = false } wasmtime = { version = "26.0.1", default-features = false } wasmtime-cli-flags = { version = "26.0.1", default-features = false } wasmtime-wasi = { version = "26.0.1", default-features = false } +wasmtime-wasi-http = { version = "26.0.1", default-features = false } wit-bindgen = { version = "0.34", default-features = false } wit-bindgen-core = { version = "0.34", default-features = false } wit-bindgen-wrpc = { version = "0.9", default-features = false, path = "./crates/wit-bindgen" } diff --git a/crates/wasmtime-cli/Cargo.toml b/crates/wasmtime-cli/Cargo.toml index d4df3dce..e46c928f 100644 --- a/crates/wasmtime-cli/Cargo.toml +++ b/crates/wasmtime-cli/Cargo.toml @@ -45,6 +45,7 @@ wasmtime = { workspace = true, features = [ "wat", ] } wasmtime-wasi = { workspace = true } +wasmtime-wasi-http = { workspace = true } wit-component = { workspace = true } wrpc-cli = { workspace = true, features = ["nats"] } wrpc-transport-nats = { workspace = true, features = ["async-nats-0_37"] } diff --git a/crates/wasmtime-cli/src/lib.rs b/crates/wasmtime-cli/src/lib.rs index de2efb83..c5cf9545 100644 --- a/crates/wasmtime-cli/src/lib.rs +++ b/crates/wasmtime-cli/src/lib.rs @@ -19,8 +19,8 @@ use wasi_preview1_component_adapter_provider::{ }; use wasmtime::component::{types, Component, InstancePre, Linker, ResourceType}; use wasmtime::{Engine, Store}; -use wasmtime_wasi::{ResourceTable, WasiCtxBuilder}; -use wasmtime_wasi::{WasiCtx, WasiView}; +use wasmtime_wasi::{ResourceTable, WasiCtx, WasiCtxBuilder, WasiView}; +use wasmtime_wasi_http::{WasiHttpCtx, WasiHttpView}; use wrpc_runtime_wasmtime::{ collect_component_resources, link_item, ServeExt as _, SharedResourceTable, WrpcView, }; @@ -48,6 +48,7 @@ pub enum Workload { pub struct Ctx { pub table: ResourceTable, pub wasi: WasiCtx, + pub http: WasiHttpCtx, pub wrpc: C, pub shared_resources: SharedResourceTable, pub timeout: Duration, @@ -78,6 +79,15 @@ impl WasiView for Ctx { } } +impl WasiHttpView for Ctx { + fn ctx(&mut self) -> &mut WasiHttpCtx { + &mut self.http + } + fn table(&mut self) -> &mut ResourceTable { + &mut self.table + } +} + #[instrument(level = "trace", skip(adapter, cx))] async fn instantiate_pre( adapter: &[u8], @@ -141,6 +151,8 @@ where let mut linker = Linker::>::new(&engine); wasmtime_wasi::add_to_linker_async(&mut linker).context("failed to link WASI")?; + wasmtime_wasi_http::add_only_http_to_linker_async(&mut linker) + .context("failed to link `wasi:http`")?; let ty = component.component_type(); let mut resources = Vec::new(); @@ -280,6 +292,7 @@ fn new_store( .allow_udp(true) .args(&[arg0]) .build(), + http: WasiHttpCtx::new(), table: ResourceTable::new(), shared_resources: SharedResourceTable::default(), wrpc,