diff --git a/Cargo.lock b/Cargo.lock index 97f698e00..557c3bde2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3847,7 +3847,9 @@ dependencies = [ "wasmer-inline-c", "wasmer-middlewares", "wasmer-types", + "wasmer-vfs", "wasmer-wasi", + "webc", ] [[package]] @@ -3900,6 +3902,7 @@ dependencies = [ "fern", "http_req", "log", + "nuke-dir", "prettytable-rs", "regex", "serde_json", @@ -3927,6 +3930,7 @@ dependencies = [ "wasmer-wasi", "wasmer-wasi-experimental-io-devices", "wasmer-wast", + "webc", ] [[package]] diff --git a/lib/c-api/Cargo.toml b/lib/c-api/Cargo.toml index e5dfd80de..547faae7c 100644 --- a/lib/c-api/Cargo.toml +++ b/lib/c-api/Cargo.toml @@ -31,6 +31,8 @@ wasmer-compiler = { version = "=3.0.0-rc.1", path = "../compiler" } wasmer-middlewares = { version = "=3.0.0-rc.1", path = "../middlewares", optional = true } wasmer-wasi = { version = "=3.0.0-rc.1", path = "../wasi", default-features = false, features = ["host-fs", "sys"], optional = true } wasmer-types = { version = "=3.0.0-rc.1", path = "../types" } +wasmer-vfs = { version = "=3.0.0-rc.1", path = "../vfs", optional = true, default-features = false, features = ["static-fs", "mem-fs"] } +webc = { version = "3.0.0", optional = true } enumset = "1.0.2" cfg-if = "1.0" lazy_static = "1.4" @@ -90,7 +92,7 @@ wasmer-artifact-load = ["wasmer-compiler/wasmer-artifact-load"] wasmer-artifact-create = ["wasmer-compiler/wasmer-artifact-create"] static-artifact-load = ["wasmer-compiler/static-artifact-load"] static-artifact-create = ["wasmer-compiler/static-artifact-create"] -webc_runner = ["wasmer-api/webc_runner"] +webc_runner = ["wasmer-api/webc_runner", "wasmer-vfs", "webc"] # Deprecated features. jit = ["compiler"] diff --git a/lib/c-api/src/wasm_c_api/wasi/mod.rs b/lib/c-api/src/wasm_c_api/wasi/mod.rs index b11faf8de..1da58a700 100644 --- a/lib/c-api/src/wasm_c_api/wasi/mod.rs +++ b/lib/c-api/src/wasm_c_api/wasi/mod.rs @@ -23,7 +23,7 @@ use std::{ io::{self, SeekFrom}, sync::MutexGuard, }; -#[cfg(feature = "pirita_file")] +#[cfg(feature = "webc_runner")] use wasmer_api::{AsStoreMut, Imports, Module}; use wasmer_wasi::{ get_wasi_version, FsError, VirtualFile, WasiBidirectionalPipePair, WasiFile, WasiFunctionEnv, @@ -846,7 +846,7 @@ pub unsafe extern "C" fn wasi_filesystem_delete(ptr: *mut wasi_filesystem_t) { /// Initializes the `imports` with an import object that links to /// the custom file system -#[cfg(feature = "pirita_file")] +#[cfg(feature = "webc_runner")] #[no_mangle] pub unsafe extern "C" fn wasi_env_with_filesystem( config: Box, @@ -859,7 +859,7 @@ pub unsafe extern "C" fn wasi_env_with_filesystem( wasi_env_with_filesystem_inner(config, store, module, fs, imports, package) } -#[cfg(feature = "pirita_file")] +#[cfg(feature = "webc_runner")] unsafe fn wasi_env_with_filesystem_inner( config: Box, store: Option<&mut wasm_store_t>, @@ -892,7 +892,7 @@ unsafe fn wasi_env_with_filesystem_inner( })) } -#[cfg(feature = "pirita_file")] +#[cfg(feature = "webc_runner")] fn prepare_webc_env( config: Box, store: &mut impl AsStoreMut, @@ -901,11 +901,11 @@ fn prepare_webc_env( len: usize, package_name: &str, ) -> Option<(WasiFunctionEnv, Imports)> { - use pirita::FsEntryType; - use pirita::StaticFileSystem; + use wasmer_vfs::static_fs::StaticFileSystem; + use webc::FsEntryType; let slice = unsafe { std::slice::from_raw_parts(bytes, len) }; - let volumes = pirita::PiritaFile::parse_volumes_from_fileblock(slice).ok()?; + let volumes = webc::WebC::parse_volumes_from_fileblock(slice).ok()?; let top_level_dirs = volumes .into_iter() .flat_map(|(_, volume)| { @@ -924,12 +924,12 @@ fn prepare_webc_env( let filesystem = Box::new(StaticFileSystem::init(slice, &package_name)?); let mut wasi_env = config.state_builder; - if !config.inherit_stdout { - wasi_env.stdout(Box::new(Pipe::new())); + if let Some(s) = config.stdout { + wasi_env.stdout(s); } - if !config.inherit_stderr { - wasi_env.stderr(Box::new(Pipe::new())); + if let Some(s) = config.stderr { + wasi_env.stderr(s); } wasi_env.set_fs(filesystem); diff --git a/lib/cli/Cargo.toml b/lib/cli/Cargo.toml index 06739fa37..6e198e267 100644 --- a/lib/cli/Cargo.toml +++ b/lib/cli/Cargo.toml @@ -65,6 +65,8 @@ walkdir = "2.3.2" regex = "1.6.0" toml = "0.5.9" url = "2.3.1" +nuke-dir = { version = "0.1.0", optional = true } +webc = { version = "3.0.0", optional = true } [build-dependencies] chrono = { version = "^0.4", default-features = false, features = [ "std", "clock" ] } @@ -93,7 +95,7 @@ wast = ["wasmer-wast"] wasi = ["wasmer-wasi"] emscripten = ["wasmer-emscripten"] wat = ["wasmer/wat"] -webc_runner = ["wasmer/webc_runner"] +webc_runner = ["wasmer/webc_runner", "nuke-dir", "webc"] compiler = [ "wasmer-compiler/translator", "wasmer-compiler/compiler", diff --git a/lib/cli/src/commands/create_exe.rs b/lib/cli/src/commands/create_exe.rs index b715ab72b..803a59ea7 100644 --- a/lib/cli/src/commands/create_exe.rs +++ b/lib/cli/src/commands/create_exe.rs @@ -4,8 +4,6 @@ use super::ObjectFormat; use crate::store::CompilerOptions; use anyhow::{Context, Result}; use clap::Parser; -#[cfg(feature = "pirita_file")] -use pirita::{ParseOptions, PiritaFileMmap}; use std::env; use std::fs; use std::fs::File; @@ -15,6 +13,8 @@ use std::path::{Path, PathBuf}; use std::process::Command; use wasmer::*; use wasmer_object::{emit_serialized, get_object_for_target}; +#[cfg(feature = "webc_runner")] +use webc::{ParseOptions, WebCMmap}; /// The `prefixer` returns the a String to prefix each of the /// functions in the static object generated by the @@ -171,13 +171,12 @@ impl CreateExe { &starting_cd, )?; - #[cfg(feature = "pirita_file")] + #[cfg(feature = "webc_runner")] { let working_dir = tempdir::TempDir::new("testpirita")?; let working_dir = working_dir.path().to_path_buf(); - if let Ok(pirita) = - PiritaFileMmap::parse(wasm_module_path.clone(), &ParseOptions::default()) + if let Ok(pirita) = WebCMmap::parse(wasm_module_path.clone(), &ParseOptions::default()) { return self.create_exe_pirita( &pirita, @@ -193,12 +192,12 @@ impl CreateExe { let (store, compiler_type) = self.compiler.get_store_for_target(target.clone())?; // Object is likely a file created from create-obj - #[cfg(feature = "pirita_file")] + #[cfg(feature = "webc_runner")] if self.path.is_dir() { let pirita_volume_path = self.webc_volume_path.clone() .ok_or(anyhow::anyhow!("If compiling using a directory (created by create-obj), you need to also specify the webc path again using --webc-volume-path because the volumes.o is not part of the directory"))?; - let file = PiritaFileMmap::parse(pirita_volume_path.clone(), &ParseOptions::default()) + let file = WebCMmap::parse(pirita_volume_path.clone(), &ParseOptions::default()) .map_err(|e| { anyhow::anyhow!( "could not parse {} as webc: {e}", @@ -594,7 +593,7 @@ impl CreateExe { } // Write the volumes.o file - #[cfg(feature = "pirita_file")] + #[cfg(feature = "webc_runner")] fn write_volume_obj( volume_bytes: &[u8], target: &Target, @@ -623,10 +622,10 @@ impl CreateExe { Ok(volume_object_path.clone()) } - #[cfg(feature = "pirita_file")] + #[cfg(feature = "webc_runner")] pub(crate) fn create_objs_pirita( store: &Store, - file: &PiritaFileMmap, + file: &WebCMmap, target: &Target, output_path: &Path, object_format: ObjectFormat, @@ -730,7 +729,7 @@ impl CreateExe { Ok(()) } - #[cfg(feature = "pirita_file")] + #[cfg(feature = "webc_runner")] fn link_exe_from_dir( &self, volume_bytes: &[u8], @@ -949,7 +948,7 @@ impl CreateExe { .replace("wasm_module_delete(module);", &deallocate_module) } - #[cfg(feature = "pirita_file")] + #[cfg(feature = "webc_runner")] fn generate_pirita_wasmer_main_c(atom_names: &[String], atom_to_run: &str) -> String { let mut c_code_to_add = String::new(); let mut c_code_to_instantiate = String::new(); @@ -994,10 +993,10 @@ impl CreateExe { c_code } - #[cfg(feature = "pirita_file")] + #[cfg(feature = "webc_runner")] fn create_exe_pirita( &self, - file: &PiritaFileMmap, + file: &WebCMmap, target: Target, cross_compilation: Option, working_dir: &Path, diff --git a/lib/cli/src/commands/create_obj.rs b/lib/cli/src/commands/create_obj.rs index b1cf3d2b6..a662724f7 100644 --- a/lib/cli/src/commands/create_obj.rs +++ b/lib/cli/src/commands/create_obj.rs @@ -5,8 +5,6 @@ use super::ObjectFormat; use crate::{commands::PrefixerFn, store::CompilerOptions}; use anyhow::{Context, Result}; use clap::Parser; -#[cfg(feature = "pirita_file")] -use pirita::{ParseOptions, PiritaFileMmap}; use std::env; use std::fs; use std::fs::File; @@ -16,6 +14,8 @@ use std::path::PathBuf; use std::process::Command; use wasmer::*; use wasmer_object::{emit_serialized, get_object_for_target}; +#[cfg(feature = "webc_runner")] +use webc::{ParseOptions, WebCMmap}; const WASMER_SERIALIZED_HEADER: &[u8] = include_bytes!("wasmer_create_exe.h"); @@ -93,10 +93,9 @@ impl CreateObj { let output_path = starting_cd.join(&self.output); let object_format = self.object_format.unwrap_or(ObjectFormat::Symbols); - #[cfg(feature = "pirita_file")] + #[cfg(feature = "webc_runner")] { - if let Ok(pirita) = - PiritaFileMmap::parse(wasm_module_path.clone(), &ParseOptions::default()) + if let Ok(pirita) = WebCMmap::parse(wasm_module_path.clone(), &ParseOptions::default()) { return self.execute_pirita(&pirita, target, output_path, object_format); } @@ -168,17 +167,18 @@ impl CreateObj { Ok(()) } - #[cfg(feature = "pirita_file")] + #[cfg(feature = "webc_runner")] fn execute_pirita( &self, - file: &PiritaFileMmap, + file: &WebCMmap, target: Target, output_path: PathBuf, object_format: ObjectFormat, ) -> Result<()> { if output_path.exists() { if output_path.is_dir() { - wapm_targz_to_pirita::nuke_dir(&output_path)?; + nuke_dir::nuke_dir(&output_path) + .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e))?; } } else { let _ = std::fs::create_dir_all(&output_path)?; diff --git a/lib/cli/src/commands/run.rs b/lib/cli/src/commands/run.rs index 677925e55..6bb771871 100644 --- a/lib/cli/src/commands/run.rs +++ b/lib/cli/src/commands/run.rs @@ -216,9 +216,9 @@ impl Run { } fn inner_execute(&self) -> Result<()> { - #[cfg(feature = "pirita_file")] + #[cfg(feature = "webc_runner")] { - if let Some(pf) = pirita::PiritaContainer::load_mmap(self.path.clone()) { + if let Ok(pf) = wasmer::runners::WapmContainer::new(self.path.clone()) { return pf .run(&self.command_name.clone().unwrap_or_default(), &self.args) .map_err(|e| anyhow!("Could not run PiritaFile: {e}")); diff --git a/lib/vfs/Cargo.toml b/lib/vfs/Cargo.toml index 15262bbd0..d4d7c3652 100644 --- a/lib/vfs/Cargo.toml +++ b/lib/vfs/Cargo.toml @@ -21,7 +21,7 @@ default = ["host-fs", "mem-fs", "webc-fs", "static-fs"] host-fs = ["libc"] mem-fs = ["slab"] webc-fs = ["webc", "anyhow"] -static-fs = ["webc", "anyhow"] +static-fs = ["webc", "anyhow", "mem-fs"] enable-serde = [ "serde", "typetag" diff --git a/tests/integration/cli/tests/run.rs b/tests/integration/cli/tests/run.rs index cedf311b7..2df66e103 100644 --- a/tests/integration/cli/tests/run.rs +++ b/tests/integration/cli/tests/run.rs @@ -76,7 +76,7 @@ fn test_wasmer_create_exe_pirita_works() -> anyhow::Result<()> { Ok(()) } -#[cfg(feature = "pirita_file")] +#[cfg(feature = "webc_runner")] #[test] fn test_wasmer_run_pirita_works() -> anyhow::Result<()> { let temp_dir = tempfile::TempDir::new()?;