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

wasmi_wasi: Update wasi-common and wiggle dependencies #1140

Merged
merged 3 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
638 changes: 282 additions & 356 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ exclude.workspace = true
anyhow = "1"
clap = { version = "4", features = ["derive"] }
wasmi = { workspace = true }
wasmi_wasi = { workspace = true, features = ["sync"] }
wasmi_wasi = { workspace = true }
wat = "1"

[dev-dependencies]
Expand Down
10 changes: 5 additions & 5 deletions crates/cli/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,20 +210,20 @@
pub fn wasi_context(&self) -> Result<WasiCtx, Error> {
let mut wasi_builder = WasiCtxBuilder::new();
for KeyValue { key, value } in &self.envs {
wasi_builder = wasi_builder.env(key, value)?;
wasi_builder.env(key, value)?;

Check warning on line 213 in crates/cli/src/args.rs

View check run for this annotation

Codecov / codecov/patch

crates/cli/src/args.rs#L213

Added line #L213 was not covered by tests
}
wasi_builder = wasi_builder.args(&self.argv())?;
wasi_builder.args(&self.argv())?;

Check warning on line 215 in crates/cli/src/args.rs

View check run for this annotation

Codecov / codecov/patch

crates/cli/src/args.rs#L215

Added line #L215 was not covered by tests
// Add pre-opened TCP sockets.
//
// Note that `num_fd` starts at 3 because the inherited `stdin`, `stdout` and `stderr`
// are already mapped to `0, 1, 2` respectively.
wasi_builder = wasi_builder.inherit_stdio();
wasi_builder.inherit_stdio();

Check warning on line 220 in crates/cli/src/args.rs

View check run for this annotation

Codecov / codecov/patch

crates/cli/src/args.rs#L220

Added line #L220 was not covered by tests
for (socket, num_fd) in self.preopen_sockets()?.into_iter().zip(3..) {
wasi_builder = wasi_builder.preopened_socket(num_fd, socket)?;
wasi_builder.preopened_socket(num_fd, socket)?;

Check warning on line 222 in crates/cli/src/args.rs

View check run for this annotation

Codecov / codecov/patch

crates/cli/src/args.rs#L222

Added line #L222 was not covered by tests
}
// Add pre-opened directories.
for (dir_name, dir) in self.preopen_dirs()? {
wasi_builder = wasi_builder.preopened_dir(dir, dir_name)?;
wasi_builder.preopened_dir(dir, dir_name)?;

Check warning on line 226 in crates/cli/src/args.rs

View check run for this annotation

Codecov / codecov/patch

crates/cli/src/args.rs#L226

Added line #L226 was not covered by tests
}
Ok(wasi_builder.build())
}
Expand Down
9 changes: 2 additions & 7 deletions crates/wasi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,9 @@ categories.workspace = true
exclude.workspace = true

[dependencies]
wasi-common = "2.0"
wasi-cap-std-sync = "2.0"
wiggle = { version = "2.0", default-features = false, features = ["wiggle_metadata"] }
wasi-common = { version = "24.0.0", default-features = false, features = ["sync"]}
wiggle = { version = "24.0.0", default-features = false }
wasmi = { workspace = true, features = ["std"]}

[dev-dependencies]
wat = "1.0.50"

[features]
default = ["sync"]
sync = []
8 changes: 3 additions & 5 deletions crates/wasi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@
//!
//! Use [`add_to_linker`] to add all supported WASI definitions to the Wasmi linker.

mod guest_memory;

#[cfg(feature = "sync")]
pub mod sync;

pub use self::guest_memory::WasmiGuestMemory;
pub use wasi_common::{Error, WasiCtx, WasiDir, WasiFile};
pub use wiggle::GuestMemory as WasmiGuestMemory;

/// Sync mode is the "default" of this crate, so we also export it at the top level.
#[cfg(feature = "sync")]
pub use sync::*;

pub use wasi_common;
2 changes: 1 addition & 1 deletion crates/wasi/src/sync/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

pub mod snapshots;

pub use wasi_cap_std_sync::*;
pub use wasi_common::sync::*;

#[doc(inline)]
pub use self::snapshots::preview_1::{
Expand Down
25 changes: 12 additions & 13 deletions crates/wasi/src/sync/snapshots/preview_1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
pin::Pin,
task::{Context, RawWaker, RawWakerVTable, Waker},
};
use wasi_common::{
snapshots::preview_1::wasi_snapshot_preview1::{UserErrorConversion, WasiSnapshotPreview1},
Error,
};
use wasi_common::{snapshots::preview_1::wasi_snapshot_preview1::WasiSnapshotPreview1, Error};
use wasmi::{state::Constructing, Caller, Extern, Linker, LinkerBuilder};

// Creates a dummy `RawWaker`. We can only create Wakers from `RawWaker`s
Expand Down Expand Up @@ -45,7 +42,7 @@
wasi_ctx: impl Fn(&mut T) -> &mut U + Send + Sync + Copy + 'static,
) -> Result<(), Error>
where
U: WasiSnapshotPreview1 + UserErrorConversion;
U: WasiSnapshotPreview1;
}

/// Adds the entire WASI API to the Wasmi [`Linker`].
Expand All @@ -66,7 +63,7 @@
wasi_ctx: impl Fn(&mut T) -> &mut U + Send + Sync + Copy + 'static,
) -> Result<(), Error>
where
U: WasiSnapshotPreview1 + UserErrorConversion,
U: WasiSnapshotPreview1,
{
<Linker<T> as AddWasi<T>>::add_wasi(linker, wasi_ctx)
}
Expand All @@ -79,7 +76,7 @@
wasi_ctx: impl Fn(&mut T) -> &mut U + Send + Sync + Copy + 'static,
) -> Result<(), Error>
where
U: WasiSnapshotPreview1 + UserErrorConversion,
U: WasiSnapshotPreview1,
{
<LinkerBuilder<Constructing, T> as AddWasi<T>>::add_wasi(linker, wasi_ctx)
}
Expand All @@ -100,7 +97,7 @@
wasi_ctx: impl Fn(&mut T) -> &mut U + Send + Sync + Copy + 'static,
) -> Result<(), Error>
where
U: WasiSnapshotPreview1 + UserErrorConversion,
U: WasiSnapshotPreview1,
{
$(
// $(#[$docs])* // TODO: find place for docs
Expand All @@ -115,16 +112,18 @@
};
let(memory, ctx) = memory.data_and_store_mut(&mut caller);
let ctx = wasi_ctx(ctx);
let memory = WasmiGuestMemory::new(memory);
match wasi_common::snapshots::preview_1::wasi_snapshot_preview1::$fname(ctx, &memory, $($arg,)*).await {
let mut memory = WasmiGuestMemory::Unshared(memory);
match wasi_common::snapshots::preview_1::wasi_snapshot_preview1::$fname(ctx, &mut memory, $($arg,)*).await {
Ok(r) => Ok(<$ret>::from(r)),
Err(wiggle::Trap::String(err)) => Err(wasmi::Error::new(err)),
Err(wiggle::Trap::I32Exit(i)) => Err(wasmi::Error::i32_exit(i)),
Err(e) => match e.downcast::<wasi_common::I32Exit>() {
Ok(wasi_common::I32Exit(status)) => Err(wasmi::Error::i32_exit(status)),
Err(e) => Err(wasmi::Error::new(e.to_string())),

Check warning on line 120 in crates/wasi/src/sync/snapshots/preview_1.rs

View check run for this annotation

Codecov / codecov/patch

crates/wasi/src/sync/snapshots/preview_1.rs#L118-L120

Added lines #L118 - L120 were not covered by tests
}
}
};
run_in_dummy_executor(result)?
}
)?;
).map_err(wiggle::anyhow::Error::from).map_err(wasi_common::Error::trap)?;

Check warning on line 126 in crates/wasi/src/sync/snapshots/preview_1.rs

View check run for this annotation

Codecov / codecov/patch

crates/wasi/src/sync/snapshots/preview_1.rs#L126

Added line #L126 was not covered by tests
)*
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion crates/wasi/tests/wasi_wat.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use wasi_cap_std_sync::WasiCtxBuilder;
use wasi_common::sync::WasiCtxBuilder;
use wasmi::{Config, Engine, Extern, Instance, Linker, Module, Store};
use wasmi_wasi::{add_to_linker, WasiCtx};

Expand Down
Loading