Repository navigation
Quest: Gradually migrate the Rust ecosystem to I/O safety #38
Description
As mentioned in the RFC, migration to I/O safety will be a gradual process. I'm laying out a roadmap here, with todo items, to help organize the process. If anyone is interested in helping with any of the items in this process, has ideas of things we should add, or has any questions about anything, please post in this issue! I'll add names to the todo items to track who's working on what.
The first steps are:
- Land the I/O safety stabilization PR (@sunfishcode)
- Update io-lifetimes' API to match what's being stabilized: io-lifetimes 0.7.2 (@sunfishcode)
- Wait for I/O safety to make it to stable Rust, ETA Rust 1.63 on August 11 (rust-lang ;-))
Once the feature reaches stable, the next step will be to contribute AsFd, From<OwnedFd> and From<T> for OwnedFd impls to popular types in the ecosystem. These changes are semver compatible, though they do have MSRV considerations.
- std already has impls for all its own types.
- I'll migrate crates I maintain:
- cap-std (@sunfishcode)
- io-streams (@sunfishcode)
- io-extras (@sunfishcode)
- We'll want to contribute impls to upstream crates for the types that io-lifetimes has impls for; these can follow the implementations in
impls_*.rsfiles in the src directory.- async-std (Implement I/O-safe traits on types async-rs/async-std#1036) (released in 1.13)
- fs-err (Implement I/O safety traits andrewhickman/fs-err#39)
- mio (Migrate to I/O safety traits tokio-rs/mio#1588; msrv bump is now done)
- os_pipe (Implement I/O safety traits oconnor663/os_pipe.rs#25)
- tokio
- socket2 (Implement the I/O-safety traits for Socket and SockRef rust-lang/socket2#325; released in 0.5)
- async-net (Add I/O-safe traits smol-rs/async-net#21)
- There are likely other crates beyond what io-lifetimes happened to add impls for. If a type implements
AsRawFd,FromRawFd, and/orIntoRawFd, it usually wantsAsFd,From<OwnedFd>, and/orFrom<T> for OwnedFd, respectively. And similar for Windows withHandleandSocketin forFd.- TODO: add others here
To help crates that are already using io-lifetimes, such as rustix:
- Update io-lifetimes to re-export std's types and traits by default when they're available in a stable rustc. (@sunfishcode) (Update for io_safety being stabilized. #41)
Once "enough" popular types have added the new impls, we can start migrating APIs to use the new traits, such as using AsFd in place of AsRawFd. When doing so, any functions that accept raw file-descriptor arguments should be changed to unsafe as well. These changes may require a semver bump. They may require a Minimum Supported Rust Version bump too, though another option is to use io-lifetimes once the change to have it re-export std's types and traits by default lands.
- fd-lock (@sunfishcode) (Use the new I/O safety traits, using rustix yoshuawuyts/fd-lock#14)
- terminal_size (Update the API for I/O safety eminence/terminal-size#66)
- TODO: add others here
Activity
notgull commentedon Aug 12, 2022
It is unlikely that
mio/tokiowill update to use I/O safety soon, as they don't want to put it behind a feature flag and their MSRV policy is for the version to be out for at least six months before considering it.Thomasdezeeuw commentedon Aug 12, 2022
The same goes for socket2, feature flags aren't the way to do this. We could go with a build.rs file, e.g. like serde, but I rather just bump the MSRV in a new version. Also note that we have rust-lang/libc#2845 going at the same time, so a ecosystem wide bump of the MSRV seems to be on the horizon.
notgull commentedon Aug 14, 2022
Since it's not linked in the original post: new traits have been added to
socket2in rust-lang/socket2#325, not only in the form ofimpls of the traits, but also boundingInto<SockRef>byAsFd/Socket.joshtriplett commentedon Aug 21, 2022
We should also aim to get
std::os::fdstabilized, to make migration easier and avoid extra cfg branches for wasi.sunfishcode commentedon Aug 23, 2022
The PR for that is rust-lang/rust#98368.
atouchet commentedon Jul 23, 2024
Mio 1.0 with I/O safety traits is now out: https://github.com/tokio-rs/mio/blob/master/CHANGELOG.md#10
polarathene commentedon Jul 23, 2024
I assume that's been resolved as well, the current
tokioMSRV is 1.70, while the msrv note was added in Aug 13 2022.async-stdstill has not had a new release, nor any request for one. So I raised an issue for that.sunfishcode commentedon Aug 15, 2024
Thanks, it appears tokio is indeed updated.
polarathene commentedon Aug 20, 2024
There was an issue with how the PR was implemented, someone will need to correct that for this item to move forward: async-rs/async-std#1036 (comment)
Presently a blocker for async-rs/async-std#1081
sunfishcode commentedon Aug 21, 2024
I've now submitted async-rs/async-std#1084 to fix the errors in async-std.
sunfishcode commentedon Sep 9, 2024
async-std 1.13 is now released with support for the traits.
eminence/terminal-size#66 is now posted to update terminal_size.
That will be the last checkbox left, other than the "TODO: add others here" boxes. Does anyone following this issue have any other crates in mind that we should update?
sunfishcode commentedon Sep 25, 2024
terminal-size 0.4.0 is now released with an API that uses
AsFd.I don't have any other "others" to add here, and all the rest of the boxes here are checked, so I think it's time to close this issue! Thanks to everyone who had a hand in this!
If you have a codebase which is not yet migrated to the I/O safety types and traits and would like help migrating it, feel free to ping me and I'll help if I'm able to.
solomoncyj commentedon Oct 20, 2024
can somone help https://github.com/wez/wezterm/ to migrte? thanks
sunfishcode commentedon Nov 4, 2024
I'm too busy to get to this soon, but I filed #75 to track porting wezterm. I'd be happy to give people pointers if anyone is interested in working on this before I get to it.