mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-24 14:11:32 +00:00
Improved Emscripten / WASI autodetection
This commit is contained in:
@ -1,6 +0,0 @@
|
||||
#include <iostream>
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
std::cout << "Does this work?" << std::endl;
|
||||
return 0;
|
||||
}
|
Binary file not shown.
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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))?;
|
||||
|
||||
|
Reference in New Issue
Block a user