mirror of
https://github.com/fluencelabs/wasmer
synced 2024-12-14 14:45:40 +00:00
create the windows io mod and link printf (#144)
This commit is contained in:
parent
0a7b9b26b8
commit
ac286b708b
11
lib/emscripten/src/io/mod.rs
Normal file
11
lib/emscripten/src/io/mod.rs
Normal file
@ -0,0 +1,11 @@
|
||||
#[cfg(unix)]
|
||||
mod unix;
|
||||
|
||||
#[cfg(windows)]
|
||||
mod windows;
|
||||
|
||||
#[cfg(unix)]
|
||||
pub use self::unix::*;
|
||||
|
||||
#[cfg(windows)]
|
||||
pub use self::windows::*;
|
29
lib/emscripten/src/io/windows.rs
Normal file
29
lib/emscripten/src/io/windows.rs
Normal file
@ -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)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user