Skip to content

Commit

Permalink
feat(wasi): make WasiCtx overridable (bytecodealliance#3895)
Browse files Browse the repository at this point in the history
In some use cases it is desirable to provide a custom snapshot WASI
context. Facilitate this by depending on a combination of traits
required rather than concrete type in the signature.

Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
  • Loading branch information
rvolosatovs authored Mar 7, 2022
1 parent 7c3dd33 commit e81d4ce
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions crates/wasi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,16 @@ macro_rules! define_wasi {

use wasmtime::Linker;

pub fn add_to_linker<T>(
pub fn add_to_linker<T, U>(
linker: &mut Linker<T>,
get_cx: impl Fn(&mut T) -> &mut crate::WasiCtx + Send + Sync + Copy + 'static,
get_cx: impl Fn(&mut T) -> &mut U + Send + Sync + Copy + 'static,
) -> anyhow::Result<()>
where $($bounds)*
where U: Send
+ wasi_common::snapshots::preview_0::wasi_unstable::WasiUnstable
+ wasi_common::snapshots::preview_0::types::UserErrorConversion
+ wasi_common::snapshots::preview_1::wasi_snapshot_preview1::WasiSnapshotPreview1
+ wasi_common::snapshots::preview_1::types::UserErrorConversion,
$($bounds)*
{
snapshots::preview_1::add_wasi_snapshot_preview1_to_linker(linker, get_cx)?;
snapshots::preview_0::add_wasi_unstable_to_linker(linker, get_cx)?;
Expand Down

0 comments on commit e81d4ce

Please sign in to comment.