From 98f808af2c23966e49abc7b2556e40adddbb51b9 Mon Sep 17 00:00:00 2001 From: Andrew Clayton Date: Tue, 30 Jan 2024 14:44:11 +0000 Subject: Wasm-wc: Upgrade to wasmtime 17 This brings WASI 0.2.0 support. Link: Signed-off-by: Andrew Clayton --- src/wasm-wasi-component/Cargo.toml | 12 ++++++------ src/wasm-wasi-component/src/lib.rs | 21 +++++++++++---------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/wasm-wasi-component/Cargo.toml b/src/wasm-wasi-component/Cargo.toml index 8f42d128..feb7f53c 100644 --- a/src/wasm-wasi-component/Cargo.toml +++ b/src/wasm-wasi-component/Cargo.toml @@ -11,13 +11,13 @@ crate-type = ["cdylib"] anyhow = "1.0.75" bytes = "1.5.0" futures-util = { version = "0.3.29", default-features = false } -http = "0.2.9" -http-body = { version = "1.0.0-rc.2", default-features = false } -http-body-util = "0.1.0-rc.2" +http = "1.0.0" +http-body = { version = "1.0.0", default-features = false } +http-body-util = "0.1.0" tokio = { version = "1.33.0", default-features = false } -wasmtime = "14.0.2" -wasmtime-wasi = "14.0.2" -wasmtime-wasi-http = "14.0.2" +wasmtime = { version = "17.0.0", default-features = false, features = ['component-model', 'cranelift'] } +wasmtime-wasi = "17.0.0" +wasmtime-wasi-http = "17.0.0" [build-dependencies] bindgen = "0.68.1" diff --git a/src/wasm-wasi-component/src/lib.rs b/src/wasm-wasi-component/src/lib.rs index 032878f5..888074ab 100644 --- a/src/wasm-wasi-component/src/lib.rs +++ b/src/wasm-wasi-component/src/lib.rs @@ -7,12 +7,13 @@ use std::mem::MaybeUninit; use std::ptr; use std::sync::OnceLock; use tokio::sync::mpsc; -use wasmtime::component::{Component, InstancePre, Linker}; +use wasmtime::component::{Component, InstancePre, Linker, ResourceTable}; use wasmtime::{Config, Engine, Store}; use wasmtime_wasi::preview2::{ - DirPerms, FilePerms, Table, WasiCtx, WasiCtxBuilder, WasiView, + DirPerms, FilePerms, WasiCtx, WasiCtxBuilder, WasiView, }; use wasmtime_wasi::{ambient_authority, Dir}; +use wasmtime_wasi_http::bindings::http::types::ErrorCode; use wasmtime_wasi_http::{WasiHttpCtx, WasiHttpView}; #[allow( @@ -259,7 +260,7 @@ impl GlobalState { } cx.build() }, - table: Table::default(), + table: ResourceTable::default(), http: WasiHttpCtx, }; let mut store = Store::new(&self.engine, data); @@ -365,7 +366,7 @@ impl GlobalState { fn to_request_body( &self, info: &mut NxtRequestInfo, - ) -> BoxBody { + ) -> BoxBody { // TODO: should convert the body into a form of `Stream` to become an // async stream of frames. The return value can represent that here // but for now this slurps up the entire body into memory and puts it @@ -407,7 +408,7 @@ impl GlobalState { async fn send_response_body( &self, info: &mut NxtRequestInfo, - mut body: BoxBody, + mut body: BoxBody, ) -> Result<()> { loop { // Acquire the next frame, and because nothing is actually async @@ -415,7 +416,7 @@ impl GlobalState { // `Pending` case should not happen. let frame = match body.frame().await { Some(Ok(frame)) => frame, - Some(Err(e)) => break Err(e), + Some(Err(e)) => break Err(e.into()), None => break Ok(()), }; match frame.data_ref() { @@ -579,14 +580,14 @@ impl NxtRequestInfo { struct StoreState { ctx: WasiCtx, http: WasiHttpCtx, - table: Table, + table: ResourceTable, } impl WasiView for StoreState { - fn table(&self) -> &Table { + fn table(&self) -> &ResourceTable { &self.table } - fn table_mut(&mut self) -> &mut Table { + fn table_mut(&mut self) -> &mut ResourceTable { &mut self.table } fn ctx(&self) -> &WasiCtx { @@ -601,7 +602,7 @@ impl WasiHttpView for StoreState { fn ctx(&mut self) -> &mut WasiHttpCtx { &mut self.http } - fn table(&mut self) -> &mut Table { + fn table(&mut self) -> &mut ResourceTable { &mut self.table } } -- cgit