diff --git a/Cargo.toml b/Cargo.toml index 5a481e4d..72d828cd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,12 +20,21 @@ bincode = "1.3.1" structopt = "0.3" serde_yaml = "0.8" serde_json = "1.0" -wasmer = { git = "https://github.com/wasmerio/wasmer.git" } -wasmer-wasi = { git = "https://github.com/wasmerio/wasmer.git" } [dependencies.async-std] version = "1.3.0" features = ["unstable"] +[dependencies.wasmer] +git = "https://github.com/wasmerio/wasmer.git" +optional = true + +[dependencies.wasmer-wasi] +git = "https://github.com/wasmerio/wasmer.git" +optional = true + +[features] +wasm-wip = ["wasmer", "wasmer-wasi"] + [dev-dependencies] insta = "0.16.1" diff --git a/src/main.rs b/src/main.rs index 0f5fcf06..08bc37c3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,19 +11,15 @@ mod screen; mod terminal_pane; mod utils; -use std::io::{self, Read, Write}; +use std::io::Write; use std::os::unix::net::UnixStream; use std::path::PathBuf; use std::sync::mpsc::{channel, Receiver, Sender}; -use std::sync::{Arc, Mutex}; use std::thread; use serde::{Deserialize, Serialize}; use structopt::StructOpt; -use wasmer::{Exports, Function, Instance, Module, Store, Value}; -use wasmer_wasi::WasiState; - use crate::command_is_executing::CommandIsExecuting; use crate::input::input_loop; use crate::layout::Layout; @@ -257,13 +253,17 @@ pub fn start(mut os_input: Box, opts: Opt) { // Here be dragons! This is very much a work in progress, and isn't quite functional // yet. It's being left out of the tests because is slows them down massively (by // recompiling a WASM module for every single test). Stay tuned for more updates! - #[cfg(not(test))] + #[cfg(feature = "wasm-wip")] active_threads.push( thread::Builder::new() .name("wasm".to_string()) .spawn(move || { // TODO: Clone shared state here move || -> Result<(), Box> { + use std::io; + use std::sync::{Arc, Mutex}; + use wasmer::{Exports, Function, Instance, Module, Store, Value}; + use wasmer_wasi::WasiState; let store = Store::default(); println!("Compiling module..."); @@ -364,6 +364,7 @@ pub fn start(mut os_input: Box, opts: Opt) { let _ipc_thread = thread::Builder::new() .name("ipc_server".to_string()) .spawn({ + use std::io::Read; let send_pty_instructions = send_pty_instructions.clone(); let send_screen_instructions = send_screen_instructions.clone(); move || { diff --git a/src/pty_bus.rs b/src/pty_bus.rs index 3c8abcff..078e3271 100644 --- a/src/pty_bus.rs +++ b/src/pty_bus.rs @@ -11,7 +11,7 @@ use std::path::PathBuf; use crate::layout::Layout; use crate::os_input_output::OsApi; -use crate::utils::logging::{debug_log_to_file, debug_to_file}; +use crate::utils::logging::debug_to_file; use crate::ScreenInstruction; pub struct ReadFromPid { diff --git a/src/screen.rs b/src/screen.rs index 53655216..56bb82d2 100644 --- a/src/screen.rs +++ b/src/screen.rs @@ -380,8 +380,14 @@ impl Screen { } } pub fn handle_pty_event(&mut self, pid: RawFd, event: VteEvent) { - let terminal_output = self.terminals.get_mut(&pid).unwrap(); - terminal_output.handle_event(event); + // if we don't have the terminal in self.terminals it's probably because + // of a race condition where the terminal was created in pty_bus but has not + // yet been created in Screen. These events are currently not buffered, so + // if you're debugging seemingly randomly missing stdout data, this is + // the reason + if let Some(terminal_output) = self.terminals.get_mut(&pid) { + terminal_output.handle_event(event); + } } pub fn write_to_active_terminal(&mut self, mut bytes: Vec) { if let Some(active_terminal_id) = &self.get_active_terminal_id() { diff --git a/src/utils/logging.rs b/src/utils/logging.rs index e175050e..fa302b09 100644 --- a/src/utils/logging.rs +++ b/src/utils/logging.rs @@ -23,14 +23,9 @@ pub fn atomic_create_dir(dir_name: &str) -> io::Result<()> { } } -pub fn debug_log_to_file(message: String) -> io::Result<()> { - atomic_create_file(MOSAIC_TMP_LOG_FILE); - let mut file = fs::OpenOptions::new() - .append(true) - .create(true) - .open(MOSAIC_TMP_LOG_FILE)?; - file.write_all(message.as_bytes())?; - file.write_all(b"\n") +pub fn debug_log_to_file(mut message: String) -> io::Result<()> { + message.push('\n'); + debug_log_to_file_without_newline(message) } pub fn debug_log_to_file_without_newline(message: String) -> io::Result<()> { @@ -39,9 +34,7 @@ pub fn debug_log_to_file_without_newline(message: String) -> io::Result<()> { .append(true) .create(true) .open(MOSAIC_TMP_LOG_FILE)?; - file.write_all(message.as_bytes())?; - - Ok(()) + file.write_all(message.as_bytes()) } pub fn debug_log_to_file_pid_0(message: String, pid: RawFd) -> io::Result<()> {