Wasm-wc: Upgrade to wasmtime 17

This brings WASI 0.2.0 support.

Link: <https://github.com/bytecodealliance/wasmtime/releases/tag/v17.0.0>
Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
This commit is contained in:
Andrew Clayton
2024-01-30 14:44:11 +00:00
parent ac3a54d671
commit 98f808af2c
2 changed files with 17 additions and 16 deletions

View File

@@ -11,13 +11,13 @@ crate-type = ["cdylib"]
anyhow = "1.0.75" anyhow = "1.0.75"
bytes = "1.5.0" bytes = "1.5.0"
futures-util = { version = "0.3.29", default-features = false } futures-util = { version = "0.3.29", default-features = false }
http = "0.2.9" http = "1.0.0"
http-body = { version = "1.0.0-rc.2", default-features = false } http-body = { version = "1.0.0", default-features = false }
http-body-util = "0.1.0-rc.2" http-body-util = "0.1.0"
tokio = { version = "1.33.0", default-features = false } tokio = { version = "1.33.0", default-features = false }
wasmtime = "14.0.2" wasmtime = { version = "17.0.0", default-features = false, features = ['component-model', 'cranelift'] }
wasmtime-wasi = "14.0.2" wasmtime-wasi = "17.0.0"
wasmtime-wasi-http = "14.0.2" wasmtime-wasi-http = "17.0.0"
[build-dependencies] [build-dependencies]
bindgen = "0.68.1" bindgen = "0.68.1"

View File

@@ -7,12 +7,13 @@ use std::mem::MaybeUninit;
use std::ptr; use std::ptr;
use std::sync::OnceLock; use std::sync::OnceLock;
use tokio::sync::mpsc; use tokio::sync::mpsc;
use wasmtime::component::{Component, InstancePre, Linker}; use wasmtime::component::{Component, InstancePre, Linker, ResourceTable};
use wasmtime::{Config, Engine, Store}; use wasmtime::{Config, Engine, Store};
use wasmtime_wasi::preview2::{ use wasmtime_wasi::preview2::{
DirPerms, FilePerms, Table, WasiCtx, WasiCtxBuilder, WasiView, DirPerms, FilePerms, WasiCtx, WasiCtxBuilder, WasiView,
}; };
use wasmtime_wasi::{ambient_authority, Dir}; use wasmtime_wasi::{ambient_authority, Dir};
use wasmtime_wasi_http::bindings::http::types::ErrorCode;
use wasmtime_wasi_http::{WasiHttpCtx, WasiHttpView}; use wasmtime_wasi_http::{WasiHttpCtx, WasiHttpView};
#[allow( #[allow(
@@ -259,7 +260,7 @@ impl GlobalState {
} }
cx.build() cx.build()
}, },
table: Table::default(), table: ResourceTable::default(),
http: WasiHttpCtx, http: WasiHttpCtx,
}; };
let mut store = Store::new(&self.engine, data); let mut store = Store::new(&self.engine, data);
@@ -365,7 +366,7 @@ impl GlobalState {
fn to_request_body( fn to_request_body(
&self, &self,
info: &mut NxtRequestInfo, info: &mut NxtRequestInfo,
) -> BoxBody<Bytes, anyhow::Error> { ) -> BoxBody<Bytes, ErrorCode> {
// TODO: should convert the body into a form of `Stream` to become an // TODO: should convert the body into a form of `Stream` to become an
// async stream of frames. The return value can represent that here // 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 // 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( async fn send_response_body(
&self, &self,
info: &mut NxtRequestInfo, info: &mut NxtRequestInfo,
mut body: BoxBody<Bytes, anyhow::Error>, mut body: BoxBody<Bytes, ErrorCode>,
) -> Result<()> { ) -> Result<()> {
loop { loop {
// Acquire the next frame, and because nothing is actually async // Acquire the next frame, and because nothing is actually async
@@ -415,7 +416,7 @@ impl GlobalState {
// `Pending` case should not happen. // `Pending` case should not happen.
let frame = match body.frame().await { let frame = match body.frame().await {
Some(Ok(frame)) => frame, Some(Ok(frame)) => frame,
Some(Err(e)) => break Err(e), Some(Err(e)) => break Err(e.into()),
None => break Ok(()), None => break Ok(()),
}; };
match frame.data_ref() { match frame.data_ref() {
@@ -579,14 +580,14 @@ impl NxtRequestInfo {
struct StoreState { struct StoreState {
ctx: WasiCtx, ctx: WasiCtx,
http: WasiHttpCtx, http: WasiHttpCtx,
table: Table, table: ResourceTable,
} }
impl WasiView for StoreState { impl WasiView for StoreState {
fn table(&self) -> &Table { fn table(&self) -> &ResourceTable {
&self.table &self.table
} }
fn table_mut(&mut self) -> &mut Table { fn table_mut(&mut self) -> &mut ResourceTable {
&mut self.table &mut self.table
} }
fn ctx(&self) -> &WasiCtx { fn ctx(&self) -> &WasiCtx {
@@ -601,7 +602,7 @@ impl WasiHttpView for StoreState {
fn ctx(&mut self) -> &mut WasiHttpCtx { fn ctx(&mut self) -> &mut WasiHttpCtx {
&mut self.http &mut self.http
} }
fn table(&mut self) -> &mut Table { fn table(&mut self) -> &mut ResourceTable {
&mut self.table &mut self.table
} }
} }