Skip to content

Commit

Permalink
Remove duplicate add_to_linker calls for preview2 interfaces
Browse files Browse the repository at this point in the history
prtest:full
  • Loading branch information
elliottt committed Sep 27, 2023
1 parent e9f77e1 commit 293930e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 38 deletions.
8 changes: 3 additions & 5 deletions crates/test-programs/tests/wasi-http-components-sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -60,8 +59,7 @@ fn instantiate_component(
ctx: Ctx,
) -> Result<(Store<Ctx>, 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);

Expand Down
5 changes: 1 addition & 4 deletions crates/test-programs/tests/wasi-http-components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -60,7 +58,6 @@ async fn instantiate_component(
ctx: Ctx,
) -> Result<(Store<Ctx>, 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);
Expand Down
11 changes: 0 additions & 11 deletions crates/test-programs/tests/wasi-http-proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,6 @@ async fn instantiate(component: Component, ctx: Ctx) -> Result<(Store<Ctx>, 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?;
Expand Down
24 changes: 6 additions & 18 deletions crates/wasi-http/src/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,9 @@ pub fn add_to_linker<T>(l: &mut wasmtime::component::Linker<T>) -> 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)?;
Expand Down Expand Up @@ -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)?;
Expand Down

0 comments on commit 293930e

Please sign in to comment.