diff --git a/Cargo.lock b/Cargo.lock index 14e6fff66..45e99f1f1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1129,6 +1129,7 @@ dependencies = [ "libc 0.2.44 (git+https://github.com/rust-lang/libc)", "time 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)", "wabt 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", + "wasmer 0.1.4", "wasmer-clif-backend 0.1.4", "wasmer-runtime 0.1.4", ] diff --git a/lib/emscripten/src/utils.rs b/lib/emscripten/src/utils.rs index 04e1c17ce..6255d046e 100644 --- a/lib/emscripten/src/utils.rs +++ b/lib/emscripten/src/utils.rs @@ -143,13 +143,19 @@ pub unsafe fn copy_stat_into_wasm(instance: &mut Instance, buf: u32, stat: &stat mod tests { use super::is_emscripten_module; use wasmer_clif_backend::CraneliftCompiler; + use wasmer_runtime::{ + compile, + module::Module, + }; use wabt::wat2wasm; + use std::sync::Arc; #[test] fn should_detect_emscripten_files() { const wast_bytes: &[u8] = include_bytes!("tests/is_emscripten_true.wast"); let wasm_binary = wat2wasm(wast_bytes.to_vec()).expect("Can't convert to wasm"); - let module = wasmer_runtime::compile(&wasm_binary[..], &CraneliftCompiler::new()).expect("WASM can't be compiled"); + let module = compile(&wasm_binary[..], &CraneliftCompiler::new()).expect("WASM can't be compiled"); + let module = Arc::new(module); assert!(is_emscripten_module(&module)); } @@ -157,7 +163,8 @@ mod tests { fn should_detect_non_emscripten_files() { const wast_bytes: &[u8] = include_bytes!("tests/is_emscripten_false.wast"); let wasm_binary = wat2wasm(wast_bytes.to_vec()).expect("Can't convert to wasm"); - let module = wasmer_runtime::compile(&wasm_binary[..], &CraneliftCompiler::new()).expect("WASM can't be compiled"); + let module = compile(&wasm_binary[..], &CraneliftCompiler::new()).expect("WASM can't be compiled"); + let module = Arc::new(module); assert!(!is_emscripten_module(&module)); } } diff --git a/lib/emscripten/tests/emtests/_common.rs b/lib/emscripten/tests/emtests/_common.rs index 594280047..6ecc52ce9 100644 --- a/lib/emscripten/tests/emtests/_common.rs +++ b/lib/emscripten/tests/emtests/_common.rs @@ -1,29 +1,47 @@ macro_rules! assert_emscripten_output { ($file:expr, $name:expr, $args:expr, $expected:expr) => {{ - use wasmer_emscripten::generate_emscripten_env; - // use wasmer::common::stdio::StdioCapturer; - use wasmer_runtime::{Import, Imports, FuncRef}; - use wasmer_runtime::table::TableBacking; - use wasmer_runtime::{Instance, module::Module}; + // TODO: Cyclic Dep! + use wasmer::{ + webassembly::{ + compile, + start_instance, + }, + common::stdio::StdioCapturer, + }; + + use wasmer_runtime::{ + instance::Instance, + module::Module, + table::TableBacking + }; + use wasmer_clif_backend::CraneliftCompiler; + use wasmer_emscripten::{ + EmscriptenGlobals, + generate_emscripten_env, + }; use std::sync::Arc; let wasm_bytes = include_bytes!($file); - let import_object = generate_emscripten_env(); -// let options = Some(InstanceOptions { -// mock_missing_imports: true, -// mock_missing_globals: true, -// mock_missing_tables: true, -// abi: InstanceABI::Emscripten, -// show_progressbar: false, -// // isa: get_isa(), -// }); -// let mut result_object = instantiate(&wasm_bytes.to_vec(), &import_object, options) -// .expect("Not compiled properly"); - let module = wasmer_runtime::compile(&wasm_bytes[..], &CraneliftCompiler::new()).expect("WASM can't be compiled"); - let instance = module.instantiate(&import_object).expect("WASM can't be instantiated"); + let module = compile(&wasm_bytes[..]) + .map_err(|err| format!("Can't create the WebAssembly module: {}", err)).unwrap(); // NOTE: Need to figure what the unwrap is for ?? + + let emscripten_globals = EmscriptenGlobals::new(); + let mut import_object = generate_emscripten_env(&emscripten_globals); + + let mut instance = module.instantiate(import_object) + .map_err(|err| format!("Can't instantiate the WebAssembly module: {}", err)).unwrap(); // NOTE: Need to figure what the unwrap is for ?? + + start_instance( + Arc::clone(&module), + &mut instance, + $name, + $args, + ); + + assert!(false, "Emscripten tests are mocked"); // let capturer = StdioCapturer::new(); // start_instance( @@ -35,7 +53,7 @@ macro_rules! assert_emscripten_output { // .unwrap(); // let output = capturer.end().unwrap().0; // let expected_output = include_str!($expected); - assert!(false, "Emscripten tests are mocked"); + // assert!(false, "Emscripten tests are mocked"); // assert!( // output.contains(expected_output), // "Output: `{}` does not contain expected output: `{}`", diff --git a/src/common/mod.rs b/src/common/mod.rs index 63a6bd39f..34d8a0b66 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -2,5 +2,5 @@ pub mod mmap; pub mod slice; mod file_descriptor; -#[cfg(test)] -pub mod stdio; +//#[cfg(test)] +pub mod stdio; \ No newline at end of file