Skip to content

Commit d5746fd

Browse files
committed
fix(wasmtime-cli): link wasi:http
Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
1 parent a609f08 commit d5746fd

File tree

4 files changed

+88
-14
lines changed

4 files changed

+88
-14
lines changed

Cargo.lock

Lines changed: 71 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ wasmparser = { version = "0.219", default-features = false }
162162
wasmtime = { version = "26.0.1", default-features = false }
163163
wasmtime-cli-flags = { version = "26.0.1", default-features = false }
164164
wasmtime-wasi = { version = "26.0.1", default-features = false }
165+
wasmtime-wasi-http = { version = "26.0.1", default-features = false }
165166
wit-bindgen = { version = "0.34", default-features = false }
166167
wit-bindgen-core = { version = "0.34", default-features = false }
167168
wit-bindgen-wrpc = { version = "0.9", default-features = false, path = "./crates/wit-bindgen" }

crates/wasmtime-cli/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ wasmtime = { workspace = true, features = [
4545
"wat",
4646
] }
4747
wasmtime-wasi = { workspace = true }
48+
wasmtime-wasi-http = { workspace = true }
4849
wit-component = { workspace = true }
4950
wrpc-cli = { workspace = true, features = ["nats"] }
5051
wrpc-transport-nats = { workspace = true, features = ["async-nats-0_37"] }

crates/wasmtime-cli/src/lib.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ use wasi_preview1_component_adapter_provider::{
1919
};
2020
use wasmtime::component::{types, Component, InstancePre, Linker, ResourceType};
2121
use wasmtime::{Engine, Store};
22-
use wasmtime_wasi::{ResourceTable, WasiCtxBuilder};
23-
use wasmtime_wasi::{WasiCtx, WasiView};
22+
use wasmtime_wasi::{ResourceTable, WasiCtx, WasiCtxBuilder, WasiView};
23+
use wasmtime_wasi_http::{WasiHttpCtx, WasiHttpView};
2424
use wrpc_runtime_wasmtime::{
2525
collect_component_resources, link_item, ServeExt as _, SharedResourceTable, WrpcView,
2626
};
@@ -48,6 +48,7 @@ pub enum Workload {
4848
pub struct Ctx<C: Invoke> {
4949
pub table: ResourceTable,
5050
pub wasi: WasiCtx,
51+
pub http: WasiHttpCtx,
5152
pub wrpc: C,
5253
pub shared_resources: SharedResourceTable,
5354
pub timeout: Duration,
@@ -78,6 +79,15 @@ impl<C: Invoke> WasiView for Ctx<C> {
7879
}
7980
}
8081

82+
impl<C: Invoke> WasiHttpView for Ctx<C> {
83+
fn ctx(&mut self) -> &mut WasiHttpCtx {
84+
&mut self.http
85+
}
86+
fn table(&mut self) -> &mut ResourceTable {
87+
&mut self.table
88+
}
89+
}
90+
8191
#[instrument(level = "trace", skip(adapter, cx))]
8292
async fn instantiate_pre<C>(
8393
adapter: &[u8],
@@ -141,6 +151,8 @@ where
141151

142152
let mut linker = Linker::<Ctx<C>>::new(&engine);
143153
wasmtime_wasi::add_to_linker_async(&mut linker).context("failed to link WASI")?;
154+
wasmtime_wasi_http::add_only_http_to_linker_async(&mut linker)
155+
.context("failed to link `wasi:http`")?;
144156

145157
let ty = component.component_type();
146158
let mut resources = Vec::new();
@@ -280,6 +292,7 @@ fn new_store<C: Invoke>(
280292
.allow_udp(true)
281293
.args(&[arg0])
282294
.build(),
295+
http: WasiHttpCtx::new(),
283296
table: ResourceTable::new(),
284297
shared_resources: SharedResourceTable::default(),
285298
wrpc,

0 commit comments

Comments
 (0)