Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide optional Read/Write methods for stdio #136769

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

thaliaarchi
Copy link
Contributor

@thaliaarchi thaliaarchi commented Feb 9, 2025

The raw types for standard I/O across platforms vary by which of the optional io::Read and io::Write methods they provide and most just use the defaults. Only Unix implements read_buf, read_vectored, and write_vectored for its stdio. Provide these methods for the platforms which support them or when useful. Additionally, provide missing methods for StdinRaw, StdoutLock, and StderrLock, which the other similar types provide.

I have checked the code against a target per platform modified, with wasm32-unknown-unknown for unsupported stdio, as well as Linux, macOS, and Windows.

x check library/std --target=aarch64-apple-darwin
x check library/std --target=aarch64-kmc-solid_asp3
x check library/std --target=aarch64-unknown-linux-gnu
x check library/std --target=aarch64-unknown-teeos
x check library/std --target=riscv32im-risc0-zkvm-elf
x check library/std --target=riscv32imac-unknown-xous-elf
x check library/std --target=wasm32-unknown-unknown
x check library/std --target=wasm32-wasip1
x check library/std --target=x86_64-fortanix-unknown-sgx
x check library/std --target=x86_64-pc-windows-gnu
x check library/std --target=x86_64-unknown-hermit
x check library/std --target=x86_64-unknown-uefi

Progress on optional Read/Write methods is tracked in #136756.

Later work

Windows and UEFI stdio use UTF-16, so will take more work to flesh out. I plan to refactor the WTF-8 abstraction from OsStr to accommodate this in a future PR.

@rustbot
Copy link
Collaborator

rustbot commented Feb 9, 2025

r? @Noratrieb

rustbot has assigned @Noratrieb.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added O-hermit Operating System: Hermit O-SGX Target: SGX O-solid Operating System: SOLID O-wasi Operating system: Wasi, Webassembly System Interface S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Feb 9, 2025
@rust-log-analyzer

This comment has been minimized.

@thaliaarchi
Copy link
Contributor Author

@joboet Looks like you wrote #136780 to have minimum conflicts to this. Thanks for that. I don't mind rebasing onto that, if yours is merged first.

@Noratrieb
Copy link
Member

r? joboet

@rustbot rustbot assigned joboet and unassigned Noratrieb Feb 12, 2025
@thaliaarchi thaliaarchi changed the title Provide optional Read/Write method for stdio Provide optional Read/Write methods for stdio Feb 13, 2025
@thaliaarchi thaliaarchi force-pushed the io-optional-methods/stdio branch 2 times, most recently from f51bb4e to 118bb74 Compare February 16, 2025 21:59
@thaliaarchi
Copy link
Contributor Author

I dropped a few commits from this PR:

joboet and others added 2 commits February 17, 2025 13:57
As per rust-lang#117276, this moves the platform definitions of `Stdout` and friends into `sys`. This PR also unifies the UNIX and Hermit implementations and moves the `__rust_print_err` function needed by libunwind on SGX into the dedicated module for such helper functions.
@thaliaarchi thaliaarchi marked this pull request as draft February 19, 2025 04:37
@thaliaarchi
Copy link
Contributor Author

Since this touches a lot of targets, I'm going to split this into multiple PRs for more target-focused review, once #136780 goes through the merge queue.

@joboet
Copy link
Member

joboet commented Feb 19, 2025

Since this touches a lot of targets, I'm going to split this into multiple PRs for more target-focused review, once #136780 goes through the merge queue.

That'd be great, thank you! Especially the SGX stuff would be much simpler to review as a dedicated PR.

@thaliaarchi thaliaarchi force-pushed the io-optional-methods/stdio branch from 118bb74 to ade071b Compare February 21, 2025 05:27
@rustbot rustbot added O-unix Operating system: Unix-like O-wasm Target: WASM (WebAssembly), http://webassembly.org/ O-windows Operating system: Windows labels Feb 21, 2025
@thaliaarchi
Copy link
Contributor Author

@rustbot blocked (on #136780)

@rustbot rustbot added S-blocked Status: Blocked on something else such as an RFC or other implementation work. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
O-hermit Operating System: Hermit O-SGX Target: SGX O-solid Operating System: SOLID O-unix Operating system: Unix-like O-wasi Operating system: Wasi, Webassembly System Interface O-wasm Target: WASM (WebAssembly), http://webassembly.org/ O-windows Operating system: Windows S-blocked Status: Blocked on something else such as an RFC or other implementation work. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants