mirror of
https://github.com/fluencelabs/wasmer
synced 2025-05-19 05:31:19 +00:00
Emscripten tests compiling again
This commit is contained in:
parent
321abe6644
commit
1025a0d730
@ -4,21 +4,26 @@ extern crate wasmer_runtime;
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
use wasmer_runtime::macros;
|
use wasmer_runtime::macros;
|
||||||
|
|
||||||
use wasmer_runtime::{
|
|
||||||
import::{Imports, NamespaceMap},
|
|
||||||
export::{Export, Context, GlobalPointer, FuncPointer},
|
|
||||||
types::{
|
|
||||||
FuncSig, Type::{self, *}, Value,
|
|
||||||
GlobalDesc,
|
|
||||||
},
|
|
||||||
vm::{self, LocalGlobal, Func},
|
|
||||||
memory::LinearMemory,
|
|
||||||
};
|
|
||||||
use byteorder::{ByteOrder, LittleEndian};
|
use byteorder::{ByteOrder, LittleEndian};
|
||||||
|
use hashbrown::{hash_map::Entry, HashMap};
|
||||||
use libc::c_int;
|
use libc::c_int;
|
||||||
use std::cell::UnsafeCell;
|
use std::cell::UnsafeCell;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use hashbrown::{hash_map::Entry, HashMap};
|
use wasmer_runtime::{
|
||||||
|
export::{Context, Export, FuncPointer, GlobalPointer},
|
||||||
|
import::{Imports, NamespaceMap},
|
||||||
|
memory::LinearMemory,
|
||||||
|
types::{
|
||||||
|
FuncSig, GlobalDesc,
|
||||||
|
Type::{self, *},
|
||||||
|
Value,
|
||||||
|
},
|
||||||
|
vm::{self, Func, LocalGlobal},
|
||||||
|
};
|
||||||
|
|
||||||
|
//#[cfg(test)]
|
||||||
|
mod file_descriptor;
|
||||||
|
pub mod stdio;
|
||||||
|
|
||||||
// EMSCRIPTEN APIS
|
// EMSCRIPTEN APIS
|
||||||
mod env;
|
mod env;
|
||||||
@ -124,7 +129,7 @@ macro_rules! global {
|
|||||||
unsafe {
|
unsafe {
|
||||||
GlobalPointer::new(
|
GlobalPointer::new(
|
||||||
// NOTE: Taking a shortcut here. LocalGlobal is a struct containing just u64.
|
// NOTE: Taking a shortcut here. LocalGlobal is a struct containing just u64.
|
||||||
std::mem::transmute::<&u64, *mut LocalGlobal>($value)
|
std::mem::transmute::<&u64, *mut LocalGlobal>($value),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}};
|
}};
|
||||||
@ -150,9 +155,7 @@ impl <'a> EmscriptenGlobals<'a> {
|
|||||||
data.insert("env", env_namepace);
|
data.insert("env", env_namepace);
|
||||||
data.insert("global", global_namepace);
|
data.insert("global", global_namepace);
|
||||||
|
|
||||||
Self {
|
Self { data }
|
||||||
data,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,7 +178,7 @@ pub fn generate_emscripten_env(globals: &EmscriptenGlobals) -> Imports {
|
|||||||
global: GlobalDesc {
|
global: GlobalDesc {
|
||||||
mutable: false,
|
mutable: false,
|
||||||
ty: ty.clone(),
|
ty: ty.clone(),
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -187,7 +190,7 @@ pub fn generate_emscripten_env(globals: &EmscriptenGlobals) -> Imports {
|
|||||||
global: GlobalDesc {
|
global: GlobalDesc {
|
||||||
mutable: false,
|
mutable: false,
|
||||||
ty: ty.clone(),
|
ty: ty.clone(),
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -199,7 +202,7 @@ pub fn generate_emscripten_env(globals: &EmscriptenGlobals) -> Imports {
|
|||||||
global: GlobalDesc {
|
global: GlobalDesc {
|
||||||
mutable: false,
|
mutable: false,
|
||||||
ty: ty.clone(),
|
ty: ty.clone(),
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -211,7 +214,7 @@ pub fn generate_emscripten_env(globals: &EmscriptenGlobals) -> Imports {
|
|||||||
global: GlobalDesc {
|
global: GlobalDesc {
|
||||||
mutable: false,
|
mutable: false,
|
||||||
ty: ty.clone(),
|
ty: ty.clone(),
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -223,7 +226,7 @@ pub fn generate_emscripten_env(globals: &EmscriptenGlobals) -> Imports {
|
|||||||
global: GlobalDesc {
|
global: GlobalDesc {
|
||||||
mutable: false,
|
mutable: false,
|
||||||
ty: ty.clone(),
|
ty: ty.clone(),
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -235,7 +238,7 @@ pub fn generate_emscripten_env(globals: &EmscriptenGlobals) -> Imports {
|
|||||||
global: GlobalDesc {
|
global: GlobalDesc {
|
||||||
mutable: false,
|
mutable: false,
|
||||||
ty: ty.clone(),
|
ty: ty.clone(),
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -252,7 +255,6 @@ pub fn generate_emscripten_env(globals: &EmscriptenGlobals) -> Imports {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
env_namespace.insert(
|
env_namespace.insert(
|
||||||
"putchar",
|
"putchar",
|
||||||
Export::Function {
|
Export::Function {
|
||||||
|
@ -1,49 +1,40 @@
|
|||||||
macro_rules! assert_emscripten_output {
|
macro_rules! assert_emscripten_output {
|
||||||
($file:expr, $name:expr, $args:expr, $expected:expr) => {{
|
($file:expr, $name:expr, $args:expr, $expected:expr) => {{
|
||||||
// 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_clif_backend::CraneliftCompiler;
|
||||||
use wasmer_emscripten::{
|
use wasmer_emscripten::{
|
||||||
EmscriptenGlobals,
|
EmscriptenGlobals,
|
||||||
generate_emscripten_env,
|
generate_emscripten_env,
|
||||||
|
stdio::StdioCapturer
|
||||||
};
|
};
|
||||||
|
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
let wasm_bytes = include_bytes!($file);
|
let wasm_bytes = include_bytes!($file);
|
||||||
|
|
||||||
let module = compile(&wasm_bytes[..])
|
let module = wasmer_runtime::compile(&wasm_bytes[..], &CraneliftCompiler::new())
|
||||||
.map_err(|err| format!("Can't create the WebAssembly module: {}", err)).unwrap(); // NOTE: Need to figure what the unwrap is for ??
|
.expect("WASM can't be compiled");
|
||||||
|
|
||||||
|
// 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 emscripten_globals = EmscriptenGlobals::new();
|
||||||
let mut import_object = generate_emscripten_env(&emscripten_globals);
|
let import_object = generate_emscripten_env(&emscripten_globals);
|
||||||
|
|
||||||
let mut instance = module.instantiate(import_object)
|
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 ??
|
.map_err(|err| format!("Can't instantiate the WebAssembly module: {}", err)).unwrap(); // NOTE: Need to figure what the unwrap is for ??
|
||||||
|
|
||||||
start_instance(
|
// start_instance(
|
||||||
Arc::clone(&module),
|
// Arc::clone(&module),
|
||||||
&mut instance,
|
// &mut instance,
|
||||||
$name,
|
// $name,
|
||||||
$args,
|
// $args,
|
||||||
);
|
// );
|
||||||
|
|
||||||
assert!(false, "Emscripten tests are mocked");
|
assert!(false, "Emscripten tests are mocked");
|
||||||
|
|
||||||
// let capturer = StdioCapturer::new();
|
let capturer = StdioCapturer::new();
|
||||||
|
|
||||||
|
instance.call("_main", &[]).map(|_o| ()).unwrap();
|
||||||
|
// TODO handle start instance logic
|
||||||
// start_instance(
|
// start_instance(
|
||||||
// Arc::clone(&result_object.module),
|
// Arc::clone(&result_object.module),
|
||||||
// &mut result_object.instance,
|
// &mut result_object.instance,
|
||||||
@ -51,14 +42,14 @@ macro_rules! assert_emscripten_output {
|
|||||||
// $args,
|
// $args,
|
||||||
// )
|
// )
|
||||||
// .unwrap();
|
// .unwrap();
|
||||||
// let output = capturer.end().unwrap().0;
|
let output = capturer.end().unwrap().0;
|
||||||
// let expected_output = include_str!($expected);
|
let expected_output = include_str!($expected);
|
||||||
// assert!(false, "Emscripten tests are mocked");
|
assert!(false, "Emscripten tests are mocked");
|
||||||
// assert!(
|
assert!(
|
||||||
// output.contains(expected_output),
|
output.contains(expected_output),
|
||||||
// "Output: `{}` does not contain expected output: `{}`",
|
"Output: `{}` does not contain expected output: `{}`",
|
||||||
// output,
|
output,
|
||||||
// expected_output
|
expected_output
|
||||||
// );
|
);
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,2 @@
|
|||||||
pub mod mmap;
|
pub mod mmap;
|
||||||
pub mod slice;
|
pub mod slice;
|
||||||
|
|
||||||
mod file_descriptor;
|
|
||||||
//#[cfg(test)]
|
|
||||||
pub mod stdio;
|
|
Loading…
x
Reference in New Issue
Block a user