Replace more miscellaenous read_wasm utilities with wat::parse_file. (#601)
This commit is contained in:
committed by
Alex Crichton
parent
7d7360b32d
commit
58dd4c6c88
@@ -22,3 +22,4 @@ pretty_env_logger = "0.3.0"
|
||||
tempfile = "3.1.0"
|
||||
os_pipe = "0.9"
|
||||
anyhow = "1.0.19"
|
||||
wat = "1.0.2"
|
||||
|
||||
@@ -127,7 +127,7 @@ fn write_testsuite_tests(out: &mut File, dir_entry: DirEntry, testsuite: &str) -
|
||||
" let path = std::path::Path::new(r#\"{}\"#);",
|
||||
path.display()
|
||||
)?;
|
||||
writeln!(out, " let data = utils::read_wasm(path)?;")?;
|
||||
writeln!(out, " let data = wat::parse_file(path)?;")?;
|
||||
writeln!(
|
||||
out,
|
||||
" let bin_name = utils::extract_exec_name_from_path(path)?;"
|
||||
|
||||
@@ -1,16 +1,6 @@
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
use tempfile::{Builder, TempDir};
|
||||
|
||||
pub fn read_wasm(path: &Path) -> anyhow::Result<Vec<u8>> {
|
||||
let data = fs::read(path)?;
|
||||
if data.starts_with(&[b'\0', b'a', b's', b'm']) {
|
||||
Ok(data)
|
||||
} else {
|
||||
anyhow::bail!("Invalid Wasm file encountered")
|
||||
}
|
||||
}
|
||||
|
||||
pub fn prepare_workspace(exe_name: &str) -> anyhow::Result<TempDir> {
|
||||
let prefix = format!("wasi_common_{}", exe_name);
|
||||
let tempdir = Builder::new().prefix(&prefix).tempdir()?;
|
||||
|
||||
@@ -38,11 +38,9 @@ use faerie::Artifact;
|
||||
use serde::Deserialize;
|
||||
use std::error::Error;
|
||||
use std::fmt::format;
|
||||
use std::fs::File;
|
||||
use std::io::prelude::*;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::str::FromStr;
|
||||
use std::{io, process, str};
|
||||
use std::{process, str};
|
||||
use target_lexicon::Triple;
|
||||
use wasmtime_cli::pick_compilation_strategy;
|
||||
use wasmtime_debug::{emit_debugsections, read_debuginfo};
|
||||
@@ -104,13 +102,6 @@ struct Args {
|
||||
flag_optimize: bool,
|
||||
}
|
||||
|
||||
fn read_wasm_file(path: PathBuf) -> Result<Vec<u8>, io::Error> {
|
||||
let mut buf: Vec<u8> = Vec::new();
|
||||
let mut file = File::open(path)?;
|
||||
file.read_to_end(&mut buf)?;
|
||||
Ok(buf)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let version = env!("CARGO_PKG_VERSION");
|
||||
let args: Args = Docopt::new(USAGE)
|
||||
@@ -189,7 +180,7 @@ fn handle_module(
|
||||
cranelift: bool,
|
||||
lightbeam: bool,
|
||||
) -> Result<(), String> {
|
||||
let data = match read_wasm_file(path) {
|
||||
let data = match wat::parse_file(path) {
|
||||
Ok(data) => data,
|
||||
Err(err) => {
|
||||
return Err(String::from(err.description()));
|
||||
|
||||
Reference in New Issue
Block a user