mirror of
https://github.com/fluencelabs/wasmer
synced 2024-12-12 22:05:33 +00:00
move stdio capture into runtime_core; rm emscripten dep in wasi
This commit is contained in:
parent
b9bb310215
commit
ec9c5360ef
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -2480,7 +2480,6 @@ dependencies = [
|
||||
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"wasmer-clif-backend 0.4.2",
|
||||
"wasmer-emscripten 0.4.2",
|
||||
"wasmer-runtime-core 0.4.2",
|
||||
"wasmer-singlepass-backend 0.4.2",
|
||||
]
|
||||
|
@ -23,6 +23,7 @@ rand = "0.6"
|
||||
|
||||
[dev-dependencies]
|
||||
wabt = "0.7.2"
|
||||
wasmer-runtime-core = { path = "../runtime-core", version = "0.4.2", features = ["regression-test"] }
|
||||
|
||||
[build-dependencies]
|
||||
glob = "0.2.11"
|
||||
|
@ -1,25 +0,0 @@
|
||||
use std::io;
|
||||
use std::io::Error;
|
||||
use std::io::ErrorKind;
|
||||
use std::io::Read;
|
||||
|
||||
pub struct FileDescriptor(libc::c_int);
|
||||
|
||||
impl FileDescriptor {
|
||||
pub fn new(file_descriptor_number: libc::c_int) -> FileDescriptor {
|
||||
FileDescriptor(file_descriptor_number)
|
||||
}
|
||||
}
|
||||
|
||||
impl Read for FileDescriptor {
|
||||
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
|
||||
let file_descriptor: libc::c_int = self.0;
|
||||
let count =
|
||||
unsafe { libc::read(file_descriptor, buf.as_mut_ptr() as *mut libc::c_void, 1) };
|
||||
if count < 0 {
|
||||
Err(Error::new(ErrorKind::Other, "read error"))
|
||||
} else {
|
||||
Ok(count as usize)
|
||||
}
|
||||
}
|
||||
}
|
@ -24,9 +24,6 @@ use wasmer_runtime_core::{
|
||||
|
||||
#[macro_use]
|
||||
mod macros;
|
||||
//#[cfg(test)]
|
||||
mod file_descriptor;
|
||||
pub mod stdio;
|
||||
|
||||
// EMSCRIPTEN APIS
|
||||
mod bitwise;
|
||||
|
@ -1,85 +0,0 @@
|
||||
use super::file_descriptor::FileDescriptor;
|
||||
use libc;
|
||||
use std::io::BufReader;
|
||||
use std::io::Read;
|
||||
|
||||
// A struct to hold the references to the base stdout and the captured one
|
||||
pub struct StdioCapturer {
|
||||
stdout_backup: libc::c_int,
|
||||
stderr_backup: libc::c_int,
|
||||
stdout_reader: libc::c_int,
|
||||
stderr_reader: libc::c_int,
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
use libc::{STDERR_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)
|
||||
impl StdioCapturer {
|
||||
fn pipe() -> (libc::c_int, libc::c_int) {
|
||||
let mut fds = [0; 2];
|
||||
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
assert_eq!(unsafe { libc::pipe(fds.as_mut_ptr()) }, 0);
|
||||
#[cfg(target_os = "windows")]
|
||||
assert_eq!(
|
||||
unsafe { libc::pipe(fds.as_mut_ptr(), 1000, libc::O_TEXT) },
|
||||
0
|
||||
);
|
||||
|
||||
(fds[0], fds[1])
|
||||
}
|
||||
|
||||
pub fn new() -> Self {
|
||||
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, 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
|
||||
// writers but no one supplying any input
|
||||
assert_eq!(unsafe { libc::close(stdout_writer) }, 0);
|
||||
assert_eq!(unsafe { libc::close(stderr_writer) }, 0);
|
||||
|
||||
StdioCapturer {
|
||||
stdout_backup,
|
||||
stderr_backup,
|
||||
stdout_reader,
|
||||
stderr_reader,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn end(self) -> Result<(String, String), std::io::Error> {
|
||||
// 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, 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);
|
||||
let mut stdout_read = "".to_string();
|
||||
let _ = reader.read_to_string(&mut stdout_read)?;
|
||||
|
||||
let fd = FileDescriptor::new(self.stderr_reader);
|
||||
let mut reader = BufReader::new(fd);
|
||||
let mut stderr_read = "".to_string();
|
||||
let _ = reader.read_to_string(&mut stderr_read)?;
|
||||
|
||||
Ok((stdout_read, stderr_read))
|
||||
}
|
||||
}
|
@ -4,9 +4,11 @@ macro_rules! assert_emscripten_output {
|
||||
use wasmer_emscripten::{
|
||||
EmscriptenGlobals,
|
||||
generate_emscripten_env,
|
||||
stdio::StdioCapturer
|
||||
};
|
||||
use wasmer_runtime_core::backend::Compiler;
|
||||
use wasmer_runtime_core::{
|
||||
stdio::StdioCapturer,
|
||||
backend::Compiler,
|
||||
};
|
||||
|
||||
#[cfg(feature = "clif")]
|
||||
fn get_compiler() -> impl Compiler {
|
||||
|
@ -50,3 +50,4 @@ rustc_version = "0.2.3"
|
||||
|
||||
[features]
|
||||
debug = []
|
||||
regression-test = []
|
@ -18,6 +18,8 @@ pub mod cache;
|
||||
pub mod codegen;
|
||||
pub mod error;
|
||||
pub mod export;
|
||||
#[cfg(any(test, feature = "regression-test"))]
|
||||
pub mod file_descriptor;
|
||||
pub mod global;
|
||||
pub mod import;
|
||||
pub mod instance;
|
||||
@ -26,6 +28,8 @@ pub mod memory;
|
||||
pub mod module;
|
||||
pub mod parse;
|
||||
mod sig_registry;
|
||||
#[cfg(any(test, feature = "regression-test"))]
|
||||
pub mod stdio;
|
||||
pub mod structures;
|
||||
mod sys;
|
||||
pub mod table;
|
||||
|
@ -18,15 +18,14 @@ generational-arena = "0.2.2"
|
||||
log = "0.4.6"
|
||||
byteorder = "1.3.1"
|
||||
# hack to get tests to work
|
||||
wasmer-singlepass-backend = { path = "../singlepass-backend", version = "0.4.2",optional = true }
|
||||
wasmer-singlepass-backend = { path = "../singlepass-backend", version = "0.4.2", optional = true }
|
||||
|
||||
[build-dependencies]
|
||||
glob = "0.2.11"
|
||||
|
||||
[dev-dependencies]
|
||||
# hack to get tests to work
|
||||
wasmer-emscripten = { path = "../emscripten", version = "0.4.2"}
|
||||
wasmer-clif-backend = { path = "../clif-backend", version = "0.4.2" }
|
||||
wasmer-runtime-core = { path = "../runtime-core", version = "0.4.2", features = ["regression-test"] }
|
||||
|
||||
[features]
|
||||
clif = []
|
||||
|
@ -1,8 +1,6 @@
|
||||
macro_rules! assert_wasi_output {
|
||||
($file:expr, $name:expr, $args:expr, $expected:expr) => {{
|
||||
// HACK(mark): remove dep on emscripten
|
||||
use wasmer_emscripten::stdio::StdioCapturer;
|
||||
use wasmer_runtime_core::{backend::Compiler, Func};
|
||||
use wasmer_runtime_core::{backend::Compiler, stdio::StdioCapturer, Func};
|
||||
use wasmer_wasi::generate_import_object;
|
||||
|
||||
#[cfg(feature = "clif")]
|
||||
|
Loading…
Reference in New Issue
Block a user