Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add documentation and refactor wasmtime-wasi #8228

Merged
merged 6 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions crates/wasi-http/src/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ wasmtime::component::bindgen!({

pub fn add_to_linker<T>(l: &mut wasmtime::component::Linker<T>) -> anyhow::Result<()>
where
T: WasiHttpView + wasmtime_wasi::WasiView + bindings::http::types::Host,
T: WasiHttpView + wasmtime_wasi::WasiView,
{
wasmtime_wasi::bindings::clocks::wall_clock::add_to_linker(l, |t| t)?;
wasmtime_wasi::bindings::clocks::monotonic_clock::add_to_linker(l, |t| t)?;
Expand Down Expand Up @@ -47,18 +47,24 @@ pub mod sync {
async: false,
with: {
"wasi:http": bindings::http, // http is in this crate
"wasi:io": wasmtime_wasi::bindings::sync_io, // io is sync
"wasi:io": wasmtime_wasi::bindings::sync, // io is sync
"wasi": wasmtime_wasi::bindings, // everything else
},
});

pub fn add_to_linker<T>(l: &mut wasmtime::component::Linker<T>) -> anyhow::Result<()>
where
T: WasiHttpView + wasmtime_wasi::WasiView + bindings::http::types::Host,
T: WasiHttpView + wasmtime_wasi::WasiView,
{
// TODO: this shouldn't be required, but the adapter unconditionally pulls in all of these
// dependencies.
wasmtime_wasi::command::sync::add_to_linker(l)?;
wasmtime_wasi::bindings::clocks::wall_clock::add_to_linker(l, |t| t)?;
wasmtime_wasi::bindings::clocks::monotonic_clock::add_to_linker(l, |t| t)?;
wasmtime_wasi::bindings::sync::io::poll::add_to_linker(l, |t| t)?;
wasmtime_wasi::bindings::sync::io::streams::add_to_linker(l, |t| t)?;
wasmtime_wasi::bindings::io::error::add_to_linker(l, |t| t)?;
wasmtime_wasi::bindings::cli::stdin::add_to_linker(l, |t| t)?;
wasmtime_wasi::bindings::cli::stdout::add_to_linker(l, |t| t)?;
wasmtime_wasi::bindings::cli::stderr::add_to_linker(l, |t| t)?;
wasmtime_wasi::bindings::random::random::add_to_linker(l, |t| t)?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be out of scope for this PR but: is there a reason we need to add all the interfaces manually here? The world in the Wit level groups all these interfaces together, so it seems like the host-side bindings should be able to group all these together as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main reason is that the auto-generated functions all take a closure that's fn(&mut T) -> &mut U but that's switched here to be T: WasiView. Otherwise though, you're right, and it's something I've wanted to clean up for awhile.


add_only_http_to_linker(l)?;

Expand Down
4 changes: 2 additions & 2 deletions crates/wasi-http/tests/all/async_.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::*;
use test_programs_artifacts::*;
use wasmtime_wasi::command::Command;
use wasmtime_wasi::bindings::Command;

foreach_http!(assert_test_exists);

Expand All @@ -13,7 +13,7 @@ async fn run(path: &str, server: &Server) -> Result<()> {
let component = Component::from_file(&engine, path)?;
let mut store = store(&engine, server);
let mut linker = Linker::new(&engine);
wasmtime_wasi::command::add_to_linker(&mut linker)?;
wasmtime_wasi::add_to_linker_async(&mut linker)?;
wasmtime_wasi_http::proxy::add_only_http_to_linker(&mut linker)?;
let (command, _instance) = Command::instantiate_async(&mut store, &component, &linker).await?;
let result = command.wasi_cli_run().call_run(&mut store).await?;
Expand Down
5 changes: 3 additions & 2 deletions crates/wasi-http/tests/all/sync.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::*;
use test_programs_artifacts::*;
use wasmtime_wasi::command::sync::Command;
use wasmtime_wasi::bindings::sync::Command;

foreach_http!(assert_test_exists);

Expand All @@ -12,7 +12,8 @@ fn run(path: &str, server: &Server) -> Result<()> {
let component = Component::from_file(&engine, path)?;
let mut store = store(&engine, server);
let mut linker = Linker::new(&engine);
wasmtime_wasi_http::proxy::sync::add_to_linker(&mut linker)?;
wasmtime_wasi::add_to_linker_sync(&mut linker)?;
wasmtime_wasi_http::proxy::sync::add_only_http_to_linker(&mut linker)?;
let (command, _instance) = Command::instantiate(&mut store, &component, &linker)?;
let result = command.wasi_cli_run().call_run(&mut store)?;
result.map_err(|()| anyhow::anyhow!("run returned an error"))
Expand Down
Loading