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

Port from libc to rustix #401

Open
notgull opened this issue Feb 26, 2024 · 7 comments
Open

Port from libc to rustix #401

notgull opened this issue Feb 26, 2024 · 7 comments

Comments

@notgull
Copy link

notgull commented Feb 26, 2024

rustix is a crate which provides I/O-safe wrappers around raw system calls on Linux and libc on other Unixes. By using it we can use raw syscalls instead of libc calls, which has a number of performance, safety and code size advantages.

I am wiling to write a PR for this; however there are a couple of items of discussions we have to go over first.

  • This will bump this crate's MSRV to v1.63. Is this acceptable?
  • It will also add a couple of (mostly inconsequential) dependencies. Is this acceptable?
@newpavlov
Copy link
Member

newpavlov commented Feb 26, 2024

I considered it (personally, I like rustix and use it instead of libc in my projects), but there are several issues:

  • MSRV 1.63 is a bit too high for us. rustix has a laxer MSRV policy, so we probably would have to wait until MSRV-aware resolver will be adopted widely enough (or until next breaking getrandom release which may have sufficiently high MSRV).
  • Some users are quite sensitive to additional dependencies, regardless whether they are "mostly inconsequential" or not.
  • rustix::rand::getrandom accepts &mut [u8], while we provide API which works over &mut [MaybeUninit<u8>].

So we probably will not be migrating to rustix at the very least until hypothetical getrandom v0.3.

@notgull
Copy link
Author

notgull commented Feb 26, 2024

For your last point, getrandom_uninit is exposed in rustix now.

For the rest, I agree. We’ll have to wait.

@newpavlov
Copy link
Member

getrandom_uninit is exposed in rustix now.

Ah, good to know!

@josephlr
Copy link
Member

josephlr commented May 2, 2024

@notgull is it the intent of rustix to support all target_family = unix Rust targets? We try to support every rust target, and I would be a pain to deal with both rustix and libc crates.

We could maybe switch just the use_file.rs code to use rustix, which would require Linux, Android, Haiku, Redox, NTO and AIX support.

@newpavlov
Copy link
Member

newpavlov commented May 2, 2024

I think it makes sense to use rustix only on Linux and Android for the raw syscall feature. For other targets it's essentially a glorified libc wrapper. We probably can limit its use only to the getrandom path and make it a (disabled by default) crate feature.

@notgull
Copy link
Author

notgull commented May 3, 2024

@notgull is it the intent of rustix to support all target_family = unix Rust targets? We try to support every rust target, and I would be a pain to deal with both rustix and libc crates.

rustix supports all of the Unix targets, as well as some of the other targets, like Windows (through winsock).

We could maybe switch just the use_file.rs code to use rustix, which would require Linux, Android, Haiku, Redox, NTO and AIX support.

Yes, I think this would work.

I think it makes sense to use rustix only on Linux and Android for the raw syscall feature. For other targets it's essentially a glorified libc wrapper. We probably can limit its use only to the getrandom path and make it a (disabled by default) crate feature.

This sounds like a pain to manage, especially when rustix is present enough in the ecosystem that you're probably going to import it anyways.

@newpavlov
Copy link
Member

This sounds like a pain to manage, especially when rustix is present enough in the ecosystem that you're probably going to import it anyways.

We are unlikely to use rustix by default and, as noted above, I don't see reasons to use it on non-Linux platforms in our case. So rustix-based code is likely to be behind a feature flag. Enabling the hypothetical linux-raw feature will be no more painful than enabling optional rustix dependency.

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

No branches or pull requests

3 participants