Skip to content

Commit

Permalink
Improved Emscripten / WASI autodetection
Browse files Browse the repository at this point in the history
  • Loading branch information
syrusakbary committed Sep 23, 2019
1 parent bafd318 commit 9942d3a
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 13 deletions.
6 changes: 0 additions & 6 deletions lib/emscripten-tests/emtests/issue_577.cpp

This file was deleted.

Binary file removed lib/emscripten-tests/emtests/issue_577.wasm
Binary file not shown.
4 changes: 3 additions & 1 deletion lib/emscripten/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions lib/runtime-core/src/structures/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 6 additions & 3 deletions lib/wasi/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
6 changes: 3 additions & 3 deletions src/bin/wasmer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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))?;

Expand Down

0 comments on commit 9942d3a

Please sign in to comment.