From a58214f2be5f265283c8c86d08e3c965fb0973cb Mon Sep 17 00:00:00 2001 From: Trevor Elliott Date: Wed, 27 Sep 2023 13:44:49 -0700 Subject: [PATCH] Remove duplicate add_to_linker calls for preview2 interfaces prtest:all --- .../tests/wasi-http-components-sync.rs | 8 +++---- .../tests/wasi-http-components.rs | 5 +--- crates/test-programs/tests/wasi-http-proxy.rs | 11 --------- crates/wasi-http/src/proxy.rs | 24 +++++-------------- 4 files changed, 10 insertions(+), 38 deletions(-) diff --git a/crates/test-programs/tests/wasi-http-components-sync.rs b/crates/test-programs/tests/wasi-http-components-sync.rs index 33c638fc6883..222fc800edce 100644 --- a/crates/test-programs/tests/wasi-http-components-sync.rs +++ b/crates/test-programs/tests/wasi-http-components-sync.rs @@ -4,9 +4,8 @@ use wasmtime::{ Config, Engine, Store, }; use wasmtime_wasi::preview2::{ - command::sync::{add_to_linker, Command}, - pipe::MemoryOutputPipe, - IsATTY, Table, WasiCtx, WasiCtxBuilder, WasiView, + command::sync::Command, pipe::MemoryOutputPipe, IsATTY, Table, WasiCtx, WasiCtxBuilder, + WasiView, }; use wasmtime_wasi_http::{WasiHttpCtx, WasiHttpView}; @@ -60,8 +59,7 @@ fn instantiate_component( ctx: Ctx, ) -> Result<(Store, Command), anyhow::Error> { let mut linker = Linker::new(&ENGINE); - add_to_linker(&mut linker)?; - wasmtime_wasi_http::proxy::add_to_linker(&mut linker)?; + wasmtime_wasi_http::proxy::sync::add_to_linker(&mut linker)?; let mut store = Store::new(&ENGINE, ctx); diff --git a/crates/test-programs/tests/wasi-http-components.rs b/crates/test-programs/tests/wasi-http-components.rs index 8d1fa1f96c52..11fb6bd498ca 100644 --- a/crates/test-programs/tests/wasi-http-components.rs +++ b/crates/test-programs/tests/wasi-http-components.rs @@ -4,9 +4,7 @@ use wasmtime::{ Config, Engine, Store, }; use wasmtime_wasi::preview2::{ - command::{add_to_linker, Command}, - pipe::MemoryOutputPipe, - IsATTY, Table, WasiCtx, WasiCtxBuilder, WasiView, + command::Command, pipe::MemoryOutputPipe, IsATTY, Table, WasiCtx, WasiCtxBuilder, WasiView, }; use wasmtime_wasi_http::{WasiHttpCtx, WasiHttpView}; @@ -60,7 +58,6 @@ async fn instantiate_component( ctx: Ctx, ) -> Result<(Store, Command), anyhow::Error> { let mut linker = Linker::new(&ENGINE); - add_to_linker(&mut linker)?; wasmtime_wasi_http::proxy::add_to_linker(&mut linker)?; let mut store = Store::new(&ENGINE, ctx); diff --git a/crates/test-programs/tests/wasi-http-proxy.rs b/crates/test-programs/tests/wasi-http-proxy.rs index 49acdd5a4806..f344dc15071f 100644 --- a/crates/test-programs/tests/wasi-http-proxy.rs +++ b/crates/test-programs/tests/wasi-http-proxy.rs @@ -59,17 +59,6 @@ async fn instantiate(component: Component, ctx: Ctx) -> Result<(Store, Prox let mut linker = Linker::new(&ENGINE); wasmtime_wasi_http::proxy::add_to_linker(&mut linker)?; - // due to the preview1 adapter - preview2::bindings::filesystem::types::add_to_linker(&mut linker, |l| l)?; - preview2::bindings::filesystem::preopens::add_to_linker(&mut linker, |l| l)?; - preview2::bindings::cli::environment::add_to_linker(&mut linker, |l| l)?; - preview2::bindings::cli::exit::add_to_linker(&mut linker, |l| l)?; - preview2::bindings::cli::terminal_input::add_to_linker(&mut linker, |l| l)?; - preview2::bindings::cli::terminal_output::add_to_linker(&mut linker, |l| l)?; - preview2::bindings::cli::terminal_stdin::add_to_linker(&mut linker, |l| l)?; - preview2::bindings::cli::terminal_stdout::add_to_linker(&mut linker, |l| l)?; - preview2::bindings::cli::terminal_stderr::add_to_linker(&mut linker, |l| l)?; - let mut store = Store::new(&ENGINE, ctx); let (proxy, _instance) = Proxy::instantiate_async(&mut store, &component, &linker).await?; diff --git a/crates/wasi-http/src/proxy.rs b/crates/wasi-http/src/proxy.rs index 1100589a6da0..b276a6545265 100644 --- a/crates/wasi-http/src/proxy.rs +++ b/crates/wasi-http/src/proxy.rs @@ -25,15 +25,9 @@ pub fn add_to_linker(l: &mut wasmtime::component::Linker) -> anyhow::Resul where T: WasiHttpView + preview2::WasiView + bindings::http::types::Host, { - preview2::bindings::clocks::wall_clock::add_to_linker(l, |t| t)?; - preview2::bindings::clocks::monotonic_clock::add_to_linker(l, |t| t)?; - preview2::bindings::clocks::timezone::add_to_linker(l, |t| t)?; - preview2::bindings::poll::poll::add_to_linker(l, |t| t)?; - preview2::bindings::io::streams::add_to_linker(l, |t| t)?; - preview2::bindings::random::random::add_to_linker(l, |t| t)?; - preview2::bindings::cli::stdout::add_to_linker(l, |t| t)?; - preview2::bindings::cli::stderr::add_to_linker(l, |t| t)?; - preview2::bindings::cli::stdin::add_to_linker(l, |t| t)?; + // TODO: this shouldn't be required, but the adapter unconditionally pulls in all of these + // dependencies. + preview2::command::add_to_linker(l)?; bindings::http::outgoing_handler::add_to_linker(l, |t| t)?; bindings::http::types::add_to_linker(l, |t| t)?; @@ -69,15 +63,9 @@ pub mod sync { where T: WasiHttpView + preview2::WasiView + bindings::http::types::Host, { - preview2::bindings::clocks::wall_clock::add_to_linker(l, |t| t)?; - preview2::bindings::clocks::monotonic_clock::add_to_linker(l, |t| t)?; - preview2::bindings::clocks::timezone::add_to_linker(l, |t| t)?; - preview2::bindings::io::streams::add_to_linker(l, |t| t)?; - preview2::bindings::random::random::add_to_linker(l, |t| t)?; - preview2::bindings::random::random::add_to_linker(l, |t| t)?; - preview2::bindings::cli::stdout::add_to_linker(l, |t| t)?; - preview2::bindings::cli::stderr::add_to_linker(l, |t| t)?; - preview2::bindings::cli::stdin::add_to_linker(l, |t| t)?; + // TODO: this shouldn't be required, but the adapter unconditionally pulls in all of these + // dependencies. + preview2::command::sync::add_to_linker(l)?; bindings::http::outgoing_handler::add_to_linker(l, |t| t)?; bindings::http::types::add_to_linker(l, |t| t)?;