Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix master; add some emscripten calls #328

Merged
merged 5 commits into from
Apr 5, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix master; add some emscripten calls
  • Loading branch information
Mark McCaskey committed Apr 5, 2019
commit 91d741668081ba83d5b23592d90a4389980e704f
5 changes: 5 additions & 0 deletions lib/emscripten/src/exception.rs
Original file line number Diff line number Diff line change
@@ -23,3 +23,8 @@ pub fn ___cxa_begin_catch(_ctx: &mut Ctx, _exception_object_ptr: u32) -> i32 {
pub fn ___cxa_end_catch(_ctx: &mut Ctx) {
debug!("emscripten::___cxa_end_catch");
}

pub fn ___cxa_uncaught_exception(_ctx: &mut Ctx) -> i32 {
debug!("emscripten::___cxa_uncaught_exception");
-1
}
2 changes: 2 additions & 0 deletions lib/emscripten/src/lib.rs
Original file line number Diff line number Diff line change
@@ -607,6 +607,7 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject
"___cxa_throw" => func!(crate::exception::___cxa_throw),
"___cxa_begin_catch" => func!(crate::exception::___cxa_begin_catch),
"___cxa_end_catch" => func!(crate::exception::___cxa_end_catch),
"___cxa_uncaught_exception" => func!(crate::exception::___cxa_uncaught_exception),

// Time
"_gettimeofday" => func!(crate::time::_gettimeofday),
@@ -619,6 +620,7 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject
"_localtime" => func!(crate::time::_localtime),
"_time" => func!(crate::time::_time),
"_strftime" => func!(crate::time::_strftime),
"_strftime_l" => func!(crate::time::_strftime_l),
"_localtime_r" => func!(crate::time::_localtime_r),
"_gmtime_r" => func!(crate::time::_gmtime_r),
"_mktime" => func!(crate::time::_mktime),
17 changes: 17 additions & 0 deletions lib/emscripten/src/time.rs
Original file line number Diff line number Diff line change
@@ -310,3 +310,20 @@ pub fn _strftime(
);
0
}

/// emscripten: _strftime_l
pub fn _strftime_l(
ctx: &mut Ctx,
s_ptr: c_int,
maxsize: u32,
format_ptr: c_int,
tm_ptr: c_int,
_last: c_int,
) -> i32 {
debug!(
"emscripten::_strftime_l {} {} {} {}",
s_ptr, maxsize, format_ptr, tm_ptr
);

_strftime(ctx, s_ptr, maxsize, format_ptr, tm_ptr)
}
66 changes: 37 additions & 29 deletions src/bin/wasmer.rs
Original file line number Diff line number Diff line change
@@ -17,6 +17,20 @@ use wasmer_runtime_core::{self, backend::CompilerConfig};
#[cfg(feature = "wasi")]
use wasmer_wasi;

// stub module to make conditional compilation happy
#[cfg(not(feature = "wasi"))]
mod wasmer_wasi {
use wasmer_runtime_core::{import::ImportObject, module::Module};

pub fn is_wasi_module(_module: &Module) -> bool {
false
}

pub fn generate_import_object(_args: Vec<Vec<u8>>, _envs: Vec<Vec<u8>>) -> ImportObject {
unimplemented!()
}
}

#[derive(Debug, StructOpt)]
#[structopt(name = "wasmer", about = "Wasm execution runtime.")]
/// The options for the wasmer Command Line Interface
@@ -213,7 +227,6 @@ 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 mut emscripten_globals = wasmer_emscripten::EmscriptenGlobals::new(&module);
(
@@ -222,34 +235,29 @@ fn execute_wasm(options: &Run) -> Result<(), String> {
Some(emscripten_globals), // TODO Em Globals is here to extend, lifetime, find better solution
)
} else {
(
InstanceABI::None,
wasmer_runtime_core::import::ImportObject::new(),
None,
)
};

#[cfg(feature = "wasi")]
let (abi, import_object) = if wasmer_wasi::is_wasi_module(&module) {
(
InstanceABI::WASI,
wasmer_wasi::generate_import_object(
[options.path.to_str().unwrap().to_owned()]
.iter()
.chain(options.args.iter())
.cloned()
.map(|arg| arg.into_bytes())
.collect(),
env::vars()
.map(|(k, v)| format!("{}={}", k, v).into_bytes())
.collect(),
),
)
} else {
(
InstanceABI::None,
wasmer_runtime_core::import::ImportObject::new(),
)
if cfg!(feature = "wasi") && wasmer_wasi::is_wasi_module(&module) {
(
InstanceABI::WASI,
wasmer_wasi::generate_import_object(
[options.path.to_str().unwrap().to_owned()]
.iter()
.chain(options.args.iter())
.cloned()
.map(|arg| arg.into_bytes())
.collect(),
env::vars()
.map(|(k, v)| format!("{}={}", k, v).into_bytes())
.collect(),
),
None,
)
} else {
(
InstanceABI::None,
wasmer_runtime_core::import::ImportObject::new(),
None,
)
}
};

let mut instance = module