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
  • Loading branch information
elliottt committed Sep 27, 2023
1 parent e9f77e1 commit 0ef0823
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 25 deletions.
5 changes: 2 additions & 3 deletions crates/test-programs/tests/wasi-http-components-sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use wasmtime::{
Config, Engine, Store,
};
use wasmtime_wasi::preview2::{
command::sync::{add_to_linker, Command},
command::sync::Command,
pipe::MemoryOutputPipe,
IsATTY, Table, WasiCtx, WasiCtxBuilder, WasiView,
};
Expand Down Expand Up @@ -60,8 +60,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
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 0ef0823

Please sign in to comment.