-
Notifications
You must be signed in to change notification settings - Fork 69
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
Use rustix instead of direct calls to libc. #76
Conversation
I support this in theory; |
Ah, this PR was using rustix 0.35.6-beta.2. The Android build error was fixed in the 0.35.6 release. I've now updated the PR. |
Are there any blockers to this being merged? I see how the extra dependency might give pause, but it's probably worth purging the remaining unsafe code in this crate, at least on Unix. |
Use the [rustix] syscall wrapper crate to factor out error handling and unsafe system calls. This reduces the amount of unsafe code here, and is a step towards factoring it out entirely once [`AsFd`] is stabilized and can replace `AsRawFd` for these kinds of uses. This does require incrementing the minimum required Rust version to 1.48. Please feel free to decline this PR if you don't wish to take on these new requirements. [rustix]: https://crates.io/crates/rustix/ [`AsFd`]: https://doc.rust-lang.org/stable/std/os/unix/io/trait.AsFd.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Truth be told, this looks good to me.
With rustix
in the dependency tree, it may be a good idea to also reimplement some other code in terms of rustix
. For instance, the package has support for safe epoll
, which means we may be able to reimplement our epoll
backend in polling
in terms of it to reduce the amount of unsafe code we use.
There are three main points of contention, from what I see:
- Is there a reason to use this instead of
nix
? Whilerustix
is more popular,nix
may also appear in the dependency tree. rustix
adds thebitflags
dependency tosmol
's dependency tree, which compiles fairly quickly but is still another brick in the wall.- Is the unsafe code we eliminate worth it in the end, since it's just replicated in
rustix
anyways?
@smol-rs/admins This may be worth a more thorough discussion to determine what direction we'd like to move in.
.read_with(|t| { | ||
// Safety: Assume `as_raw_fd()` returns a valid fd; when `AsFd` | ||
// is stabilized, we can remove this unsafe and simplify. | ||
let fd = unsafe { BorrowedFd::borrow_raw(t.as_raw_fd()) }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AsFd
is stabilized now, so I think we can eliminate this unsafe
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost, but async-io still has an MSRV of 1.48, and I/O safety is stabilized in Rust 1.63. I've now added more to these comments to mention that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't run the tests on the MSRV build, so it's alright.
Thanks for the PR! I'm basically agreed with merging this, but have a few questions.
Given
Personally, I think the optimization such as uses of raw system calls to be the important benefit of this PR, not only the removal of unsafe code. (If the removal of unsafe code were the only benefit of this PR, I might not have agreed with this PR.) |
Ah, good catch. There are Right now, I can confirm that with those tests commented out, the rest of the tests do still pass on 1.48 on all archtectures that have outline asm implementations.
Thanks for the heads-up here. Rustix doesn't have that specific pattern, with
Rustix does have various non-Linux platform-specific APIs, for example fcopyfile. There's no specific plan; things get added as needed. Patches to add more are welcome. Filing issues is good too; polling APIs can be subtle, and I'd be happy to help figure things out. |
This eliminates the need for a direct dependency on windows-sys.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
- Use [`rustix`] instead of [`libc`]/[`windows-sys`] for system calls (#76) - Add a `will_fire` method to `Timer` to test if it will ever fire (#106) - Reduce syscalls in `Async::new` (#107) - Improve the drop ergonomics of `Readable` and `Writable` (#109) - Change the "`wepoll`" in documentation to "`IOCP`" (#116) [`rustix`]: https://crates.io/crates/rustix/ [`libc`]: https://crates.io/crates/libc/ [`windows-sys`]: https://crates.io/crates/windows-sys/
- Use [`rustix`] instead of [`libc`]/[`windows-sys`] for system calls (#76) - Add a `will_fire` method to `Timer` to test if it will ever fire (#106) - Reduce syscalls in `Async::new` (#107) - Improve the drop ergonomics of `Readable` and `Writable` (#109) - Change the "`wepoll`" in documentation to "`IOCP`" (#116) [`rustix`]: https://crates.io/crates/rustix/ [`libc`]: https://crates.io/crates/libc/ [`windows-sys`]: https://crates.io/crates/windows-sys/
Use the rustix syscall wrapper crate to factor out error handling and
unsafe system calls. This reduces the amount of unsafe code here, and is
a step towards factoring it out entirely once
AsFd
is stabilized andcan replace
AsRawFd
for these kinds of uses.This does require incrementing the minimum required Rust version to 1.48.
Please feel free to decline this PR if you don't wish to take on these new
requirements.