Skip to content

Commit

Permalink
fix(wasmtime-cli): link wasi:http
Browse files Browse the repository at this point in the history
Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
  • Loading branch information
rvolosatovs committed Nov 22, 2024
1 parent a609f08 commit da407d0
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 14 deletions.
83 changes: 71 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
1 change: 1 addition & 0 deletions crates/wasmtime-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
17 changes: 15 additions & 2 deletions crates/wasmtime-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -48,6 +48,7 @@ pub enum Workload {
pub struct Ctx<C: Invoke> {
pub table: ResourceTable,
pub wasi: WasiCtx,
pub http: WasiHttpCtx,
pub wrpc: C,
pub shared_resources: SharedResourceTable,
pub timeout: Duration,
Expand Down Expand Up @@ -78,6 +79,15 @@ impl<C: Invoke> WasiView for Ctx<C> {
}
}

impl<C: Invoke> WasiHttpView for Ctx<C> {
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<C>(
adapter: &[u8],
Expand Down Expand Up @@ -141,6 +151,8 @@ where

let mut linker = Linker::<Ctx<C>>::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();
Expand Down Expand Up @@ -280,6 +292,7 @@ fn new_store<C: Invoke>(
.allow_udp(true)
.args(&[arg0])
.build(),
http: WasiHttpCtx::new(),
table: ResourceTable::new(),
shared_resources: SharedResourceTable::default(),
wrpc,
Expand Down

0 comments on commit da407d0

Please sign in to comment.