wasm: add 22 more utilities to feat_wasm and add WASI platform stubs

This commit is contained in:
Sylvestre Ledru
2026-03-31 23:03:41 +02:00
parent cad160f9f3
commit 9aeaa68d27
5 changed files with 59 additions and 2 deletions
+19 -1
View File
@@ -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
+8
View File
@@ -488,3 +488,11 @@ pub fn symlink<P1: AsRef<Path>, P2: AsRef<Path>>(src: P1, dst: P2) -> std::io::R
symlink_file(src, dst)
}
}
#[cfg(target_os = "wasi")]
fn symlink<P1: AsRef<Path>, P2: AsRef<Path>>(_src: P1, _dst: P2) -> std::io::Result<()> {
Err(std::io::Error::new(
std::io::ErrorKind::Unsupported,
"symlinks not supported on this platform",
))
}
+28
View File
@@ -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<std::io::BufWriter<Box<dyn std::io::Write>>> {
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<dyn std::io::Write>
))
}
#[cfg(unix)]
mod unix;
+4
View File
@@ -883,6 +883,10 @@ fn pathbuf_from_stdout() -> Result<PathBuf, TouchError> {
.map_err(|e| TouchError::WindowsStdoutPathError(e.to_string()))?
.into())
}
#[cfg(target_os = "wasi")]
{
Ok(PathBuf::from("/dev/stdout"))
}
}
#[cfg(test)]
-1
View File
@@ -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",
))]