Skip to content

Commit

Permalink
remove wat2wasm binary usage everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
slandymani committed Nov 18, 2024
1 parent 92e5d57 commit 06c2739
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 147 deletions.
41 changes: 5 additions & 36 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions packages/vm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ clru = "0.2.0"
hex = "0.4"
owasm-crypto = {path = "../crypto", version = "0.3.1"}
sha2 = "0.9.1"
tempfile = "3.1.0"
wasm-instrument = { version = "0.4.0", default-features = false, features = [
"sign_ext"
] }
wasmer = {version = "=4.3.3", default-features = false, features = ["singlepass", "compiler"]}
wasmer-middlewares = "=4.3.3"
wasmer-types = "=4.3.3"
wat = "1.0"
wat = "=1.0.34"
1 change: 0 additions & 1 deletion packages/vm/fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ cargo-fuzz = true

[dependencies]
libfuzzer-sys = "0.4"
tempfile = "3.1.0"

[dependencies.owasm-vm]
path = ".."
Expand Down
20 changes: 2 additions & 18 deletions packages/vm/fuzz/fuzz_targets/fuzz_target_1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ extern crate owasm_vm;
use crate::owasm_vm::cache::*;
use crate::owasm_vm::error::Error;
use owasm_vm::vm::Querier;
use std::io::{Read, Write};
use std::process::Command;
use tempfile::NamedTempFile;

pub struct MockQuerier {}

Expand Down Expand Up @@ -47,21 +44,8 @@ impl Querier for MockQuerier {
}

fn wat2wasm(wat: impl AsRef<[u8]>) -> Vec<u8> {
let mut input_file = NamedTempFile::new().unwrap();
let mut output_file = NamedTempFile::new().unwrap();
input_file.write_all(wat.as_ref()).unwrap();
Command::new("wat2wasm")
.args(&[
input_file.path().to_str().unwrap(),
"-o",
output_file.path().to_str().unwrap(),
"--no-check",
])
.output()
.unwrap();
let mut wasm = Vec::new();
output_file.read_to_end(&mut wasm).unwrap();
wasm
let wat_bytes = wat.as_ref();
wat::parse_bytes(wat_bytes).unwrap().into_owned()
}

fn generate_wat(imported_function: String) -> String {
Expand Down
7 changes: 0 additions & 7 deletions packages/vm/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ use std::{
sync::{Arc, RwLock},
};

use wat;

use clru::CLruCache;
use wasmer::{Engine, Instance, Module, Store};

Expand Down Expand Up @@ -101,11 +99,6 @@ impl Cache {

#[cfg(test)]
mod tests {
use std::io::{Read, Write};
use std::process::Command;

use tempfile::NamedTempFile;

use crate::store::make_engine;
use crate::vm::Querier;

Expand Down
21 changes: 2 additions & 19 deletions packages/vm/src/calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,6 @@ where

#[cfg(test)]
mod tests {
use std::io::{Read, Write};
use std::process::Command;

use tempfile::NamedTempFile;

use crate::cache::CacheOptions;
use crate::compile::compile;

Expand Down Expand Up @@ -102,20 +97,8 @@ mod tests {
}

fn wat2wasm(wat: impl AsRef<[u8]>) -> Vec<u8> {
let mut input_file = NamedTempFile::new().unwrap();
let mut output_file = NamedTempFile::new().unwrap();
input_file.write_all(wat.as_ref()).unwrap();
Command::new("wat2wasm")
.args(&[
input_file.path().to_str().unwrap(),
"-o",
output_file.path().to_str().unwrap(),
])
.output()
.unwrap();
let mut wasm = Vec::new();
output_file.read_to_end(&mut wasm).unwrap();
wasm
let wat_bytes = wat.as_ref();
wat::parse_bytes(wat_bytes).unwrap().into_owned()
}

#[test]
Expand Down
37 changes: 11 additions & 26 deletions packages/vm/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,25 +116,10 @@ mod tests {
use super::*;

use assert_matches::assert_matches;
use std::io::{Read, Write};
use std::process::Command;
use tempfile::NamedTempFile;

fn wat2wasm(wat: impl AsRef<[u8]>) -> Vec<u8> {
let mut input_file = NamedTempFile::new().unwrap();
let mut output_file = NamedTempFile::new().unwrap();
input_file.write_all(wat.as_ref()).unwrap();
Command::new("wat2wasm")
.args(&[
input_file.path().to_str().unwrap(),
"-o",
output_file.path().to_str().unwrap(),
])
.output()
.unwrap();
let mut wasm = Vec::new();
output_file.read_to_end(&mut wasm).unwrap();
wasm
let wat_bytes = wat.as_ref();
wat::parse_bytes(wat_bytes).unwrap().into_owned()
}

fn get_module_from_wasm(code: &[u8]) -> Module {
Expand Down Expand Up @@ -221,16 +206,16 @@ mod tests {
r#"(module
(type (;0;) (func))
(func (;0;) (type 0)
(local i32)
(local $idx i32)
i32.const 0
local.set 0
local.set $idx
block ;; label = @1
loop ;; label = @2
local.get 0
i32.const 1
i32.add
local.set 0
local.get 0
local.set $idx
local.get $idx
i32.const 1000000000
i32.lt_u
br_if 0 (;@2;)
Expand Down Expand Up @@ -351,16 +336,16 @@ mod tests {
(type (;1;) (func))
(import "env" "ask_external_data" (func (;0;) (type 0)))
(func (;1;) (type 1)
(local i32)
(local $idx i32)
i32.const 0
local.set 0
local.set $idx
block ;; label = @1
loop ;; label = @2
local.get 0
local.get $idx
i32.const 1
i32.add
local.set 0
local.get 0
local.set $idx
local.get $idx
i32.const 1000000000
i32.lt_u
br_if 0 (;@2;)
Expand Down
19 changes: 2 additions & 17 deletions packages/vm/src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,10 +330,7 @@ mod test {
use crate::compile::compile;
use crate::store::{make_engine, make_store};

use std::io::{Read, Write};
use std::process::Command;
use std::ptr::NonNull;
use tempfile::NamedTempFile;
use wasmer::ExternType::Function;
use wasmer::{FunctionType, Store};
use wasmer::Instance;
Expand Down Expand Up @@ -378,20 +375,8 @@ mod test {
}

fn wat2wasm(wat: impl AsRef<[u8]>) -> Vec<u8> {
let mut input_file = NamedTempFile::new().unwrap();
let mut output_file = NamedTempFile::new().unwrap();
input_file.write_all(wat.as_ref()).unwrap();
Command::new("wat2wasm")
.args(&[
input_file.path().to_str().unwrap(),
"-o",
output_file.path().to_str().unwrap(),
])
.output()
.unwrap();
let mut wasm = Vec::new();
output_file.read_to_end(&mut wasm).unwrap();
wasm
let wat_bytes = wat.as_ref();
wat::parse_bytes(wat_bytes).unwrap().into_owned()
}

fn create_owasm_env() -> (Environment<MockQuerier>, Instance, Store) {
Expand Down
23 changes: 2 additions & 21 deletions packages/vm/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,6 @@ where

#[cfg(test)]
mod tests {
use std::{
io::{Read, Write},
process::Command,
};

use tempfile::NamedTempFile;

use crate::cache::{Cache, CacheOptions};
use crate::store::make_engine;

Expand Down Expand Up @@ -210,20 +203,8 @@ mod tests {
}

fn wat2wasm(wat: impl AsRef<[u8]>) -> Vec<u8> {
let mut input_file = NamedTempFile::new().unwrap();
let mut output_file = NamedTempFile::new().unwrap();
input_file.write_all(wat.as_ref()).unwrap();
Command::new("wat2wasm")
.args(&[
input_file.path().to_str().unwrap(),
"-o",
output_file.path().to_str().unwrap(),
])
.output()
.unwrap();
let mut wasm = Vec::new();
output_file.read_to_end(&mut wasm).unwrap();
wasm
let wat_bytes = wat.as_ref();
wat::parse_bytes(wat_bytes).unwrap().into_owned()
}

#[test]
Expand Down

0 comments on commit 06c2739

Please sign in to comment.