Skip to content

sort: add wasi support for merge operations - #16689

Open
eduardomourar wants to merge 2 commits into
uutils:mainfrom
eduardomourar:feat/wasi-sort-support-merge
Open

eduardomourar wants to merge 2 commits into
uutils:mainfrom
eduardomourar:feat/wasi-sort-support-merge

Conversation

@eduardomourar

@eduardomourar eduardomourar commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

sort -m spawns an OS thread per merge batch to overlap reading and sorting. WASI has no real threads, so this panicked into an unreachable trap instead of a usable error, and every affected merge test was skipped under WASI.

Add a synchronous target_os = "wasi" merge and --check path that reads chunks on the calling thread instead of handing them to a reader thread, reusing the same chunk-parsing code. Also tighten --batch-size handling: WASI has no getrlimit, so it now assumes a conservative fd limit instead of treating merge batch size as unbounded.

Addresses the sort -m half of #16599 (dd's thread spawn is a separate issue).

🤖 Generated with Claude Code

@sylvestre

Copy link
Copy Markdown
Contributor

thanks for the patch!
However, it is quite big :(
The WASI merge copies most of the threaded FileMerger. Please share that code instead (see inline).
Please also move the test attribute reordering and the NoLocaleData removals into a separate PR.

Comment thread src/uu/sort/src/merge.rs Resolved
Comment thread src/uu/sort/src/merge.rs Resolved
Comment thread src/uu/sort/src/merge.rs Resolved
Comment thread src/uu/sort/src/sort.rs Outdated
/// WASI has no `getrlimit`; guess a conservative limit instead of `None`, so
/// `--batch-size`/merge stay bounded on wasmtime's often-smaller fd table.
#[cfg(target_os = "wasi")]
#[allow(clippy::unnecessary_wraps)]

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.

please avoid the #[allow], and where does 256 come from?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I made the modification accordingly. I am not too happy with it visually. If this was not what you had in mind, please propose the way in the code concretely so I can learn for next time.

Comment thread tests/by-util/test_sort.rs Resolved
Comment thread tests/by-util/test_sort.rs Resolved
Comment thread tests/by-util/test_sort.rs Resolved
@github-actions

Copy link
Copy Markdown

Binary size comparison:

Individual binary size comparison VS main (threshold: >=5% AND >=4 KB).

Total size of compared binaries: 155.48 MB (+100 KB, +0.06%)

Significant per-binary changes:
  env     1.20 MB ->    1.28 MB  (+80 KB, +6.51%)

@eduardomourar
eduardomourar force-pushed the feat/wasi-sort-support-merge branch from f2d23b7 to 162ed9a Compare November 19, 2026 12:29
@github-actions

Copy link
Copy Markdown

GNU testsuite comparison:

Congrats! The gnu test tests/tail/follow-name is no longer failing!
Congrats! The gnu test tests/tail/pid-pipe is no longer failing!

This branch has not been deployed

No deployments
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.

2 participants