• Home
Name Date Size #Lines LOC

..--

src/12-May-2024-31,43221,701

test/12-May-2024-10,0938,098

.cirrus.ymlD12-May-20249.5 KiB319275

.gitattributesD12-May-202426 21

.gitignoreD12-May-202482 1211

BUILD.gnD12-May-20241.9 KiB7167

CHANGELOG.mdD12-May-202474.4 KiB1,5861,411

CONTRIBUTING.mdD12-May-20243.9 KiB11573

CONVENTIONS.mdD12-May-20242.6 KiB8762

Cargo.tomlD12-May-20242.4 KiB115101

Cross.tomlD12-May-202465 65

LICENSED12-May-20241.1 KiB2217

OAT.xmlD12-May-20244 KiB6612

README.OpenSourceD12-May-2024327 1111

README.mdD12-May-20243.5 KiB10683

README_zh.mdD12-May-20241.5 KiB4429

RELEASE_PROCEDURE.mdD12-May-2024768 2015

bors.tomlD12-May-20241.3 KiB5553

release.tomlD12-May-2024188 65

rustfmt.tomlD12-May-202414 11

README.OpenSource

1[
2  {
3    "Name": "nix",
4    "License": "MIT",
5    "License File": "LICENSE",
6    "Version Number": "v0.26.2",
7    "Owner": "fangting12@huawei.com",
8    "Upstream URL": "https://github.com/nix-rust/nix",
9    "Description": "A Rust library that provides support for interacting with Unix-like operating systems."
10  }
11]

README.md

1# Rust bindings to *nix APIs
2
3[![Cirrus Build Status](https://api.cirrus-ci.com/github/nix-rust/nix.svg)](https://cirrus-ci.com/github/nix-rust/nix)
4[![crates.io](https://img.shields.io/crates/v/nix.svg)](https://crates.io/crates/nix)
5
6[Documentation (Releases)](https://docs.rs/nix/)
7
8Nix seeks to provide friendly bindings to various *nix platform APIs (Linux, Darwin,
9...). The goal is to not provide a 100% unified interface, but to unify
10what can be while still providing platform specific APIs.
11
12For many system APIs, Nix provides a safe alternative to the unsafe APIs
13exposed by the [libc crate](https://github.com/rust-lang/libc).  This is done by
14wrapping the libc functionality with types/abstractions that enforce legal/safe
15usage.
16
17
18As an example of what Nix provides, examine the differences between what is
19exposed by libc and nix for the
20[gethostname](https://man7.org/linux/man-pages/man2/gethostname.2.html) system
21call:
22
23```rust,ignore
24// libc api (unsafe, requires handling return code/errno)
25pub unsafe extern fn gethostname(name: *mut c_char, len: size_t) -> c_int;
26
27// nix api (returns a nix::Result<OsString>)
28pub fn gethostname() -> Result<OsString>;
29```
30
31## Supported Platforms
32
33nix target support consists of two tiers. While nix attempts to support all
34platforms supported by [libc](https://github.com/rust-lang/libc), only some
35platforms are actively supported due to either technical or manpower
36limitations. Support for platforms is split into three tiers:
37
38  * Tier 1 - Builds and tests for this target are run in CI. Failures of either
39             block the inclusion of new code.
40  * Tier 2 - Builds for this target are run in CI. Failures during the build
41             blocks the inclusion of new code. Tests may be run, but failures
42             in tests don't block the inclusion of new code.
43  * Tier 3 - Builds for this target are run in CI. Failures during the build
44             *do not* block the inclusion of new code. Testing may be run, but
45             failures in tests don't block the inclusion of new code.
46
47The following targets are supported by `nix`:
48
49Tier 1:
50  * aarch64-apple-darwin
51  * aarch64-unknown-linux-gnu
52  * arm-unknown-linux-gnueabi
53  * armv7-unknown-linux-gnueabihf
54  * i686-unknown-freebsd
55  * i686-unknown-linux-gnu
56  * i686-unknown-linux-musl
57  * mips-unknown-linux-gnu
58  * mips64-unknown-linux-gnuabi64
59  * mips64el-unknown-linux-gnuabi64
60  * mipsel-unknown-linux-gnu
61  * powerpc64le-unknown-linux-gnu
62  * x86_64-unknown-freebsd
63  * x86_64-unknown-linux-gnu
64  * x86_64-unknown-linux-musl
65
66Tier 2:
67  * aarch64-apple-ios
68  * aarch64-linux-android
69  * arm-linux-androideabi
70  * arm-unknown-linux-musleabi
71  * armv7-linux-androideabi
72  * i686-linux-android
73  * powerpc-unknown-linux-gnu
74  * s390x-unknown-linux-gnu
75  * x86_64-apple-ios
76  * x86_64-linux-android
77  * x86_64-apple-darwin
78  * x86_64-unknown-illumos
79  * x86_64-unknown-netbsd
80
81Tier 3:
82  * armv7-unknown-linux-uclibceabihf
83  * x86_64-fuchsia
84  * x86_64-unknown-dragonfly
85  * x86_64-unknown-haiku
86  * x86_64-unknown-linux-gnux32
87  * x86_64-unknown-openbsd
88  * x86_64-unknown-redox
89
90## Minimum Supported Rust Version (MSRV)
91
92nix is supported on Rust 1.56.1 and higher.  Its MSRV will not be
93changed in the future without bumping the major or minor version.
94
95## Contributing
96
97Contributions are very welcome.  Please See [CONTRIBUTING](CONTRIBUTING.md) for
98additional details.
99
100Feel free to join us in [the nix-rust/nix](https://gitter.im/nix-rust/nix) channel on Gitter to
101discuss `nix` development.
102
103## License
104
105Nix is licensed under the MIT license.  See [LICENSE](LICENSE) for more details.
106

README_zh.md

1# Rust bindings to **nix** APIs
2
3[![Cirrus Build Status](https://api.cirrus-ci.com/github/nix-rust/nix.svg)](https://cirrus-ci.com/github/nix-rust/nix)
4[![crates.io](https://img.shields.io/crates/v/nix.svg)](https://crates.io/crates/nix)
5
6[Documentation (Releases)](https://docs.rs/nix/)
7
8## 引入背景
9Nix试图为各种*nix平台的API提供友好的绑定(Linux、Darwin、...)。对于许多系统API,Nix提供了一个安全的替代方案,以取代[libc crate](https://github.com/rust-lang/libc)所暴露的不安全API。 具体做法是用类型/抽象来包装libc的功能,强制执行合法、安全的使用。
10
11Nix提供一个例子对比与libc系统调用的区别
12[gethostname](https://man7.org/linux/man-pages/man2/gethostname.2.html)13
14```rust,ignore
15// libc api (unsafe, requires handling return code/errno)
16pub unsafe extern fn gethostname(name: *mut c_char, len: size_t) -> c_int;
17
18// nix api (returns a nix::Result<OsString>)
19pub fn gethostname() -> Result<OsString>;
20```
21## nix在OH中的使用
22在"BUILD.gn"中使用deps字段添加对num-traits的crates的依赖,例如:
23
24```BUILD.gn
25ohos_rust_shared_library("foo") {
26  source = [ "src/lib.rs" ]
27  deps = [ "//third_party/rust/crates/nix:lib" ]
28}
29```
30
31## Minimum Supported Rust Version (MSRV)
32
33nix在Rust 1.56.1及更高版本上得到支持。
34
35## License
36
37Nix使用MIT License。 更多细节见[LICENSE](LICENSE)。
38
39## 开发者贡献
40
41在使用该工具的过程中有任何问题欢迎开发者在社区issue中反馈。
42
43<br>
44