Skip to content

Commit

Permalink
Merge branch 'feature/wasi' of github.com:wasmerio/wasmer into featur…
Browse files Browse the repository at this point in the history
…e/wasi
  • Loading branch information
lachlansneff committed Mar 29, 2019
2 parents b1030d3 + 514432c commit 4df5f02
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
5 changes: 3 additions & 2 deletions src/bin/wasmer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ fn execute_wasm(options: &Run) -> Result<(), String> {

// TODO: refactor this
#[cfg(not(feature = "wasi"))]
let (_abi, import_object, _em_globals) = if wasmer_emscripten::is_emscripten_module(&module) {
let (abi, import_object, _em_globals) = if wasmer_emscripten::is_emscripten_module(&module) {
let mut emscripten_globals = wasmer_emscripten::EmscriptenGlobals::new(&module);
(
InstanceABI::Emscripten,
Expand All @@ -220,7 +220,7 @@ fn execute_wasm(options: &Run) -> Result<(), String> {
};

#[cfg(feature = "wasi")]
let (_abi, import_object) = if wasmer_wasi::is_wasi_module(&module) {
let (abi, import_object) = if wasmer_wasi::is_wasi_module(&module) {
(
InstanceABI::WASI,
wasmer_wasi::generate_import_object(
Expand Down Expand Up @@ -249,6 +249,7 @@ fn execute_wasm(options: &Run) -> Result<(), String> {
webassembly::run_instance(
&module,
&mut instance,
abi,
options.path.to_str().unwrap(),
options.args.iter().map(|arg| arg.as_str()).collect(),
)
Expand Down
28 changes: 17 additions & 11 deletions src/webassembly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use wasmer_runtime::{
use wasmer_runtime_core::backend::CompilerConfig;
use wasmer_runtime_core::types::Value;

use wasmer_emscripten::{is_emscripten_module, run_emscripten_instance};
use wasmer_emscripten::run_emscripten_instance;

pub struct ResultObject {
/// A webassembly::Module object representing the compiled WebAssembly module.
Expand Down Expand Up @@ -93,18 +93,24 @@ pub fn compile_with_config(
pub fn run_instance(
module: &Module,
instance: &mut Instance,
abi: InstanceABI,
path: &str,
args: Vec<&str>,
) -> CallResult<()> {
if is_emscripten_module(module) {
run_emscripten_instance(module, instance, path, args)?;
} else {
let args: Vec<Value> = args
.into_iter()
.map(|x| Value::I32(x.parse().unwrap()))
.collect();
instance.call("main", &args)?;
};

match abi {
InstanceABI::Emscripten => {
run_emscripten_instance(module, instance, path, args)?;
}
InstanceABI::WASI => {
instance.call("_start", &[])?;
}
InstanceABI::None => {
let args: Vec<Value> = args
.into_iter()
.map(|x| Value::I32(x.parse().unwrap()))
.collect();
instance.call("main", &args)?;
}
}
Ok(())
}

0 comments on commit 4df5f02

Please sign in to comment.