From b1c267fd735c6543f220e450373d952691e9b712 Mon Sep 17 00:00:00 2001 From: viju Date: Tue, 12 May 2026 20:25:32 +0530 Subject: [PATCH] dd: support wasm32-wasip1 (#12258) --- .github/workflows/wasi.yml | 2 +- Cargo.toml | 1 + src/uu/dd/src/conversion_tables.rs | 10 ++++++++-- src/uu/dd/src/dd.rs | 4 +++- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/.github/workflows/wasi.yml b/.github/workflows/wasi.yml index 8c3721d6a..c69414ccc 100644 --- a/.github/workflows/wasi.yml +++ b/.github/workflows/wasi.yml @@ -37,7 +37,7 @@ jobs: CARGO_TARGET_WASM32_WASIP1_RUNNER: wasmtime run: | # Get all utilities and exclude ones that don't compile for wasm32-wasip1 - EXCLUDE="dd|df|du|env|expr|mktemp|more|tac|test" + EXCLUDE="df|du|env|expr|mktemp|more|tac|test" UTILS=$(./util/show-utils.sh | tr ' ' '\n' | grep -vE "^($EXCLUDE)$" | sed 's/^/-p uu_/' | tr '\n' ' ') cargo test --target wasm32-wasip1 --no-default-features $UTILS - name: Run integration tests via wasmtime diff --git a/Cargo.toml b/Cargo.toml index f62ac1287..a775c1e7e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -190,6 +190,7 @@ feat_wasm = [ "csplit", "cut", "date", + "dd", "dir", "dircolors", "dirname", diff --git a/src/uu/dd/src/conversion_tables.rs b/src/uu/dd/src/conversion_tables.rs index 57d8f162b..8ad529264 100644 --- a/src/uu/dd/src/conversion_tables.rs +++ b/src/uu/dd/src/conversion_tables.rs @@ -17,7 +17,10 @@ pub fn build_lcase_table() -> ConversionTable { // Initialize locale from environment if not already done // SAFETY: setlocale is called with a valid C string and is used to initialize // the locale for character conversion functions - unsafe { libc::setlocale(libc::LC_CTYPE, c"".as_ptr()) }; + #[cfg(not(target_os = "wasi"))] + unsafe { + libc::setlocale(libc::LC_CTYPE, c"".as_ptr()) + }; let mut table = [0u8; 256]; for (i, item) in table.iter_mut().enumerate() { @@ -34,7 +37,10 @@ pub fn build_ucase_table() -> ConversionTable { // Initialize locale from environment if not already done // SAFETY: setlocale is called with a valid C string and is used to initialize // the locale for character conversion functions - unsafe { libc::setlocale(libc::LC_CTYPE, c"".as_ptr()) }; + #[cfg(not(target_os = "wasi"))] + unsafe { + libc::setlocale(libc::LC_CTYPE, c"".as_ptr()) + }; let mut table = [0u8; 256]; for (i, item) in table.iter_mut().enumerate() { diff --git a/src/uu/dd/src/dd.rs b/src/uu/dd/src/dd.rs index 8071cae64..6bf2b49ff 100644 --- a/src/uu/dd/src/dd.rs +++ b/src/uu/dd/src/dd.rs @@ -359,7 +359,7 @@ struct Input<'a> { impl<'a> Input<'a> { /// Instantiate this struct with stdin as a source. fn new_stdin(settings: &'a Settings) -> UResult { - #[cfg(not(unix))] + #[cfg(windows)] let mut src = { let f = File::from(io::stdin().as_handle().try_clone_to_owned()?); let is_file = if let Ok(metadata) = f.metadata() { @@ -378,6 +378,8 @@ impl<'a> Input<'a> { Source::Stdin(io::stdin()) } }; + #[cfg(all(not(unix), not(windows)))] + let mut src = Source::Stdin(io::stdin()); #[cfg(unix)] let mut src = Source::stdin_as_file(); #[cfg(unix)]