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

create the windows io mod and link printf #144

Merged
merged 9 commits into from
Feb 7, 2019
11 changes: 11 additions & 0 deletions lib/emscripten/src/io/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#[cfg(unix)]
mod unix;

#[cfg(windows)]
mod windows;

#[cfg(unix)]
pub use self::unix::*;

#[cfg(windows)]
pub use self::windows::*;
File renamed without changes.
29 changes: 29 additions & 0 deletions lib/emscripten/src/io/windows.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use libc::{c_char, c_int};
use wasmer_runtime_core::vm::Ctx;

// This may be problematic for msvc which uses inline functions for the printf family
// this cfg_attr will try to link with the legacy lib that does not inline printf
// this will allow for compiliation, but will produce a linker error if there is a problem
// finding printf.
#[cfg_attr(
all(windows, target_env = "msvc"),
link(name = "legacy_stdio_definitions", kind = "static-nobundle")
)]
extern "C" {
#[link_name = "printf"]
pub fn _printf(s: *const c_char, ...) -> c_int;
}

/// putchar
pub fn putchar(chr: i32, ctx: &mut Ctx) {
unsafe { libc::putchar(chr) };
}

/// printf
pub fn printf(memory_offset: i32, extra: i32, ctx: &mut Ctx) -> i32 {
debug!("emscripten::printf {}, {}", memory_offset, extra);
unsafe {
let addr = emscripten_memory_pointer!(ctx.memory(0), memory_offset) as _;
_printf(addr, extra)
}
}