Improved Emscripten / WASI autodetection

This commit is contained in:
Syrus
2019-09-22 18:23:22 -07:00
parent bafd318284
commit 9942d3ae98
6 changed files with 16 additions and 13 deletions

View File

@ -1,6 +0,0 @@
#include <iostream>
int main(int argc, char* argv[]) {
std::cout << "Does this work?" << std::endl;
return 0;
}

View File

@ -24,7 +24,9 @@ pub fn is_emscripten_module(module: &Module) -> bool {
.namespace_table
.get(import_name.namespace_index);
let field = module.info().name_table.get(import_name.name_index);
if (field == "_emscripten_memcpy_big" || field == "emscripten_memcpy_big")
if (field == "_emscripten_memcpy_big"
|| field == "emscripten_memcpy_big"
|| field == "__map_file")
&& namespace == "env"
{
return true;

View File

@ -39,6 +39,10 @@ where
self.elems.len()
}
pub fn is_empty(&self) -> bool {
self.elems.is_empty()
}
pub fn push(&mut self, value: V) -> K {
let len = self.len();
self.elems.push(value);

View File

@ -2,14 +2,17 @@ use wasmer_runtime_core::module::Module;
/// Check if a provided module is compiled with WASI support
pub fn is_wasi_module(module: &Module) -> bool {
if module.info().imported_functions.is_empty() {
return false;
}
for (_, import_name) in &module.info().imported_functions {
let namespace = module
.info()
.namespace_table
.get(import_name.namespace_index);
if namespace == "wasi_unstable" {
return true;
if namespace != "wasi_unstable" {
return false;
}
}
false
true
}

View File

@ -512,7 +512,7 @@ fn execute_wasm(options: &Run) -> Result<(), String> {
import_object.allow_missing_functions = true; // Import initialization might be left to the loader.
let instance = module
.instantiate(&import_object)
.map_err(|e| format!("Can't instantiate module: {:?}", e))?;
.map_err(|e| format!("Can't instantiate loader module: {:?}", e))?;
let args: Vec<Value> = options
.args
@ -551,7 +551,7 @@ fn execute_wasm(options: &Run) -> Result<(), String> {
let import_object = wasmer_emscripten::generate_emscripten_env(&mut emscripten_globals);
let mut instance = module
.instantiate(&import_object)
.map_err(|e| format!("Can't instantiate module: {:?}", e))?;
.map_err(|e| format!("Can't instantiate emscripten module: {:?}", e))?;
wasmer_emscripten::run_emscripten_instance(
&module,
@ -591,7 +591,7 @@ fn execute_wasm(options: &Run) -> Result<(), String> {
#[allow(unused_mut)] // mut used in feature
let mut instance = module
.instantiate(&import_object)
.map_err(|e| format!("Can't instantiate module: {:?}", e))?;
.map_err(|e| format!("Can't instantiate WASI module: {:?}", e))?;
let start: Func<(), ()> = instance.func("_start").map_err(|e| format!("{:?}", e))?;