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

Use rustix instead of libc #878

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

notgull
Copy link

@notgull notgull commented Apr 23, 2024

Closes #847

rustix is a wrapper around either raw Linux system calls or libc, based
on the current platform. The main advantage is that it can make programs
much more efficient, since system calls can be inlined directly into
the functions that call them. I've seen rustix reduce instruction counts
in my programs when I've made the switch in another programs.

In addition, it reduces the amount of unsafe code.

@notgull notgull requested a review from TimonPost as a code owner April 23, 2024 04:48
@joshka
Copy link
Contributor

joshka commented May 3, 2024

Would it make sense to implement this as an alternative behind a feature flag rather than a direct replacement? Doing this would make it more convenient to compare any performance differences and behavior changes.

Closes crossterm-rs#847

rustix is a wrapper around either raw Linux system calls or libc, based
on the current platform. The main advantage is that it can make programs
much more efficient, since system calls can be inlined directly into
the functions that call them. I've seen rustix reduce instruction counts
in my programs when I've made the switch in another programs.

In addition, it reduces the amount of unsafe code.

Signed-off-by: John Nunley <dev@notgull.net>
@notgull
Copy link
Author

notgull commented May 4, 2024

Would it make sense to implement this as an alternative behind a feature flag rather than a direct replacement? Doing this would make it more convenient to compare any performance differences and behavior changes.

I don't think so. The question comes down to how we expose this as a feature flag.

  • Do we make libc the default and expose rustix as an optional feature? Then rustix users will still be lugging around a libc dependency that they might want to get rid of. And vice versa, for rustix being the default and libc being an optional feature.
  • If we make them both optional and require the end user to enable them, this starts up endless bickering about feature unification and enabling them in the dependency tree. For instance, if crate a enables the libc feature and crate b enables the rustix feature, which one do you use?

It adds a lot more complexity than just using one backend does.

@joshka
Copy link
Contributor

joshka commented May 4, 2024

One approach to mutually exclusive feature flags like this is to use cfg(not(feature(...)) (or cfg_if). I'd imagine that we'd only need a libc feature.

My context on this is as a maintainer of Ratatui, where we generally suggest people choose Crossterm as their backend. I'd like to get a feel for whether this change has actual performance benefits, and I'm sure that being able to measure that would be nice.

Doing things with alternative implementations instead of pure replacement also carries less inherent risk - especially when there's no tests.

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.

Port from libc to rustix on Unix platforms
2 participants