dcuddeback / termios-rs

Safe bindings for the termios library.
http://dcuddeback.github.io/termios-rs/termios/
MIT License
75 stars 26 forks source link

Using bindgen to support all platforms #36

Open nospam3089 opened 1 year ago

nospam3089 commented 1 year ago

The low-maintenance state of this crate is great, but here comes a suggestion for a somewhat disruptive design change which might be worth considering.

One can argue it made more sense to fully handcraft the files in src/os/ back when this termios crate was first written than what is the case today when the available tooling situation is better. The main drawback with handcrafted platform files are that only those explicitly listed platforms are supported. If switching to instead use bindgen, all relevant platforms should be working without the tedious and error prone task of manually translating the header file into Rust. This PR implements such a change, while still maintaining the ::os::* modules as in previous versions for well-known platforms.

The one thing I knowingly didn't bother updating prior to learning your opinion is the CONTRIBUTING.md file. Hence the draft status. If this looks mostly good to you, I'll polish up the documentation too.

Even though making huge structural changes, to the best of my understanding this should not require more than a patch level update to semver versioning since all public interfaces should remain unchanged. That might require a bit more consideration prior to merging though.

Regarding crate naming, I'm hoping we can be able to reach out to @basmith and obtain have the ownership of the seemingly unused and abandoned crate currently holding the termios-sys name. Otherwise libtermios-sys is available. Sorting out crate naming is likely also blocking this to be merged.

Running cargo test succeeds on linux and illumos. The https://git.netizen.se/termios-rs/log/?h=wip/haiku_support branch brings termios-rs to haiku, a platform where it previously refused to build. No other platforms have been attempted by me, yet.

jgarzik commented 8 months ago

1) conceptually looks nice.

2) Is it useful to consider an inheritable composition method? Specifically, the following two-stage arrangement is worth considering from my PoV:

a) POSIX definitions b) OS-specific definitions, inherits and updates POSIX definitions. Essentially a diff from (a), rather than a full list.