Skip to content

Commit

Permalink
Rename WasiRuntime to Runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael-F-Bryan authored and theduke committed May 26, 2023
1 parent 36b077d commit 752f9ad
Show file tree
Hide file tree
Showing 23 changed files with 74 additions and 83 deletions.
2 changes: 1 addition & 1 deletion lib/cli/src/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ impl RunWithPathBuf {
use wasmer_wasix::{
bin_factory::BinaryPackage,
runners::{emscripten::EmscriptenRunner, wasi::WasiRunner, wcgi::WcgiRunner},
WasiRuntime,
Runtime,
};

let wasmer_dir = WasmerConfig::get_wasmer_dir().map_err(anyhow::Error::msg)?;
Expand Down
10 changes: 5 additions & 5 deletions lib/cli/src/commands/run/wasi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ use wasmer_wasix::{
},
types::__WASI_STDIN_FILENO,
wasmer_wasix_types::wasi::Errno,
PluggableRuntime, RewindState, WasiEnv, WasiEnvBuilder, WasiError, WasiFunctionEnv,
WasiRuntime, WasiVersion,
PluggableRuntime, RewindState, Runtime, WasiEnv, WasiEnvBuilder, WasiError, WasiFunctionEnv,
WasiVersion,
};

use crate::utils::{parse_envvar, parse_mapdir};
Expand Down Expand Up @@ -155,7 +155,7 @@ impl Wasi {
module: &Module,
program_name: String,
args: Vec<String>,
rt: Arc<dyn WasiRuntime + Send + Sync>,
rt: Arc<dyn Runtime + Send + Sync>,
) -> Result<WasiEnvBuilder> {
let args = args.into_iter().map(|arg| arg.into_bytes());

Expand Down Expand Up @@ -245,7 +245,7 @@ impl Wasi {
engine: Engine,
wasmer_dir: &Path,
handle: Handle,
) -> Result<impl WasiRuntime + Send + Sync> {
) -> Result<impl Runtime + Send + Sync> {
let mut rt = PluggableRuntime::new(Arc::new(TokioTaskManager::new(handle)));

if self.networking {
Expand Down Expand Up @@ -288,7 +288,7 @@ impl Wasi {
module: &Module,
program_name: String,
args: Vec<String>,
runtime: Arc<dyn WasiRuntime + Send + Sync>,
runtime: Arc<dyn Runtime + Send + Sync>,
store: &mut Store,
) -> Result<(WasiFunctionEnv, Instance)> {
let builder = self.prepare(module, program_name, args, runtime)?;
Expand Down
27 changes: 12 additions & 15 deletions lib/cli/src/commands/run_unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use wasmer_wasix::{
wasi::WasiRunner,
wcgi::{AbortHandle, WcgiRunner},
},
WasiRuntime,
Runtime,
};
use webc::{metadata::Manifest, v1::DirOrFile, Container};

Expand Down Expand Up @@ -118,7 +118,7 @@ impl RunUnstable {
fn execute_target(
&self,
executable_target: ExecutableTarget,
runtime: Arc<dyn WasiRuntime + Send + Sync>,
runtime: Arc<dyn Runtime + Send + Sync>,
store: &mut Store,
) -> Result<(), Error> {
match executable_target {
Expand All @@ -135,7 +135,7 @@ impl RunUnstable {
path: &Path,
module: &Module,
store: &mut Store,
runtime: Arc<dyn WasiRuntime + Send + Sync>,
runtime: Arc<dyn Runtime + Send + Sync>,
) -> Result<(), Error> {
if wasmer_emscripten::is_emscripten_module(module) {
self.execute_emscripten_module()
Expand All @@ -150,7 +150,7 @@ impl RunUnstable {
fn execute_webc(
&self,
pkg: &BinaryPackage,
runtime: Arc<dyn WasiRuntime + Send + Sync>,
runtime: Arc<dyn Runtime + Send + Sync>,
) -> Result<(), Error> {
let id = match self.entrypoint.as_deref() {
Some(cmd) => cmd,
Expand All @@ -177,10 +177,7 @@ impl RunUnstable {
}

#[tracing::instrument(skip_all)]
fn load_injected_packages(
&self,
runtime: &dyn WasiRuntime,
) -> Result<Vec<BinaryPackage>, Error> {
fn load_injected_packages(&self, runtime: &dyn Runtime) -> Result<Vec<BinaryPackage>, Error> {
let mut dependencies = Vec::new();

for name in &self.wasi.uses {
Expand All @@ -201,7 +198,7 @@ impl RunUnstable {
command_name: &str,
pkg: &BinaryPackage,
uses: Vec<BinaryPackage>,
runtime: Arc<dyn WasiRuntime + Send + Sync>,
runtime: Arc<dyn Runtime + Send + Sync>,
) -> Result<(), Error> {
let mut runner = wasmer_wasix::runners::wasi::WasiRunner::new()
.with_args(self.args.clone())
Expand All @@ -220,7 +217,7 @@ impl RunUnstable {
command_name: &str,
pkg: &BinaryPackage,
uses: Vec<BinaryPackage>,
runtime: Arc<dyn WasiRuntime + Send + Sync>,
runtime: Arc<dyn Runtime + Send + Sync>,
) -> Result<(), Error> {
let mut runner = wasmer_wasix::runners::wcgi::WcgiRunner::new();

Expand All @@ -243,7 +240,7 @@ impl RunUnstable {
&self,
command_name: &str,
pkg: &BinaryPackage,
runtime: Arc<dyn WasiRuntime + Send + Sync>,
runtime: Arc<dyn Runtime + Send + Sync>,
) -> Result<(), Error> {
let mut runner = wasmer_wasix::runners::emscripten::EmscriptenRunner::new();
runner.set_args(self.args.clone());
Expand Down Expand Up @@ -288,7 +285,7 @@ impl RunUnstable {
&self,
wasm_path: &Path,
module: &Module,
runtime: Arc<dyn WasiRuntime + Send + Sync>,
runtime: Arc<dyn Runtime + Send + Sync>,
store: &mut Store,
) -> Result<(), Error> {
let program_name = wasm_path.display().to_string();
Expand Down Expand Up @@ -417,7 +414,7 @@ impl PackageSource {
///
/// This will try to automatically download and cache any resources from the
/// internet.
fn resolve_target(&self, rt: &dyn WasiRuntime) -> Result<ExecutableTarget, Error> {
fn resolve_target(&self, rt: &dyn Runtime) -> Result<ExecutableTarget, Error> {
match self {
PackageSource::File(path) => ExecutableTarget::from_file(path, rt),
PackageSource::Dir(d) => ExecutableTarget::from_dir(d, rt),
Expand Down Expand Up @@ -498,7 +495,7 @@ impl ExecutableTarget {
/// Try to load a Wasmer package from a directory containing a `wasmer.toml`
/// file.
#[tracing::instrument(skip_all)]
fn from_dir(dir: &Path, runtime: &dyn WasiRuntime) -> Result<Self, Error> {
fn from_dir(dir: &Path, runtime: &dyn Runtime) -> Result<Self, Error> {
let mut files = BTreeMap::new();
load_files_from_disk(&mut files, dir, dir)?;

Expand Down Expand Up @@ -526,7 +523,7 @@ impl ExecutableTarget {

/// Try to load a file into something that can be used to run it.
#[tracing::instrument(skip_all)]
fn from_file(path: &Path, runtime: &dyn WasiRuntime) -> Result<Self, Error> {
fn from_file(path: &Path, runtime: &dyn Runtime) -> Result<Self, Error> {
match TargetOnDisk::from_file(path)? {
TargetOnDisk::WebAssemblyBinary | TargetOnDisk::Wat => {
let wasm = std::fs::read(path)?;
Expand Down
9 changes: 3 additions & 6 deletions lib/wasi/src/bin_factory/binary_package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
module_cache::ModuleHash,
resolver::{PackageId, PackageInfo, PackageSpecifier},
},
WasiRuntime,
Runtime,
};

#[derive(Derivative, Clone)]
Expand Down Expand Up @@ -76,10 +76,7 @@ pub struct BinaryPackage {
impl BinaryPackage {
/// Load a [`webc::Container`] and all its dependencies into a
/// [`BinaryPackage`].
pub async fn from_webc(
container: &Container,
rt: &dyn WasiRuntime,
) -> Result<Self, anyhow::Error> {
pub async fn from_webc(container: &Container, rt: &dyn Runtime) -> Result<Self, anyhow::Error> {
let source = rt.source();
let root = PackageInfo::from_manifest(container.manifest())?;
let root_id = PackageId {
Expand All @@ -100,7 +97,7 @@ impl BinaryPackage {
/// Load a [`BinaryPackage`] and all its dependencies from a registry.
pub async fn from_registry(
specifier: &PackageSpecifier,
runtime: &dyn WasiRuntime,
runtime: &dyn Runtime,
) -> Result<Self, anyhow::Error> {
let source = runtime.source();
let root_summary = source.latest(specifier).await?;
Expand Down
6 changes: 3 additions & 3 deletions lib/wasi/src/bin_factory/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ use wasmer::{Function, FunctionEnvMut, Memory32, Memory64, Module, Store};
use wasmer_wasix_types::wasi::Errno;

use super::{BinFactory, BinaryPackage};
use crate::{runtime::SpawnMemoryType, WasiEnv, WasiFunctionEnv, WasiRuntime};
use crate::{runtime::SpawnMemoryType, Runtime, WasiEnv, WasiFunctionEnv};

#[tracing::instrument(level = "trace", skip_all, fields(%name, %binary.package_name))]
pub async fn spawn_exec(
binary: BinaryPackage,
name: &str,
store: Store,
env: WasiEnv,
runtime: &Arc<dyn WasiRuntime + Send + Sync + 'static>,
runtime: &Arc<dyn Runtime + Send + Sync + 'static>,
) -> Result<TaskJoinHandle, SpawnError> {
let key = binary.hash();

Expand Down Expand Up @@ -73,7 +73,7 @@ pub async fn spawn_exec(
pub fn spawn_exec_module(
module: Module,
env: WasiEnv,
runtime: &Arc<dyn WasiRuntime + Send + Sync + 'static>,
runtime: &Arc<dyn Runtime + Send + Sync + 'static>,
) -> Result<TaskJoinHandle, SpawnError> {
// Create a new task manager
let tasks = runtime.task_manager();
Expand Down
10 changes: 5 additions & 5 deletions lib/wasi/src/bin_factory/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,25 @@ pub use self::{
binary_package::*,
exec::{spawn_exec, spawn_exec_module},
};
use crate::{os::command::Commands, WasiRuntime};
use crate::{os::command::Commands, Runtime};

#[derive(Debug, Clone)]
pub struct BinFactory {
pub(crate) commands: Commands,
runtime: Arc<dyn WasiRuntime + Send + Sync + 'static>,
runtime: Arc<dyn Runtime + Send + Sync + 'static>,
pub(crate) local: Arc<RwLock<HashMap<String, Option<BinaryPackage>>>>,
}

impl BinFactory {
pub fn new(runtime: Arc<dyn WasiRuntime + Send + Sync + 'static>) -> BinFactory {
pub fn new(runtime: Arc<dyn Runtime + Send + Sync + 'static>) -> BinFactory {
BinFactory {
commands: Commands::new_with_builtins(runtime.clone()),
runtime,
local: Arc::new(RwLock::new(HashMap::new())),
}
}

pub fn runtime(&self) -> &dyn WasiRuntime {
pub fn runtime(&self) -> &dyn Runtime {
self.runtime.deref()
}

Expand Down Expand Up @@ -97,7 +97,7 @@ impl BinFactory {
async fn load_package_from_filesystem(
fs: &dyn FileSystem,
path: &Path,
rt: &dyn WasiRuntime,
rt: &dyn Runtime,
) -> Result<BinaryPackage, anyhow::Error> {
let mut f = fs
.new_open_options()
Expand Down
4 changes: 2 additions & 2 deletions lib/wasi/src/http/client_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::string::FromUtf8Error;
use std::sync::Arc;

use crate::bindings::wasix_http_client_v1 as sys;
use crate::{capabilities::Capabilities, WasiRuntime};
use crate::{capabilities::Capabilities, Runtime};

use crate::{
http::{DynHttpClient, HttpClientCapabilityV1},
Expand All @@ -29,7 +29,7 @@ impl std::fmt::Display for sys::Method<'_> {

pub struct WasixHttpClientImpl {
cap: Capabilities,
runtime: Arc<dyn WasiRuntime + Send + Sync>,
runtime: Arc<dyn Runtime + Send + Sync>,
}

impl WasixHttpClientImpl {
Expand Down
2 changes: 1 addition & 1 deletion lib/wasi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ pub use crate::{
rewind::*,
runtime::{
task_manager::{VirtualTaskManager, VirtualTaskManagerExt},
PluggableRuntime, WasiRuntime,
PluggableRuntime, Runtime,
},
state::{
WasiEnv, WasiEnvBuilder, WasiEnvInit, WasiFunctionEnv, WasiInstanceHandles,
Expand Down
6 changes: 3 additions & 3 deletions lib/wasi/src/os/command/builtins/cmd_wasmer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use wasmer_wasix_types::wasi::Errno;
use crate::{
bin_factory::{spawn_exec, BinaryPackage},
syscalls::stderr_write,
VirtualTaskManagerExt, WasiEnv, WasiRuntime,
Runtime, VirtualTaskManagerExt, WasiEnv,
};

const HELP: &str = r#"USAGE:
Expand All @@ -35,13 +35,13 @@ use crate::os::command::VirtualCommand;

#[derive(Debug, Clone)]
pub struct CmdWasmer {
runtime: Arc<dyn WasiRuntime + Send + Sync + 'static>,
runtime: Arc<dyn Runtime + Send + Sync + 'static>,
}

impl CmdWasmer {
const NAME: &str = "wasmer";

pub fn new(runtime: Arc<dyn WasiRuntime + Send + Sync + 'static>) -> Self {
pub fn new(runtime: Arc<dyn Runtime + Send + Sync + 'static>) -> Self {
Self { runtime }
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/wasi/src/os/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{collections::HashMap, sync::Arc};
use wasmer::{FunctionEnvMut, Store};
use wasmer_wasix_types::wasi::Errno;

use crate::{syscalls::stderr_write, SpawnError, WasiEnv, WasiRuntime};
use crate::{syscalls::stderr_write, Runtime, SpawnError, WasiEnv};

use super::task::{OwnedTaskStatus, TaskJoinHandle, TaskStatus};

Expand Down Expand Up @@ -43,7 +43,7 @@ impl Commands {
}

// TODO: this method should be somewhere on the runtime, not here.
pub fn new_with_builtins(runtime: Arc<dyn WasiRuntime + Send + Sync + 'static>) -> Self {
pub fn new_with_builtins(runtime: Arc<dyn Runtime + Send + Sync + 'static>) -> Self {
let mut cmd = Self::new();
let cmd_wasmer = builtins::cmd_wasmer::CmdWasmer::new(runtime.clone());
cmd.register_command(cmd_wasmer);
Expand Down
9 changes: 3 additions & 6 deletions lib/wasi/src/os/console/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use crate::{
capabilities::Capabilities,
os::task::{control_plane::WasiControlPlane, process::WasiProcess},
runtime::resolver::PackageSpecifier,
SpawnError, VirtualTaskManagerExt, WasiEnv, WasiRuntime,
Runtime, SpawnError, VirtualTaskManagerExt, WasiEnv,
};

#[derive(Derivative)]
Expand All @@ -46,7 +46,7 @@ pub struct Console {
no_welcome: bool,
prompt: String,
env: HashMap<String, String>,
runtime: Arc<dyn WasiRuntime + Send + Sync + 'static>,
runtime: Arc<dyn Runtime + Send + Sync + 'static>,
stdin: ArcBoxFile,
stdout: ArcBoxFile,
stderr: ArcBoxFile,
Expand All @@ -55,10 +55,7 @@ pub struct Console {
}

impl Console {
pub fn new(
webc_boot_package: &str,
runtime: Arc<dyn WasiRuntime + Send + Sync + 'static>,
) -> Self {
pub fn new(webc_boot_package: &str, runtime: Arc<dyn Runtime + Send + Sync + 'static>) -> Self {
let prog = webc_boot_package
.split_once(' ')
.map(|a| a.1)
Expand Down
4 changes: 2 additions & 2 deletions lib/wasi/src/runners/emscripten.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use wasmer_emscripten::{
};
use webc::metadata::{annotations::Emscripten, Command};

use crate::{bin_factory::BinaryPackage, WasiRuntime};
use crate::{bin_factory::BinaryPackage, Runtime};

#[derive(Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
pub struct EmscriptenRunner {
Expand Down Expand Up @@ -53,7 +53,7 @@ impl crate::runners::Runner for EmscriptenRunner {
&mut self,
command_name: &str,
pkg: &BinaryPackage,
runtime: Arc<dyn WasiRuntime + Send + Sync>,
runtime: Arc<dyn Runtime + Send + Sync>,
) -> Result<(), Error> {
let cmd = pkg
.get_command(command_name)
Expand Down
4 changes: 2 additions & 2 deletions lib/wasi/src/runners/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use wasmer::Module;

use crate::runtime::{
module_cache::{CacheError, ModuleHash},
WasiRuntime,
Runtime,
};

/// A directory that should be mapped from the host filesystem into a WASI
Expand All @@ -28,7 +28,7 @@ pub struct MappedDirectory {
}

/// Compile a module, trying to use a pre-compiled version if possible.
pub(crate) fn compile_module(wasm: &[u8], runtime: &dyn WasiRuntime) -> Result<Module, Error> {
pub(crate) fn compile_module(wasm: &[u8], runtime: &dyn Runtime) -> Result<Module, Error> {
// TODO(Michael-F-Bryan,theduke): This should be abstracted out into some
// sort of ModuleResolver component that is attached to the runtime and
// encapsulates finding a WebAssembly binary, compiling it, and caching.
Expand Down
Loading

0 comments on commit 752f9ad

Please sign in to comment.