Skip to content

Commit

Permalink
Update and refactor the wasmi_wasi crate (#700)
Browse files Browse the repository at this point in the history
* bump wasmi_wasi version

* refactor the wasmi_wasi crate

It now mirrors the API of the wasmtime_wasi crate.

* update changelog
  • Loading branch information
Robbepop committed Mar 2, 2023
1 parent c95434f commit 223f815
Show file tree
Hide file tree
Showing 10 changed files with 767 additions and 533 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -21,6 +21,10 @@ Dates in this file are formattes as `YYYY-MM-DD`.

[`tail-call`]: https://github.com/WebAssembly/tail-call

### Changed

- The `wasmi_wasi` crate now more closely mirrors the `wasmtime_wasi` crate API. (https://github.com/paritytech/wasmi/pull/700)

### Internal

- Refactor the `wasmi` Wasm engine to handle Wasm calls and returns in its core. [(#694)]
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/Cargo.toml
Expand Up @@ -15,7 +15,7 @@ categories.workspace = true
anyhow = "1"
clap = { version = "4", features = ["derive"] }
wasmi = { version = "0.28.0", path = "../wasmi" }
wasmi_wasi = { version = "0.2.0", path = "../wasi" }
wasmi_wasi = { version = "0.3.0", path = "../wasi" }
wat = "1"

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/context.rs
Expand Up @@ -40,7 +40,7 @@ impl Context {
});
}
let mut linker = <wasmi::Linker<WasiCtx>>::new(&engine);
wasmi_wasi::define_wasi(&mut linker, &mut store, |ctx| ctx)
wasmi_wasi::add_to_linker(&mut linker, |ctx| ctx)
.map_err(|error| anyhow!("failed to add WASI definitions to the linker: {error}"))?;
let instance = linker
.instantiate(&mut store, &module)
Expand Down
6 changes: 5 additions & 1 deletion crates/wasi/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "wasmi_wasi"
version = "0.2.0"
version = "0.3.0"
documentation = "https://docs.rs/wasmi_wasi"
description = "WASI library support for the wasmi interpreter"
authors.workspace = true
Expand All @@ -19,3 +19,7 @@ wasmi = { version = "0.28.0", path = "../wasmi" }

[dev-dependencies]
wat = "1.0.50"

[features]
default = ["sync"]
sync = []
25 changes: 11 additions & 14 deletions crates/wasi/src/lib.rs
@@ -1,18 +1,15 @@
//! This crate provides support for WASI `preview1` for the `wasmi` interpreter.
//!
//! Use [`add_to_linker`] to add all supported WASI definitions to the `wasmi` linker.

mod guest_memory;
pub mod snapshots;

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

pub use self::guest_memory::WasmiGuestMemory;
pub use snapshots::preview_1::define_wasi;
pub use wasi_cap_std_sync::{
ambient_authority,
clocks,
file::{filetype_from, get_fd_flags, File},
net,
sched,
stdio,
Dir,
TcpListener,
WasiCtxBuilder,
};
pub use wasi_common::{Error, WasiCtx, WasiDir, WasiFile};
pub use wasmi::Linker;

/// Sync mode is the "default" of this crate, so we also export it at the top level.
#[cfg(feature = "sync")]
pub use sync::*;
514 changes: 0 additions & 514 deletions crates/wasi/src/snapshots/preview_1.rs

This file was deleted.

10 changes: 10 additions & 0 deletions crates/wasi/src/sync/mod.rs
@@ -0,0 +1,10 @@
//! Re-export the commonly used wasi-cap-std-sync crate here. This saves
//! consumers of this library from having to keep additional dependencies
//! in sync.

pub mod snapshots;

pub use wasi_cap_std_sync::*;

#[doc(inline)]
pub use self::snapshots::preview_1::add_wasi_snapshot_preview1_to_linker as add_to_linker;
File renamed without changes.

0 comments on commit 223f815

Please sign in to comment.