13da5c369Sopenharmony_ci# Rust bindings to *nix APIs
23da5c369Sopenharmony_ci
33da5c369Sopenharmony_ci[![Cirrus Build Status](https://api.cirrus-ci.com/github/nix-rust/nix.svg)](https://cirrus-ci.com/github/nix-rust/nix)
43da5c369Sopenharmony_ci[![crates.io](https://img.shields.io/crates/v/nix.svg)](https://crates.io/crates/nix)
53da5c369Sopenharmony_ci
63da5c369Sopenharmony_ci[Documentation (Releases)](https://docs.rs/nix/)
73da5c369Sopenharmony_ci
83da5c369Sopenharmony_ciNix seeks to provide friendly bindings to various *nix platform APIs (Linux, Darwin,
93da5c369Sopenharmony_ci...). The goal is to not provide a 100% unified interface, but to unify
103da5c369Sopenharmony_ciwhat can be while still providing platform specific APIs.
113da5c369Sopenharmony_ci
123da5c369Sopenharmony_ciFor many system APIs, Nix provides a safe alternative to the unsafe APIs
133da5c369Sopenharmony_ciexposed by the [libc crate](https://github.com/rust-lang/libc).  This is done by
143da5c369Sopenharmony_ciwrapping the libc functionality with types/abstractions that enforce legal/safe
153da5c369Sopenharmony_ciusage.
163da5c369Sopenharmony_ci
173da5c369Sopenharmony_ci
183da5c369Sopenharmony_ciAs an example of what Nix provides, examine the differences between what is
193da5c369Sopenharmony_ciexposed by libc and nix for the
203da5c369Sopenharmony_ci[gethostname](https://man7.org/linux/man-pages/man2/gethostname.2.html) system
213da5c369Sopenharmony_cicall:
223da5c369Sopenharmony_ci
233da5c369Sopenharmony_ci```rust,ignore
243da5c369Sopenharmony_ci// libc api (unsafe, requires handling return code/errno)
253da5c369Sopenharmony_cipub unsafe extern fn gethostname(name: *mut c_char, len: size_t) -> c_int;
263da5c369Sopenharmony_ci
273da5c369Sopenharmony_ci// nix api (returns a nix::Result<OsString>)
283da5c369Sopenharmony_cipub fn gethostname() -> Result<OsString>;
293da5c369Sopenharmony_ci```
303da5c369Sopenharmony_ci
313da5c369Sopenharmony_ci## Supported Platforms
323da5c369Sopenharmony_ci
333da5c369Sopenharmony_cinix target support consists of two tiers. While nix attempts to support all
343da5c369Sopenharmony_ciplatforms supported by [libc](https://github.com/rust-lang/libc), only some
353da5c369Sopenharmony_ciplatforms are actively supported due to either technical or manpower
363da5c369Sopenharmony_cilimitations. Support for platforms is split into three tiers:
373da5c369Sopenharmony_ci
383da5c369Sopenharmony_ci  * Tier 1 - Builds and tests for this target are run in CI. Failures of either
393da5c369Sopenharmony_ci             block the inclusion of new code.
403da5c369Sopenharmony_ci  * Tier 2 - Builds for this target are run in CI. Failures during the build
413da5c369Sopenharmony_ci             blocks the inclusion of new code. Tests may be run, but failures
423da5c369Sopenharmony_ci             in tests don't block the inclusion of new code.
433da5c369Sopenharmony_ci  * Tier 3 - Builds for this target are run in CI. Failures during the build
443da5c369Sopenharmony_ci             *do not* block the inclusion of new code. Testing may be run, but
453da5c369Sopenharmony_ci             failures in tests don't block the inclusion of new code.
463da5c369Sopenharmony_ci
473da5c369Sopenharmony_ciThe following targets are supported by `nix`:
483da5c369Sopenharmony_ci
493da5c369Sopenharmony_ciTier 1:
503da5c369Sopenharmony_ci  * aarch64-apple-darwin
513da5c369Sopenharmony_ci  * aarch64-unknown-linux-gnu
523da5c369Sopenharmony_ci  * arm-unknown-linux-gnueabi
533da5c369Sopenharmony_ci  * armv7-unknown-linux-gnueabihf
543da5c369Sopenharmony_ci  * i686-unknown-freebsd
553da5c369Sopenharmony_ci  * i686-unknown-linux-gnu
563da5c369Sopenharmony_ci  * i686-unknown-linux-musl
573da5c369Sopenharmony_ci  * mips-unknown-linux-gnu
583da5c369Sopenharmony_ci  * mips64-unknown-linux-gnuabi64
593da5c369Sopenharmony_ci  * mips64el-unknown-linux-gnuabi64
603da5c369Sopenharmony_ci  * mipsel-unknown-linux-gnu
613da5c369Sopenharmony_ci  * powerpc64le-unknown-linux-gnu
623da5c369Sopenharmony_ci  * x86_64-unknown-freebsd
633da5c369Sopenharmony_ci  * x86_64-unknown-linux-gnu
643da5c369Sopenharmony_ci  * x86_64-unknown-linux-musl
653da5c369Sopenharmony_ci
663da5c369Sopenharmony_ciTier 2:
673da5c369Sopenharmony_ci  * aarch64-apple-ios
683da5c369Sopenharmony_ci  * aarch64-linux-android
693da5c369Sopenharmony_ci  * arm-linux-androideabi
703da5c369Sopenharmony_ci  * arm-unknown-linux-musleabi
713da5c369Sopenharmony_ci  * armv7-linux-androideabi
723da5c369Sopenharmony_ci  * i686-linux-android
733da5c369Sopenharmony_ci  * powerpc-unknown-linux-gnu
743da5c369Sopenharmony_ci  * s390x-unknown-linux-gnu
753da5c369Sopenharmony_ci  * x86_64-apple-ios
763da5c369Sopenharmony_ci  * x86_64-linux-android
773da5c369Sopenharmony_ci  * x86_64-apple-darwin
783da5c369Sopenharmony_ci  * x86_64-unknown-illumos
793da5c369Sopenharmony_ci  * x86_64-unknown-netbsd
803da5c369Sopenharmony_ci
813da5c369Sopenharmony_ciTier 3:
823da5c369Sopenharmony_ci  * armv7-unknown-linux-uclibceabihf
833da5c369Sopenharmony_ci  * x86_64-fuchsia
843da5c369Sopenharmony_ci  * x86_64-unknown-dragonfly
853da5c369Sopenharmony_ci  * x86_64-unknown-haiku
863da5c369Sopenharmony_ci  * x86_64-unknown-linux-gnux32
873da5c369Sopenharmony_ci  * x86_64-unknown-openbsd
883da5c369Sopenharmony_ci  * x86_64-unknown-redox
893da5c369Sopenharmony_ci
903da5c369Sopenharmony_ci## Minimum Supported Rust Version (MSRV)
913da5c369Sopenharmony_ci
923da5c369Sopenharmony_cinix is supported on Rust 1.56.1 and higher.  Its MSRV will not be
933da5c369Sopenharmony_cichanged in the future without bumping the major or minor version.
943da5c369Sopenharmony_ci
953da5c369Sopenharmony_ci## Contributing
963da5c369Sopenharmony_ci
973da5c369Sopenharmony_ciContributions are very welcome.  Please See [CONTRIBUTING](CONTRIBUTING.md) for
983da5c369Sopenharmony_ciadditional details.
993da5c369Sopenharmony_ci
1003da5c369Sopenharmony_ciFeel free to join us in [the nix-rust/nix](https://gitter.im/nix-rust/nix) channel on Gitter to
1013da5c369Sopenharmony_cidiscuss `nix` development.
1023da5c369Sopenharmony_ci
1033da5c369Sopenharmony_ci## License
1043da5c369Sopenharmony_ci
1053da5c369Sopenharmony_ciNix is licensed under the MIT license.  See [LICENSE](LICENSE) for more details.
106