From 2d9d61d50cd6553776c9ca94d0e69b0e1568bb39 Mon Sep 17 00:00:00 2001 From: Christoph Herzog Date: Wed, 3 Apr 2024 20:36:13 +0200 Subject: [PATCH 1/3] deps: Switch from unmaintained term_size to terminal_size The term_size crate has been unmaintained for years. The RUSTSEC warning recommends terminal-size instead. The crate seems stable, and a review of the code shows it's safe to use and does what is expected. (no build.rs or similar, only calls to the relevant syscalls). Gets rid of a RUSTSEC warning. --- Cargo.lock | 20 ++++++++++---------- lib/wasix/Cargo.toml | 2 +- lib/wasix/src/os/tty/tty_sys.rs | 8 +++++--- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1503414fe24..0a263d00c34 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4751,22 +4751,22 @@ dependencies = [ ] [[package]] -name = "term_size" -version = "0.3.2" +name = "termcolor" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e4129646ca0ed8f45d09b929036bafad5377103edd06e50bf574b353d2b08d9" +checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" dependencies = [ - "libc", - "winapi 0.3.9", + "winapi-util", ] [[package]] -name = "termcolor" -version = "1.4.1" +name = "terminal_size" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" +checksum = "21bebf2b7c9e0a515f6e0f8c51dc0f8e4696391e6f1ff30379559f8365fb0df7" dependencies = [ - "winapi-util", + "rustix", + "windows-sys 0.48.0", ] [[package]] @@ -6815,7 +6815,7 @@ dependencies = [ "sha2", "shared-buffer", "tempfile", - "term_size", + "terminal_size", "termios", "thiserror", "tokio 1.36.0", diff --git a/lib/wasix/Cargo.toml b/lib/wasix/Cargo.toml index 05dacf6fb0e..2b5735b36e5 100644 --- a/lib/wasix/Cargo.toml +++ b/lib/wasix/Cargo.toml @@ -57,7 +57,7 @@ serde_json = { version = "^1" } serde_yaml = { version = "^0.9" } weezl = { version = "^0.1" } hex = { version = "^0.4" } -term_size = { version = "0.3" } +terminal_size = { version = "0.3.0" } linked_hash_set = { version = "0.1" } http = "0.2.8" heapless = "0.7.16" diff --git a/lib/wasix/src/os/tty/tty_sys.rs b/lib/wasix/src/os/tty/tty_sys.rs index fbbf9cc00a6..2b16e3fa148 100644 --- a/lib/wasix/src/os/tty/tty_sys.rs +++ b/lib/wasix/src/os/tty/tty_sys.rs @@ -18,10 +18,12 @@ impl TtyBridge for SysTty { let stdout_tty = sys::is_stdout_tty(); let stderr_tty = sys::is_stderr_tty(); - if let Some((w, h)) = term_size::dimensions() { + if let Some((terminal_size::Width(width), terminal_size::Height(height))) = + terminal_size::terminal_size() + { WasiTtyState { - cols: w as u32, - rows: h as u32, + cols: width.into(), + rows: height.into(), width: 800, height: 600, stdin_tty, From 5b5b1f06e18cce6eb23e15dfed8261ced5e457ae Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Mon, 15 Apr 2024 17:44:48 +0200 Subject: [PATCH 2/3] Improved WASIX tty --- lib/wasix/Cargo.toml | 4 ++- lib/wasix/src/os/tty/tty_sys.rs | 62 ++++++++++++++++++--------------- 2 files changed, 36 insertions(+), 30 deletions(-) diff --git a/lib/wasix/Cargo.toml b/lib/wasix/Cargo.toml index 2b5735b36e5..cea67105e06 100644 --- a/lib/wasix/Cargo.toml +++ b/lib/wasix/Cargo.toml @@ -57,7 +57,6 @@ serde_json = { version = "^1" } serde_yaml = { version = "^0.9" } weezl = { version = "^0.1" } hex = { version = "^0.4" } -terminal_size = { version = "0.3.0" } linked_hash_set = { version = "0.1" } http = "0.2.8" heapless = "0.7.16" @@ -121,6 +120,9 @@ termios = { version = "0.3" } [target.'cfg(windows)'.dependencies] winapi = "0.3" +[target.'cfg(not(target_arch = "wasm32"))'.dependencies] +terminal_size = { version = "0.3.0" } + [dev-dependencies] wasmer = { path = "../api", version = "=4.2.7", default-features = false, features = ["wat", "js-serializable-module"] } tokio = { version = "1", features = [ "sync", "macros", "rt" ], default_features = false } diff --git a/lib/wasix/src/os/tty/tty_sys.rs b/lib/wasix/src/os/tty/tty_sys.rs index 2b16e3fa148..90ea7484bef 100644 --- a/lib/wasix/src/os/tty/tty_sys.rs +++ b/lib/wasix/src/os/tty/tty_sys.rs @@ -17,35 +17,19 @@ impl TtyBridge for SysTty { let stdin_tty = sys::is_stdin_tty(); let stdout_tty = sys::is_stdout_tty(); let stderr_tty = sys::is_stderr_tty(); - - if let Some((terminal_size::Width(width), terminal_size::Height(height))) = - terminal_size::terminal_size() - { - WasiTtyState { - cols: width.into(), - rows: height.into(), - width: 800, - height: 600, - stdin_tty, - stdout_tty, - stderr_tty, - echo, - line_buffered, - line_feeds, - } - } else { - WasiTtyState { - rows: 80, - cols: 25, - width: 800, - height: 600, - stdin_tty, - stdout_tty, - stderr_tty, - echo, - line_buffered, - line_feeds, - } + let (cols, rows) = sys_terminal_size::get_terminal_size(); + + WasiTtyState { + cols: cols, + rows: rows, + width: 800, + height: 600, + stdin_tty, + stdout_tty, + stderr_tty, + echo, + line_buffered, + line_feeds, } } @@ -68,6 +52,26 @@ impl TtyBridge for SysTty { } } +mod sys_terminal_size { + static DEFAULT_SIZE: (u32, u32) = (80, 25); + + #[cfg(not(target_arch = "wasm32"))] + pub fn get_terminal_size() -> (u32, u32) { + if let Some((terminal_size::Width(width), terminal_size::Height(height))) = + terminal_size::terminal_size() + { + (width.into(), height.into()) + } else { + DEFAULT_SIZE + } + } + + #[cfg(target_arch = "wasm32")] + pub fn get_terminal_size() -> (u32, u32) { + DEFAULT_SIZE + } +} + #[allow(unused_mut)] #[cfg(all(unix, not(target_os = "ios")))] mod sys { From f5c605607203445626b08a2d8895c9e4b1c523fe Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Mon, 15 Apr 2024 17:45:31 +0200 Subject: [PATCH 3/3] Fixed linting --- lib/wasix/src/os/tty/tty_sys.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/wasix/src/os/tty/tty_sys.rs b/lib/wasix/src/os/tty/tty_sys.rs index 90ea7484bef..d269ff9403a 100644 --- a/lib/wasix/src/os/tty/tty_sys.rs +++ b/lib/wasix/src/os/tty/tty_sys.rs @@ -20,8 +20,8 @@ impl TtyBridge for SysTty { let (cols, rows) = sys_terminal_size::get_terminal_size(); WasiTtyState { - cols: cols, - rows: rows, + cols, + rows, width: 800, height: 600, stdin_tty,