diff --git a/tools/ci-cdk/canary-lambda/src/latest/wasm_canary.rs b/tools/ci-cdk/canary-lambda/src/latest/wasm_canary.rs index 4832a587466..1bf035d6d86 100644 --- a/tools/ci-cdk/canary-lambda/src/latest/wasm_canary.rs +++ b/tools/ci-cdk/canary-lambda/src/latest/wasm_canary.rs @@ -8,7 +8,7 @@ use crate::{mk_canary, CanaryEnv}; use aws_config::SdkConfig; use wasmtime::component::{bindgen, Component, Linker}; use wasmtime::{Engine, Store}; -use wasmtime_wasi::preview2::WasiCtxBuilder; +use wasmtime_wasi::WasiCtxBuilder; mk_canary!("wasm", |_sdk_config: &SdkConfig, _env: &CanaryEnv| { wasm_canary() @@ -22,25 +22,17 @@ bindgen!({ }); struct WasiHostCtx { - preview2_ctx: wasmtime_wasi::preview2::WasiCtx, + preview2_ctx: wasmtime_wasi::WasiCtx, preview2_table: wasmtime::component::ResourceTable, wasi_http_ctx: wasmtime_wasi_http::WasiHttpCtx, } -impl wasmtime_wasi::preview2::WasiView for WasiHostCtx { - fn table(&self) -> &wasmtime::component::ResourceTable { - &self.preview2_table - } - - fn ctx(&self) -> &wasmtime_wasi::preview2::WasiCtx { - &self.preview2_ctx - } - - fn table_mut(&mut self) -> &mut wasmtime::component::ResourceTable { +impl wasmtime_wasi::WasiView for WasiHostCtx { + fn table(&mut self) -> &mut wasmtime::component::ResourceTable { &mut self.preview2_table } - fn ctx_mut(&mut self) -> &mut wasmtime_wasi::preview2::WasiCtx { + fn ctx(&mut self) -> &mut wasmtime_wasi::WasiCtx { &mut self.preview2_ctx } } @@ -72,7 +64,8 @@ pub async fn wasm_canary() -> anyhow::Result<()> { // Create the linker and link in the necessary WASI bindings let mut linker: Linker = Linker::new(&engine); - link_all_the_things(&mut linker); + wasmtime_wasi::add_to_linker_async(&mut linker)?; + wasmtime_wasi_http::proxy::add_to_linker(&mut linker)?; // Configure and create a `WasiCtx`, which WASI functions need access to // through the host state of the store (which in this case is the host state @@ -84,8 +77,8 @@ pub async fn wasm_canary() -> anyhow::Result<()> { let host_ctx = WasiHostCtx { preview2_ctx: wasi_ctx, - preview2_table: wasmtime_wasi::preview2::ResourceTable::new(), - wasi_http_ctx: wasmtime_wasi_http::WasiHttpCtx {}, + preview2_table: wasmtime_wasi::ResourceTable::new(), + wasi_http_ctx: wasmtime_wasi_http::WasiHttpCtx::new(), }; let mut store: Store = Store::new(&engine, host_ctx); @@ -105,65 +98,6 @@ pub async fn wasm_canary() -> anyhow::Result<()> { Ok(()) } -/// This function adds all of the WASI bindings to the linker -fn link_all_the_things(linker: &mut Linker) { - //IO - wasmtime_wasi::preview2::bindings::io::poll::add_to_linker(linker, |cx| cx) - .expect("Failed to link Poll"); - wasmtime_wasi::preview2::bindings::io::error::add_to_linker(linker, |cx| cx) - .expect("Failed to link Error"); - wasmtime_wasi::preview2::bindings::io::streams::add_to_linker(linker, |cx| cx) - .expect("Failed to link Streams"); - - //Random - wasmtime_wasi::preview2::bindings::random::random::add_to_linker(linker, |cx| cx) - .expect("Failed to link Random"); - - //Clocks - wasmtime_wasi::preview2::bindings::wasi::clocks::monotonic_clock::add_to_linker(linker, |cx| { - cx - }) - .expect("Failed to link Clock"); - wasmtime_wasi::preview2::bindings::wasi::clocks::wall_clock::add_to_linker(linker, |cx| cx) - .expect("Failed to link Wall Clock"); - - //Filesystem - wasmtime_wasi::preview2::bindings::filesystem::types::add_to_linker(linker, |cx| cx) - .expect("Failed to link Filesystem Types"); - wasmtime_wasi::preview2::bindings::filesystem::preopens::add_to_linker(linker, |cx| cx) - .expect("Failed to link Filesystem Preopen"); - - //CLI - wasmtime_wasi::preview2::bindings::wasi::cli::environment::add_to_linker(linker, |cx| cx) - .expect("Failed to link Environment"); - wasmtime_wasi::preview2::bindings::wasi::cli::exit::add_to_linker(linker, |cx| cx) - .expect("Failed to link Environment"); - wasmtime_wasi::preview2::bindings::wasi::cli::stdin::add_to_linker(linker, |cx| cx) - .expect("Failed to link Stdin"); - wasmtime_wasi::preview2::bindings::wasi::cli::stdout::add_to_linker(linker, |cx| cx) - .expect("Failed to link Stdout"); - wasmtime_wasi::preview2::bindings::wasi::cli::stderr::add_to_linker(linker, |cx| cx) - .expect("Failed to link Stderr"); - - // CLI Terminal - wasmtime_wasi::preview2::bindings::wasi::cli::terminal_input::add_to_linker(linker, |cx| cx) - .expect("Failed to link Terminal Input"); - wasmtime_wasi::preview2::bindings::wasi::cli::terminal_output::add_to_linker(linker, |cx| cx) - .expect("Failed to link Terminal Output"); - wasmtime_wasi::preview2::bindings::wasi::cli::terminal_stdin::add_to_linker(linker, |cx| cx) - .expect("Failed to link Terminal Stdin"); - wasmtime_wasi::preview2::bindings::wasi::cli::terminal_stdout::add_to_linker(linker, |cx| cx) - .expect("Failed to link Terminal Stdout"); - wasmtime_wasi::preview2::bindings::wasi::cli::terminal_stderr::add_to_linker(linker, |cx| cx) - .expect("Failed to link Terminal Stderr"); - - //HTTP - wasmtime_wasi_http::bindings::http::types::add_to_linker(linker, |cx| cx) - .expect("Failed to link HTTP Types"); - wasmtime_wasi_http::bindings::http::outgoing_handler::add_to_linker(linker, |cx| cx) - .expect("Failed to link HTTP Outgoing Handler"); -} - // #[ignore] #[cfg(test)] #[tokio::test]