Skip to content

wasm: support for wasm32-wasip2 target#12653

Open
eduardomourar wants to merge 3 commits into
uutils:mainfrom
eduardomourar:feat/support-wasm32-wasip2
Open

wasm: support for wasm32-wasip2 target#12653
eduardomourar wants to merge 3 commits into
uutils:mainfrom
eduardomourar:feat/support-wasm32-wasip2

Conversation

@eduardomourar

@eduardomourar eduardomourar commented Jun 6, 2026

Copy link
Copy Markdown

Add support for the wasm32-wasip2 (WASI Preview 2) target, enabling coreutils to compile and be used on sandboxed environments that can run WebAssembly components.

Changes

  • Add wasm32-wasip2 target to CI workflows
  • Update code for wasip2 compatibility (yes and uucore libraries)
  • Ensure unit tests pass on the new target
  • Update documentation about supported platforms

@oech3

oech3 commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

But why? Is there any usecase wasip1 cannot cover? If wasip2 works on web browsers using shim, we should drop wasip1 at the same time.

@eduardomourar

eduardomourar commented Jun 6, 2026

Copy link
Copy Markdown
Author

The main reason to have WASI Preview 2 is because Preview 1 is not being further developed. In wasip1, we would never get full support for streams and socket. With wasip2, on other hand, we will have those as well as support for the WebAssembly Component Model. This documentation might help answering you: https://component-model.bytecodealliance.org/design/why-component-model.html#interoperability

Should we drop wasip1? Probably not yet. There are few features that are missing in Preview2:

  • std::os::wasi::prelude::OsStrExt is still under the unstable flag as discussed here
  • WASI CLI Exit with code has stabilized but it has not been implemented in rust std
  • Generated WASM component cannot be easily loaded yet in the browser. You need JCO to transpile it and include the respective WASI shims in order to have something similar to the Uutils Playground.

@oech3

oech3 commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Ok. But do you want to publish release binaries too? Or is cargo check or cargo test on the CI enough?

Comment thread tests/by-util/test_tr.rs Outdated
Comment thread tests/by-util/test_tr.rs Outdated
Comment thread tests/by-util/test_rm.rs Outdated
Comment thread tests/by-util/test_numfmt.rs Outdated
new_ucmd!()
.args(&["--from=iec-i", "10M"])
.fails_with_code(2)
.fails_with_code(if cfg!(wasip2_runner) { 1 } else { 2 })

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why that ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have written now in docs/src/wasi-test-gaps.md some details on that. The WASI Preview 2, as currently implemented in Rust std, only allows to exit with code 0 (success) or 1 (failure).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is limitation for wasip2 instead of ideal behaviour. So we should just guard the test by cfg.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be done as part of other PR.

Comment thread tests/by-util/test_cat.rs Outdated
@github-actions

github-actions Bot commented Jun 6, 2026

Copy link
Copy Markdown

GNU testsuite comparison:

Skip an intermittent issue tests/misc/tty-eof (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/tail/retry (passes in this run but fails in the 'main' branch)
Note: The gnu test tests/cut/cut-huge-range is now being skipped but was previously passing.
Congrats! The gnu test tests/rm/many-dir-entries-vs-OOM is now passing!

@eduardomourar

eduardomourar commented Jun 6, 2026

Copy link
Copy Markdown
Author

Ok. But do you want to publish release binaries too? Or is cargo check or cargo test on the CI enough?

For me, I would benefit of having the released binary for wasip2. I understand it adds a bit more complexity to maintain it, but I think the burden to keep wasip2 is basically the same as wasip1.

@sylvestre sylvestre force-pushed the feat/support-wasm32-wasip2 branch from 5feb45e to 732f48f Compare June 7, 2026 20:31
@eduardomourar eduardomourar force-pushed the feat/support-wasm32-wasip2 branch 2 times, most recently from db9d3ff to 712ff58 Compare June 9, 2026 17:09
@oech3

This comment was marked as outdated.

@oech3

oech3 commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Correctness of error handling is unrelated with initial support (cargo build). Please split PR for less diff.

@eduardomourar eduardomourar force-pushed the feat/support-wasm32-wasip2 branch from 712ff58 to e5bfc97 Compare June 9, 2026 20:51
@eduardomourar

eduardomourar commented Jun 9, 2026

Copy link
Copy Markdown
Author

@oech3, done. I only left the changes to run the build successfully. I am skipping the integration tests for wasip2 as it will be part of the PR related to error handling.

@eduardomourar eduardomourar force-pushed the feat/support-wasm32-wasip2 branch from e5bfc97 to 042f481 Compare June 9, 2026 21:14
@codspeed-hq

codspeed-hq Bot commented Jun 10, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 64 untouched benchmarks
⏩ 305 skipped benchmarks1


Comparing eduardomourar:feat/support-wasm32-wasip2 (02c6ba8) with main (d01be5b)

Open in CodSpeed

Footnotes

  1. 305 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@eduardomourar

Copy link
Copy Markdown
Author

@codspeedbot fix this regression

@sylvestre

Copy link
Copy Markdown
Contributor

this is probably noise, you can ignore the perf warning

@eduardomourar

eduardomourar commented Jun 10, 2026

Copy link
Copy Markdown
Author

@sylvestre and @oech3, I have rebased it. So let me know if you need me to do anything about those perf warnings, ok?

@eduardomourar eduardomourar force-pushed the feat/support-wasm32-wasip2 branch from 042f481 to 749d289 Compare June 18, 2026 13:08
@eduardomourar

eduardomourar commented Jun 18, 2026

Copy link
Copy Markdown
Author

@sylvestre and @oech3, as far I aware there is no other pending issues. If so, this is ready to be approved and merged.

@oech3

oech3 commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Please fix yes's as_encoded_bytes cfg issue.

@oech3

oech3 commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

(also I have no priv for merge)

@eduardomourar

eduardomourar commented Jun 18, 2026

Copy link
Copy Markdown
Author

Please fix yes's as_encoded_bytes cfg issue.

That was already fixed. I pushed a small change in order to run the integration test of yes command for both wasip1 and wasip2.

@eduardomourar eduardomourar force-pushed the feat/support-wasm32-wasip2 branch from 238914c to 484c0af Compare June 18, 2026 19:40
@eduardomourar eduardomourar force-pushed the feat/support-wasm32-wasip2 branch from 484c0af to 02c6ba8 Compare June 19, 2026 20:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants