Skip to content

Commit

Permalink
Remove PluggableRuntime::default()
Browse files Browse the repository at this point in the history
We don't want this impl anymore, because the user should be forced to
supply the virtual task manager manually so they are cognizent of the
fact they WASIX is running on an async runtime.
  • Loading branch information
theduke committed Mar 20, 2023
1 parent 1f8e508 commit 71de958
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 28 deletions.
3 changes: 2 additions & 1 deletion lib/cli/src/commands/run/wasi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use virtual_fs::{DeviceFile, PassthruFileSystem, RootFileSystemBuilder};
use wasmer::{AsStoreMut, Instance, Module, RuntimeError, Value};
use wasmer_wasix::os::tty_sys::SysTty;
use wasmer_wasix::os::TtyBridge;
use wasmer_wasix::runtime::task_manager::tokio::TokioTaskManager;
use wasmer_wasix::types::__WASI_STDIN_FILENO;
use wasmer_wasix::{
default_fs_backing, get_wasi_versions, PluggableRuntime, WasiEnv, WasiError, WasiFunctionEnv,
Expand Down Expand Up @@ -129,7 +130,7 @@ impl Wasi {
.map(|(a, b)| (a.to_string(), b.to_string()))
.collect::<HashMap<_, _>>();

let mut rt = PluggableRuntime::default();
let mut rt = PluggableRuntime::new(Arc::new(TokioTaskManager::shared()));

if self.networking {
rt.set_networking_implementation(virtual_net::host::LocalNetworking::default());
Expand Down
6 changes: 3 additions & 3 deletions lib/wasi/src/bin_factory/module_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,13 +283,13 @@ impl ModuleCache {
#[cfg(test)]
#[cfg(feature = "sys")]
mod tests {
use std::time::Duration;
use std::{sync::Arc, time::Duration};

use tracing_subscriber::{
filter, prelude::__tracing_subscriber_SubscriberExt, util::SubscriberInitExt, Layer,
};

use crate::PluggableRuntime;
use crate::{runtime::task_manager::tokio::TokioTaskManager, PluggableRuntime};

use super::*;

Expand All @@ -306,7 +306,7 @@ mod tests {
let mut cache = ModuleCache::new(None, None, true);
cache.cache_time = std::time::Duration::from_millis(500);

let rt = PluggableRuntime::default();
let rt = PluggableRuntime::new(Arc::new(TokioTaskManager::shared()));
let tasks = rt.task_manager();

let mut store = Vec::new();
Expand Down
16 changes: 0 additions & 16 deletions lib/wasi/src/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,22 +141,6 @@ impl PluggableRuntime {
}
}

impl Default for PluggableRuntime {
#[cfg(feature = "sys-thread")]
fn default() -> Self {
let rt = task_manager::tokio::TokioTaskManager::shared();
let mut s = Self::new(Arc::new(rt));
let engine = wasmer::Store::default().engine().clone();
s.engine = Some(engine);
s
}

#[cfg(not(feature = "sys-thread"))]
fn default() -> Self {
unimplemented!("Default WasiRuntime is not implemented on this target")
}
}

impl WasiRuntime for PluggableRuntime {
fn networking(&self) -> &DynVirtualNetworking {
&self.networking
Expand Down
7 changes: 4 additions & 3 deletions lib/wasi/src/state/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use crate::{
fs::{WasiFs, WasiFsRoot, WasiInodes},
os::task::control_plane::{ControlPlaneConfig, ControlPlaneError, WasiControlPlane},
parse_static_webc,
runtime::task_manager::tokio::TokioTaskManager,
state::WasiState,
syscalls::types::{__WASI_STDERR_FILENO, __WASI_STDIN_FILENO, __WASI_STDOUT_FILENO},
PluggableRuntime, WasiEnv, WasiFunctionEnv, WasiRuntime, WasiRuntimeError,
Expand Down Expand Up @@ -722,9 +723,9 @@ impl WasiEnvBuilder {
}
}

let runtime = self
.runtime
.unwrap_or_else(|| Arc::new(PluggableRuntime::default()));
let runtime = self.runtime.unwrap_or_else(|| {
Arc::new(PluggableRuntime::new(Arc::new(TokioTaskManager::default())))
});

let uses = self.uses;
let map_commands = self.map_commands;
Expand Down
10 changes: 6 additions & 4 deletions lib/wasi/tests/stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ use std::sync::Arc;

use virtual_fs::{AsyncReadExt, AsyncWriteExt};
use wasmer::{Module, Store};
use wasmer_wasix::{Pipe, PluggableRuntime, WasiEnv};
use wasmer_wasix::{
runtime::task_manager::tokio::TokioTaskManager, Pipe, PluggableRuntime, WasiEnv,
};

mod sys {
#[tokio::test]
Expand Down Expand Up @@ -76,7 +78,7 @@ async fn test_stdout() {
// Create the `WasiEnv`.
let (stdout_tx, mut stdout_rx) = Pipe::channel();

let rt = PluggableRuntime::default();
let rt = PluggableRuntime::new(Arc::new(TokioTaskManager::shared()));

let builder = WasiEnv::builder("command-name")
.runtime(Arc::new(rt))
Expand Down Expand Up @@ -112,7 +114,7 @@ async fn test_env() {
builder.build()
});

let rt = PluggableRuntime::default();
let rt = PluggableRuntime::new(Arc::new(TokioTaskManager::shared()));

// Create the `WasiEnv`.
let (pipe_tx, mut pipe_rx) = Pipe::channel();
Expand Down Expand Up @@ -157,7 +159,7 @@ async fn test_stdin() {
let buf = "Hello, stdin!\n".as_bytes().to_owned();
pipe_tx.write_all(&buf[..]).await.unwrap();

let rt = PluggableRuntime::default();
let rt = PluggableRuntime::new(Arc::new(TokioTaskManager::shared()));

let builder = WasiEnv::builder("command-name")
.runtime(Arc::new(rt))
Expand Down
3 changes: 2 additions & 1 deletion tests/lib/wast/src/wasi_wast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use virtual_fs::{
AsyncWriteExt, FileSystem, Pipe, ReadBuf, RootFileSystemBuilder,
};
use wasmer::{FunctionEnv, Imports, Module, Store};
use wasmer_wasix::runtime::task_manager::tokio::TokioTaskManager;
use wasmer_wasix::types::wasi::{Filesize, Timestamp};
use wasmer_wasix::{
generate_import_object_from_env, get_wasi_version, FsError, PluggableRuntime, VirtualFile,
Expand Down Expand Up @@ -100,7 +101,7 @@ impl<'a> WasiTest<'a> {
out
};

let mut rt = PluggableRuntime::default();
let mut rt = PluggableRuntime::new(Arc::new(TokioTaskManager::shared()));
rt.set_engine(Some(store.engine().clone()));

let tasks = rt.task_manager().runtime().clone();
Expand Down

0 comments on commit 71de958

Please sign in to comment.