Switch from wabt crate to wast (#434)
* Switch lightbeam from `wabt` to `wast` Switch from a C++-based `*.wat` parser to a Rust-based parser * Remove unneeded `wabt` dev-dependency from wasmtime-api * Rewrite `wasmtime-wast` crate with `wast-parser` This commit moves the `wasmtime-wast` crate off the `wabt` crate on to the `wast-parser` crate which is a Rust implementation of a `*.wast` and `*.wat` parser. The intention here is to continue to reduce the amount of C++ required to build wasmtime! * Use new `wat` and `wast` crate names
This commit is contained in:
committed by
Dan Gohman
parent
ebef2c6b57
commit
9947bc5209
@@ -40,9 +40,8 @@ use std::collections::HashMap;
|
||||
use std::ffi::OsStr;
|
||||
use std::fs::File;
|
||||
use std::path::Component;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::path::Path;
|
||||
use std::process::exit;
|
||||
use wabt;
|
||||
use wasi_common::preopen_dir;
|
||||
use wasmtime::pick_compilation_strategy;
|
||||
use wasmtime_api::{Config, Engine, HostRef, Instance, Module, Store};
|
||||
@@ -115,19 +114,6 @@ struct Args {
|
||||
flag_wasi_c: bool,
|
||||
}
|
||||
|
||||
fn read_wasm(path: PathBuf) -> Result<Vec<u8>, Error> {
|
||||
let data = std::fs::read(&path)
|
||||
.with_context(|_| format!("failed to read file: {}", path.display()))?;
|
||||
|
||||
// If data is a wasm binary, use that. If it's using wat format, convert it
|
||||
// to a wasm binary with wat2wasm.
|
||||
Ok(if data.starts_with(&[b'\0', b'a', b's', b'm']) {
|
||||
data
|
||||
} else {
|
||||
wabt::wat2wasm(data)?
|
||||
})
|
||||
}
|
||||
|
||||
fn compute_preopen_dirs(flag_dir: &[String], flag_mapdir: &[String]) -> Vec<(String, File)> {
|
||||
let mut preopen_dirs = Vec::new();
|
||||
|
||||
@@ -353,8 +339,8 @@ fn instantiate_module(
|
||||
module_registry: &HashMap<String, (Instance, HashMap<String, usize>)>,
|
||||
path: &Path,
|
||||
) -> Result<(HostRef<Instance>, HostRef<Module>, Vec<u8>), Error> {
|
||||
// Read the wasm module binary.
|
||||
let data = read_wasm(path.to_path_buf())?;
|
||||
// Read the wasm module binary either as `*.wat` or a raw binary
|
||||
let data = wat::parse_file(path.to_path_buf())?;
|
||||
|
||||
let module = HostRef::new(Module::new(store.clone(), &data)?);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user