crossterm-rs / crossterm

Cross platform terminal library rust
MIT License
3.28k stars 281 forks source link

Port from libc to rustix on Unix platforms #847

Closed notgull closed 5 months ago

notgull commented 11 months ago

rustix is a system call wrapper that wraps raw system calls on Linux and libc on other platforms. It would allow crossterm to refactor out error handling and unsafe syscall handling code from its codebase. In terms of speed, rustix bypasses libc for Linux system calls. In some cases, this can allow system calls to be directly inlined into their calling functions, lowering the instruction count.

rustix currently supports all of the system calls that this crate uses. The only problem would be that it would bump the MSRV to 1.63, but if that isn't an issue then I can write a PR for this.

notgull commented 10 months ago

@TimonPost What are your thoughts on this? If I submitted a PR, would it be accepted?

TimonPost commented 10 months ago

Im doubting a little, a pr is welcome, but i think in general we got pretty simple usecases and most of them havent changed for years now. It seems rustix might bring a couple of extra dependencies - which would be my biggest consern. So could be good to check that out, certainly removing unsafe is better, but unsafe isnt a big issue directly if used right.

notgull commented 10 months ago

It seems rustix might bring a couple of extra dependencies - which would be my biggest consern.

rustix brings in two dependencies on Linux: bitflags (which is already used in this crate) and linux-raw-sys. On other platforms rustix doesn't bring in the raw Linux bindings and instead brings in libc and libc_errno.

TimonPost commented 10 months ago

even bringing in bitflags could cause duplicated versions to be included. It creates a dependency between rustix and crossterm where they need to use the same versions. Tho bitflags probably is quite stable. But again feel free to open PR and check what impact it has on the Cagro.lock