Skip to content
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
461 changes: 193 additions & 268 deletions Cargo.lock

Large diffs are not rendered by default.

11 changes: 4 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,10 @@ members = [

[workspace.dependencies]
tracing = { version = "0.1", features = ["log"] }
wasmtime-wasi = { version = "9.0.4", features = ["tokio"] }
wasi-common-preview1 = { package = "wasi-common", version = "9.0.4" }
wasmtime = { version = "9.0.4", features = ["component-model"] }
spin-componentize = { git = "https://github.com/fermyon/spin-componentize", rev = "8a596f722556d17cc1dc9b3ae8a7e7a77d3e90ae" }
wasi-host = { package = "host", git = "https://github.com/fermyon/spin-componentize", rev = "8a596f722556d17cc1dc9b3ae8a7e7a77d3e90ae" }
wasi-common = { git = "https://github.com/fermyon/spin-componentize", rev = "8a596f722556d17cc1dc9b3ae8a7e7a77d3e90ae" }
wasi-cap-std-sync = { git = "https://github.com/fermyon/spin-componentize", rev = "8a596f722556d17cc1dc9b3ae8a7e7a77d3e90ae" }
wasmtime-wasi = { version = "10.0.0", features = ["tokio"] }
wasi-common-preview1 = { package = "wasi-common", version = "10.0.0" }
wasmtime = { version = "10.0.0", features = ["component-model"] }
spin-componentize = { git = "https://github.com/fermyon/spin-componentize", rev = "bdea058594f73edba21e12950b5f71a71244bac9" }

[workspace.dependencies.bindle]
git = "https://github.com/fermyon/bindle"
Expand Down
7 changes: 2 additions & 5 deletions crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,11 @@ anyhow = "1.0"
async-trait = "0.1"
crossbeam-channel = "0.5"
tracing = { workspace = true }
wasi-host = { workspace = true }
wasi-common = { workspace = true }
wasi-common-preview1 = { workspace = true }
wasi-cap-std-sync = { workspace = true }
wasmtime = { workspace = true }
wasmtime-wasi = { workspace = true }
wasi-common-preview1 = { workspace = true }
system-interface = { version = "0.25.1", features = ["cap_std_impls"] }
cap-std = "1.0.5"
cap-std = "1.0.13"

[target.'cfg(unix)'.dependencies]
rustix = "0.37.19"
Expand Down
4 changes: 2 additions & 2 deletions crates/core/src/io.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::sync::{Arc, RwLock};

use wasi_common::pipe::WritePipe;
use wasmtime_wasi::preview2::pipe::WritePipe;

/// An in-memory stdio output buffer.
#[derive(Default)]
Expand All @@ -19,7 +19,7 @@ impl OutputBuffer {

#[cfg(test)]
mod tests {
use wasi_common::OutputStream;
use wasmtime_wasi::preview2::OutputStream;

use super::*;

Expand Down
46 changes: 35 additions & 11 deletions crates/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,25 @@ mod store;
use std::{sync::Arc, time::Duration};

use anyhow::Result;
pub use async_trait::async_trait;
use crossbeam_channel::Sender;
use tracing::instrument;
pub use wasi_common::I32Exit;
use wasmtime_wasi::preview2::Table;

use self::host_component::{HostComponents, HostComponentsBuilder};

pub use async_trait::async_trait;
pub use wasmtime::{
self,
component::{Component, Instance},
Instance as ModuleInstance, Module, Trap,
};

use self::host_component::{HostComponents, HostComponentsBuilder};
pub use wasmtime_wasi::preview2::I32Exit;

pub use host_component::{
AnyHostComponentDataHandle, HostComponent, HostComponentDataHandle, HostComponentsData,
};
pub use io::OutputBuffer;
pub use store::{Store, StoreBuilder, Wasi};
pub use store::{Store, StoreBuilder, Wasi, WasiVersion};

/// The default [`EngineBuilder::epoch_tick_interval`].
pub const DEFAULT_EPOCH_TICK_INTERVAL: Duration = Duration::from_millis(10);
Expand Down Expand Up @@ -69,6 +71,7 @@ pub struct Data<T> {
wasi: Wasi,
host_components_data: HostComponentsData,
store_limits: limits::StoreLimitsAsync,
table: Table,
}

impl<T> Data<T> {
Expand All @@ -90,6 +93,30 @@ impl<T> AsMut<T> for Data<T> {
}
}

impl<T: Send> wasmtime_wasi::preview2::WasiView for Data<T> {
fn table(&self) -> &wasmtime_wasi::preview2::Table {
&self.table
}

fn table_mut(&mut self) -> &mut wasmtime_wasi::preview2::Table {
&mut self.table
}

fn ctx(&self) -> &wasmtime_wasi::preview2::WasiCtx {
match &self.wasi {
Wasi::Preview1(_) => panic!("using WASI Preview 1 functions with Preview 2 store"),
Wasi::Preview2(ctx) => ctx,
}
}

fn ctx_mut(&mut self) -> &mut wasmtime_wasi::preview2::WasiCtx {
match &mut self.wasi {
Wasi::Preview1(_) => panic!("using WASI Preview 1 functions with Preview 2 store"),
Wasi::Preview2(ctx) => ctx,
}
}
}

/// An alias for [`wasmtime::Linker`] specialized to [`Data`].
pub type ModuleLinker<T> = wasmtime::Linker<Data<T>>;

Expand All @@ -113,10 +140,7 @@ impl<T: Send + Sync> EngineBuilder<T> {
let engine = wasmtime::Engine::new(&config.inner)?;

let mut linker: Linker<T> = Linker::new(&engine);
wasi_host::command::add_to_linker(&mut linker, |data| match &mut data.wasi {
Wasi::Preview1(_) => panic!("using WASI Preview 1 functions with Preview 2 store"),
Wasi::Preview2(ctx) => ctx,
})?;
wasmtime_wasi::preview2::wasi::command::add_to_linker(&mut linker)?;

let mut module_linker = ModuleLinker::new(&engine);
wasmtime_wasi::tokio::add_to_linker(&mut module_linker, |data| match &mut data.wasi {
Expand Down Expand Up @@ -241,12 +265,12 @@ impl<T: Send + Sync> Engine<T> {
}

/// Creates a new [`StoreBuilder`].
pub fn store_builder(&self, wasi: Wasi) -> StoreBuilder {
pub fn store_builder(&self, wasi_version: WasiVersion) -> StoreBuilder {
StoreBuilder::new(
self.inner.clone(),
self.epoch_tick_interval,
&self.host_components,
wasi,
wasi_version,
)
}

Expand Down
Loading