From 942cc966821c422c0ca467913795342e3e2a85c2 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Mon, 30 Mar 2026 20:42:26 +0200 Subject: [PATCH 1/2] cat: add WASI stub for is_unsafe_overwrite and add to feat_wasm WASI has no fstat-based device/inode checks, so always return false (assume safe) for the overwrite detection. --- Cargo.toml | 1 + src/uu/cat/src/platform/mod.rs | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 9cdfab875e7..86a13168f15 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -184,6 +184,7 @@ feat_wasm = [ "base32", "base64", "basenc", + "cat", "cut", "ls", "date", diff --git a/src/uu/cat/src/platform/mod.rs b/src/uu/cat/src/platform/mod.rs index 3fa27a27686..80ef6e233ac 100644 --- a/src/uu/cat/src/platform/mod.rs +++ b/src/uu/cat/src/platform/mod.rs @@ -9,6 +9,12 @@ pub use self::unix::is_unsafe_overwrite; #[cfg(windows)] pub use self::windows::is_unsafe_overwrite; +// WASI: no fstat-based device/inode checks available; assume safe. +#[cfg(target_os = "wasi")] +pub fn is_unsafe_overwrite(_input: &I, _output: &O) -> bool { + false +} + #[cfg(unix)] mod unix; From 91fa417bf5ad0e87ae30b4897d96d050453d2121 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Tue, 31 Mar 2026 23:03:41 +0200 Subject: [PATCH 2/2] wasm: add 22 more utilities to feat_wasm and add WASI platform stubs --- Cargo.toml | 24 +++++++++++++++++++++++- src/uu/ln/src/ln.rs | 7 +++++++ src/uu/split/src/platform/mod.rs | 28 ++++++++++++++++++++++++++++ src/uu/touch/src/touch.rs | 4 ++++ src/uu/tsort/src/tsort.rs | 1 - 5 files changed, 62 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 86a13168f15..42ffdb31c8f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -180,25 +180,36 @@ feat_Tier1 = [ # It is bit complex to deduplicate with other lists feat_wasm = [ "arch", - "basename", "base32", "base64", "basenc", + "basename", "cat", + "comm", + "cp", + "csplit", "cut", "ls", "date", + "dir", "dircolors", "dirname", "echo", "expand", + "expr", "factor", "false", "fmt", "fold", + "head", "join", "link", + "ln", + "ls", + "mkdir", + "mv", "nl", + "nproc", "numfmt", "od", "paste", @@ -208,18 +219,29 @@ feat_wasm = [ "printf", "ptx", "pwd", + "readlink", + "realpath", + "rm", + "rmdir", "seq", + "sort", + "split", "shred", "shuf", "sleep", "sum", + "tail", "tee", + "touch", + "tr", "true", "truncate", + "tsort", "uname", "unexpand", "uniq", "unlink", + "vdir", "wc", "yes", # cksum family diff --git a/src/uu/ln/src/ln.rs b/src/uu/ln/src/ln.rs index 1c7d40b8476..1d4cdcdabb6 100644 --- a/src/uu/ln/src/ln.rs +++ b/src/uu/ln/src/ln.rs @@ -23,6 +23,13 @@ use thiserror::Error; use std::os::unix::fs::symlink; #[cfg(windows)] use std::os::windows::fs::{symlink_dir, symlink_file}; +#[cfg(target_os = "wasi")] +fn symlink, P2: AsRef>(_src: P1, _dst: P2) -> std::io::Result<()> { + Err(std::io::Error::new( + std::io::ErrorKind::Unsupported, + "symlinks not supported on this platform", + )) +} use std::path::{Path, PathBuf}; use uucore::backup_control::{self, BackupMode}; use uucore::fs::{MissingHandling, ResolveMode, canonicalize}; diff --git a/src/uu/split/src/platform/mod.rs b/src/uu/split/src/platform/mod.rs index 5afc43eeb7f..0128e7f5552 100644 --- a/src/uu/split/src/platform/mod.rs +++ b/src/uu/split/src/platform/mod.rs @@ -12,6 +12,34 @@ pub use self::windows::instantiate_current_writer; #[cfg(windows)] pub use self::windows::paths_refer_to_same_file; +// WASI: no process spawning (filter) or device/inode comparison. +#[cfg(target_os = "wasi")] +pub fn paths_refer_to_same_file(_p1: &std::ffi::OsStr, _p2: &std::ffi::OsStr) -> bool { + false +} + +#[cfg(target_os = "wasi")] +pub fn instantiate_current_writer( + _filter: Option<&str>, + filename: &str, + is_new: bool, +) -> std::io::Result>> { + let file = if is_new { + std::fs::OpenOptions::new() + .write(true) + .create(true) + .truncate(true) + .open(std::path::Path::new(filename))? + } else { + std::fs::OpenOptions::new() + .append(true) + .open(std::path::Path::new(filename))? + }; + Ok(std::io::BufWriter::new( + Box::new(file) as Box + )) +} + #[cfg(unix)] mod unix; diff --git a/src/uu/touch/src/touch.rs b/src/uu/touch/src/touch.rs index d1080c1dddf..4cf4dce2299 100644 --- a/src/uu/touch/src/touch.rs +++ b/src/uu/touch/src/touch.rs @@ -883,6 +883,10 @@ fn pathbuf_from_stdout() -> Result { .map_err(|e| TouchError::WindowsStdoutPathError(e.to_string()))? .into()) } + #[cfg(target_os = "wasi")] + { + Ok(PathBuf::from("/dev/stdout")) + } } #[cfg(test)] diff --git a/src/uu/tsort/src/tsort.rs b/src/uu/tsort/src/tsort.rs index a689cd05be4..0c355e7bd31 100644 --- a/src/uu/tsort/src/tsort.rs +++ b/src/uu/tsort/src/tsort.rs @@ -82,7 +82,6 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { target_os = "linux", target_os = "android", target_os = "fuchsia", - target_os = "wasi", target_env = "uclibc", target_os = "freebsd", ))]