From 9aeaa68d270cc37903d8b0890cf9667e15e7b18a Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Tue, 31 Mar 2026 23:03:41 +0200 Subject: [PATCH] wasm: add 22 more utilities to feat_wasm and add WASI platform stubs --- Cargo.toml | 20 +++++++++++++++++++- src/uu/ln/src/ln.rs | 8 ++++++++ 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, 59 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index cb27c7806..10b0369ca 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -180,27 +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", @@ -211,7 +220,13 @@ feat_wasm = [ "printf", "ptx", "pwd", + "readlink", + "realpath", + "rm", + "rmdir", "seq", + "sort", + "split", "shred", "shuf", "sleep", @@ -219,13 +234,16 @@ feat_wasm = [ "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 1c7d40b84..f7c953908 100644 --- a/src/uu/ln/src/ln.rs +++ b/src/uu/ln/src/ln.rs @@ -488,3 +488,11 @@ pub fn symlink, P2: AsRef>(src: P1, dst: P2) -> std::io::R symlink_file(src, dst) } } + +#[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", + )) +} diff --git a/src/uu/split/src/platform/mod.rs b/src/uu/split/src/platform/mod.rs index 5afc43eeb..0128e7f55 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 d1080c1dd..4cf4dce22 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 5b2fb66d6..1868af85c 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", ))]