Fixed most dependency errors

This commit is contained in:
Felix Schütt
2022-10-27 18:42:32 +02:00
parent 6d404dee25
commit 7e76db8490
9 changed files with 46 additions and 39 deletions

4
Cargo.lock generated
View File

@@ -3847,7 +3847,9 @@ dependencies = [
"wasmer-inline-c", "wasmer-inline-c",
"wasmer-middlewares", "wasmer-middlewares",
"wasmer-types", "wasmer-types",
"wasmer-vfs",
"wasmer-wasi", "wasmer-wasi",
"webc",
] ]
[[package]] [[package]]
@@ -3900,6 +3902,7 @@ dependencies = [
"fern", "fern",
"http_req", "http_req",
"log", "log",
"nuke-dir",
"prettytable-rs", "prettytable-rs",
"regex", "regex",
"serde_json", "serde_json",
@@ -3927,6 +3930,7 @@ dependencies = [
"wasmer-wasi", "wasmer-wasi",
"wasmer-wasi-experimental-io-devices", "wasmer-wasi-experimental-io-devices",
"wasmer-wast", "wasmer-wast",
"webc",
] ]
[[package]] [[package]]

View File

@@ -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-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-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-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" enumset = "1.0.2"
cfg-if = "1.0" cfg-if = "1.0"
lazy_static = "1.4" lazy_static = "1.4"
@@ -90,7 +92,7 @@ wasmer-artifact-load = ["wasmer-compiler/wasmer-artifact-load"]
wasmer-artifact-create = ["wasmer-compiler/wasmer-artifact-create"] wasmer-artifact-create = ["wasmer-compiler/wasmer-artifact-create"]
static-artifact-load = ["wasmer-compiler/static-artifact-load"] static-artifact-load = ["wasmer-compiler/static-artifact-load"]
static-artifact-create = ["wasmer-compiler/static-artifact-create"] 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. # Deprecated features.
jit = ["compiler"] jit = ["compiler"]

View File

@@ -23,7 +23,7 @@ use std::{
io::{self, SeekFrom}, io::{self, SeekFrom},
sync::MutexGuard, sync::MutexGuard,
}; };
#[cfg(feature = "pirita_file")] #[cfg(feature = "webc_runner")]
use wasmer_api::{AsStoreMut, Imports, Module}; use wasmer_api::{AsStoreMut, Imports, Module};
use wasmer_wasi::{ use wasmer_wasi::{
get_wasi_version, FsError, VirtualFile, WasiBidirectionalPipePair, WasiFile, WasiFunctionEnv, 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 /// Initializes the `imports` with an import object that links to
/// the custom file system /// the custom file system
#[cfg(feature = "pirita_file")] #[cfg(feature = "webc_runner")]
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn wasi_env_with_filesystem( pub unsafe extern "C" fn wasi_env_with_filesystem(
config: Box<wasi_config_t>, config: Box<wasi_config_t>,
@@ -859,7 +859,7 @@ pub unsafe extern "C" fn wasi_env_with_filesystem(
wasi_env_with_filesystem_inner(config, store, module, fs, imports, package) 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( unsafe fn wasi_env_with_filesystem_inner(
config: Box<wasi_config_t>, config: Box<wasi_config_t>,
store: Option<&mut wasm_store_t>, 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( fn prepare_webc_env(
config: Box<wasi_config_t>, config: Box<wasi_config_t>,
store: &mut impl AsStoreMut, store: &mut impl AsStoreMut,
@@ -901,11 +901,11 @@ fn prepare_webc_env(
len: usize, len: usize,
package_name: &str, package_name: &str,
) -> Option<(WasiFunctionEnv, Imports)> { ) -> Option<(WasiFunctionEnv, Imports)> {
use pirita::FsEntryType; use wasmer_vfs::static_fs::StaticFileSystem;
use pirita::StaticFileSystem; use webc::FsEntryType;
let slice = unsafe { std::slice::from_raw_parts(bytes, len) }; 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 let top_level_dirs = volumes
.into_iter() .into_iter()
.flat_map(|(_, volume)| { .flat_map(|(_, volume)| {
@@ -924,12 +924,12 @@ fn prepare_webc_env(
let filesystem = Box::new(StaticFileSystem::init(slice, &package_name)?); let filesystem = Box::new(StaticFileSystem::init(slice, &package_name)?);
let mut wasi_env = config.state_builder; let mut wasi_env = config.state_builder;
if !config.inherit_stdout { if let Some(s) = config.stdout {
wasi_env.stdout(Box::new(Pipe::new())); wasi_env.stdout(s);
} }
if !config.inherit_stderr { if let Some(s) = config.stderr {
wasi_env.stderr(Box::new(Pipe::new())); wasi_env.stderr(s);
} }
wasi_env.set_fs(filesystem); wasi_env.set_fs(filesystem);

View File

@@ -65,6 +65,8 @@ walkdir = "2.3.2"
regex = "1.6.0" regex = "1.6.0"
toml = "0.5.9" toml = "0.5.9"
url = "2.3.1" url = "2.3.1"
nuke-dir = { version = "0.1.0", optional = true }
webc = { version = "3.0.0", optional = true }
[build-dependencies] [build-dependencies]
chrono = { version = "^0.4", default-features = false, features = [ "std", "clock" ] } chrono = { version = "^0.4", default-features = false, features = [ "std", "clock" ] }
@@ -93,7 +95,7 @@ wast = ["wasmer-wast"]
wasi = ["wasmer-wasi"] wasi = ["wasmer-wasi"]
emscripten = ["wasmer-emscripten"] emscripten = ["wasmer-emscripten"]
wat = ["wasmer/wat"] wat = ["wasmer/wat"]
webc_runner = ["wasmer/webc_runner"] webc_runner = ["wasmer/webc_runner", "nuke-dir", "webc"]
compiler = [ compiler = [
"wasmer-compiler/translator", "wasmer-compiler/translator",
"wasmer-compiler/compiler", "wasmer-compiler/compiler",

View File

@@ -4,8 +4,6 @@ use super::ObjectFormat;
use crate::store::CompilerOptions; use crate::store::CompilerOptions;
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use clap::Parser; use clap::Parser;
#[cfg(feature = "pirita_file")]
use pirita::{ParseOptions, PiritaFileMmap};
use std::env; use std::env;
use std::fs; use std::fs;
use std::fs::File; use std::fs::File;
@@ -15,6 +13,8 @@ use std::path::{Path, PathBuf};
use std::process::Command; use std::process::Command;
use wasmer::*; use wasmer::*;
use wasmer_object::{emit_serialized, get_object_for_target}; 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 /// The `prefixer` returns the a String to prefix each of the
/// functions in the static object generated by the /// functions in the static object generated by the
@@ -171,13 +171,12 @@ impl CreateExe {
&starting_cd, &starting_cd,
)?; )?;
#[cfg(feature = "pirita_file")] #[cfg(feature = "webc_runner")]
{ {
let working_dir = tempdir::TempDir::new("testpirita")?; let working_dir = tempdir::TempDir::new("testpirita")?;
let working_dir = working_dir.path().to_path_buf(); let working_dir = working_dir.path().to_path_buf();
if let Ok(pirita) = if let Ok(pirita) = WebCMmap::parse(wasm_module_path.clone(), &ParseOptions::default())
PiritaFileMmap::parse(wasm_module_path.clone(), &ParseOptions::default())
{ {
return self.create_exe_pirita( return self.create_exe_pirita(
&pirita, &pirita,
@@ -193,12 +192,12 @@ impl CreateExe {
let (store, compiler_type) = self.compiler.get_store_for_target(target.clone())?; let (store, compiler_type) = self.compiler.get_store_for_target(target.clone())?;
// Object is likely a file created from create-obj // Object is likely a file created from create-obj
#[cfg(feature = "pirita_file")] #[cfg(feature = "webc_runner")]
if self.path.is_dir() { if self.path.is_dir() {
let pirita_volume_path = self.webc_volume_path.clone() 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"))?; .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| { .map_err(|e| {
anyhow::anyhow!( anyhow::anyhow!(
"could not parse {} as webc: {e}", "could not parse {} as webc: {e}",
@@ -594,7 +593,7 @@ impl CreateExe {
} }
// Write the volumes.o file // Write the volumes.o file
#[cfg(feature = "pirita_file")] #[cfg(feature = "webc_runner")]
fn write_volume_obj( fn write_volume_obj(
volume_bytes: &[u8], volume_bytes: &[u8],
target: &Target, target: &Target,
@@ -623,10 +622,10 @@ impl CreateExe {
Ok(volume_object_path.clone()) Ok(volume_object_path.clone())
} }
#[cfg(feature = "pirita_file")] #[cfg(feature = "webc_runner")]
pub(crate) fn create_objs_pirita( pub(crate) fn create_objs_pirita(
store: &Store, store: &Store,
file: &PiritaFileMmap, file: &WebCMmap,
target: &Target, target: &Target,
output_path: &Path, output_path: &Path,
object_format: ObjectFormat, object_format: ObjectFormat,
@@ -730,7 +729,7 @@ impl CreateExe {
Ok(()) Ok(())
} }
#[cfg(feature = "pirita_file")] #[cfg(feature = "webc_runner")]
fn link_exe_from_dir( fn link_exe_from_dir(
&self, &self,
volume_bytes: &[u8], volume_bytes: &[u8],
@@ -949,7 +948,7 @@ impl CreateExe {
.replace("wasm_module_delete(module);", &deallocate_module) .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 { 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_add = String::new();
let mut c_code_to_instantiate = String::new(); let mut c_code_to_instantiate = String::new();
@@ -994,10 +993,10 @@ impl CreateExe {
c_code c_code
} }
#[cfg(feature = "pirita_file")] #[cfg(feature = "webc_runner")]
fn create_exe_pirita( fn create_exe_pirita(
&self, &self,
file: &PiritaFileMmap, file: &WebCMmap,
target: Target, target: Target,
cross_compilation: Option<CrossCompileSetup>, cross_compilation: Option<CrossCompileSetup>,
working_dir: &Path, working_dir: &Path,

View File

@@ -5,8 +5,6 @@ use super::ObjectFormat;
use crate::{commands::PrefixerFn, store::CompilerOptions}; use crate::{commands::PrefixerFn, store::CompilerOptions};
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use clap::Parser; use clap::Parser;
#[cfg(feature = "pirita_file")]
use pirita::{ParseOptions, PiritaFileMmap};
use std::env; use std::env;
use std::fs; use std::fs;
use std::fs::File; use std::fs::File;
@@ -16,6 +14,8 @@ use std::path::PathBuf;
use std::process::Command; use std::process::Command;
use wasmer::*; use wasmer::*;
use wasmer_object::{emit_serialized, get_object_for_target}; 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"); 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 output_path = starting_cd.join(&self.output);
let object_format = self.object_format.unwrap_or(ObjectFormat::Symbols); let object_format = self.object_format.unwrap_or(ObjectFormat::Symbols);
#[cfg(feature = "pirita_file")] #[cfg(feature = "webc_runner")]
{ {
if let Ok(pirita) = if let Ok(pirita) = WebCMmap::parse(wasm_module_path.clone(), &ParseOptions::default())
PiritaFileMmap::parse(wasm_module_path.clone(), &ParseOptions::default())
{ {
return self.execute_pirita(&pirita, target, output_path, object_format); return self.execute_pirita(&pirita, target, output_path, object_format);
} }
@@ -168,17 +167,18 @@ impl CreateObj {
Ok(()) Ok(())
} }
#[cfg(feature = "pirita_file")] #[cfg(feature = "webc_runner")]
fn execute_pirita( fn execute_pirita(
&self, &self,
file: &PiritaFileMmap, file: &WebCMmap,
target: Target, target: Target,
output_path: PathBuf, output_path: PathBuf,
object_format: ObjectFormat, object_format: ObjectFormat,
) -> Result<()> { ) -> Result<()> {
if output_path.exists() { if output_path.exists() {
if output_path.is_dir() { 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 { } else {
let _ = std::fs::create_dir_all(&output_path)?; let _ = std::fs::create_dir_all(&output_path)?;

View File

@@ -216,9 +216,9 @@ impl Run {
} }
fn inner_execute(&self) -> Result<()> { 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 return pf
.run(&self.command_name.clone().unwrap_or_default(), &self.args) .run(&self.command_name.clone().unwrap_or_default(), &self.args)
.map_err(|e| anyhow!("Could not run PiritaFile: {e}")); .map_err(|e| anyhow!("Could not run PiritaFile: {e}"));

View File

@@ -21,7 +21,7 @@ default = ["host-fs", "mem-fs", "webc-fs", "static-fs"]
host-fs = ["libc"] host-fs = ["libc"]
mem-fs = ["slab"] mem-fs = ["slab"]
webc-fs = ["webc", "anyhow"] webc-fs = ["webc", "anyhow"]
static-fs = ["webc", "anyhow"] static-fs = ["webc", "anyhow", "mem-fs"]
enable-serde = [ enable-serde = [
"serde", "serde",
"typetag" "typetag"

View File

@@ -76,7 +76,7 @@ fn test_wasmer_create_exe_pirita_works() -> anyhow::Result<()> {
Ok(()) Ok(())
} }
#[cfg(feature = "pirita_file")] #[cfg(feature = "webc_runner")]
#[test] #[test]
fn test_wasmer_run_pirita_works() -> anyhow::Result<()> { fn test_wasmer_run_pirita_works() -> anyhow::Result<()> {
let temp_dir = tempfile::TempDir::new()?; let temp_dir = tempfile::TempDir::new()?;