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

View File

@@ -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<CrossCompileSetup>,
working_dir: &Path,

View File

@@ -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)?;

View File

@@ -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}"));