fix windows linking and appveyor build (#166)

This commit is contained in:
Mackenzie Clark
2019-02-08 13:51:29 -08:00
committed by GitHub
parent 1886b3d3c1
commit 9a56680281
7 changed files with 53 additions and 149 deletions

View File

@ -9,7 +9,6 @@ use crate::env::call_malloc;
use crate::utils::{copy_cstr_into_wasm, read_string_from_wasm};
use wasmer_runtime_core::vm::Ctx;
#[link(name = "c")]
extern "C" {
#[link_name = "_putenv"]
pub fn putenv(s: *const c_char) -> c_int;

View File

@ -5,14 +5,14 @@ use wasmer_runtime_core::vm::Ctx;
// 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;
}
//#[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) {
@ -22,8 +22,9 @@ pub fn putchar(chr: i32, ctx: &mut Ctx) {
/// 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)
}
// unsafe {
// let addr = emscripten_memory_pointer!(ctx.memory(0), memory_offset) as _;
// _printf(addr, extra)
// }
-1
}

View File

@ -11,6 +11,16 @@ pub struct StdioCapturer {
stderr_reader: libc::c_int,
}
#[cfg(not(target_os = "windows"))]
use libc::{STDERR_FILENO, STDIN_FILENO, STDOUT_FILENO};
#[cfg(target_os = "windows")]
const STDIN_FILENO: libc::c_int = 0;
#[cfg(target_os = "windows")]
const STDOUT_FILENO: libc::c_int = 1;
#[cfg(target_os = "windows")]
const STDERR_FILENO: libc::c_int = 2;
// Implementation inspired in
// https://github.com/rust-lang/rust/blob/7d52cbce6db83e4fc2d8706b4e4b9c7da76cbcf8/src/test/run-pass/issues/issue-30490.rs
// Currently only works in Unix systems (Mac, Linux)
@ -30,14 +40,14 @@ impl StdioCapturer {
}
pub fn new() -> Self {
let stdout_backup = unsafe { libc::dup(libc::STDOUT_FILENO) };
let stderr_backup = unsafe { libc::dup(libc::STDERR_FILENO) };
let stdout_backup = unsafe { libc::dup(STDOUT_FILENO) };
let stderr_backup = unsafe { libc::dup(STDERR_FILENO) };
let (stdout_reader, stdout_writer) = Self::pipe();
let (stderr_reader, stderr_writer) = Self::pipe();
assert!(unsafe { libc::dup2(stdout_writer, libc::STDOUT_FILENO) } > -1);
assert!(unsafe { libc::dup2(stderr_writer, libc::STDERR_FILENO) } > -1);
assert!(unsafe { libc::dup2(stdout_writer, STDOUT_FILENO) } > -1);
assert!(unsafe { libc::dup2(stderr_writer, STDERR_FILENO) } > -1);
// Make sure we close any duplicates of the writer end of the pipe,
// otherwise we can get stuck reading from the pipe which has open
@ -57,8 +67,8 @@ impl StdioCapturer {
// The Stdio passed into the Command took over (and closed) std{out, err}
// so we should restore them as they were.
assert!(unsafe { libc::dup2(self.stdout_backup, libc::STDOUT_FILENO) } > -1);
assert!(unsafe { libc::dup2(self.stderr_backup, libc::STDERR_FILENO) } > -1);
assert!(unsafe { libc::dup2(self.stdout_backup, STDOUT_FILENO) } > -1);
assert!(unsafe { libc::dup2(self.stderr_backup, STDERR_FILENO) } > -1);
let fd = FileDescriptor::new(self.stdout_reader);
let mut reader = BufReader::new(fd);

View File

@ -10,7 +10,6 @@ use libc::{clockid_t, time as libc_time};
type clockid_t = c_int;
#[cfg(target_os = "windows")]
#[link(name = "c")]
extern "C" {
#[link_name = "time"]
pub fn libc_time(s: *const time_t) -> time_t;