|
1 |
| -libc |
2 |
| -==== |
| 1 | +[![Travis-CI Status]][Travis-CI] [![Appveyor Status]][Appveyor] [![Cirrus-CI Status]][Cirrus-CI] [![Latest Version]][crates.io] [![Documentation]][docs.rs] ![License] |
3 | 2 |
|
4 |
| -Raw FFI bindings to platform libraries like `libc`. |
| 3 | +libc - Raw FFI bindings to platforms' system libraries |
| 4 | +==== |
5 | 5 |
|
6 |
| -[](https://travis-ci.org/rust-lang/libc) |
7 |
| -[](https://ci.appveyor.com/project/rust-lang-libs/libc) |
8 |
| -[](https://cirrus-ci.com/github/rust-lang/libc) |
9 |
| -[](https://crates.io/crates/libc) |
10 |
| -[](https://docs.rs/libc) |
11 |
| -[] |
| 6 | +`libc` provides all of the definitions necessary to easily interoperate with C |
| 7 | +code (or "C-like" code) on each of the platforms that Rust supports. This |
| 8 | +includes type definitions (e.g. `c_int`), constants (e.g. `EINVAL`) as well as |
| 9 | +function headers (e.g. `malloc`). |
12 | 10 |
|
13 |
| -**NOTE:** The minimum supported Rust version is **Rust 1.13.0** . APIs requiring |
14 |
| -newer Rust features are only available on newer Rust versions: |
| 11 | +This crate exports all underlying platform types, functions, and constants under |
| 12 | +the crate root, so all items are accessible as `libc::foo`. The types and values |
| 13 | +of all the exported APIs match the platform that libc is compiled for. |
15 | 14 |
|
16 |
| -| Feature | Version | |
17 |
| -|----------------------|---------| |
18 |
| -| `union` | 1.19.0 | |
19 |
| -| `const mem::size_of` | 1.24.0 | |
20 |
| -| `repr(align)` | 1.25.0 | |
21 |
| -| `core::ffi::c_void` | 1.30.0 | |
| 15 | +More detailed information about the design of this library can be found in its |
| 16 | +[associated RFC][rfc]. |
22 | 17 |
|
23 |
| -To use `libc` at its fullest, Rust 1.30.0 is required. |
| 18 | +[rfc]: https://github.com/rust-lang/rfcs/blob/master/text/1291-promote-libc.md |
24 | 19 |
|
25 | 20 | ## Usage
|
26 | 21 |
|
27 |
| -First, add the following to your `Cargo.toml`: |
| 22 | +Add the following to your `Cargo.toml`: |
28 | 23 |
|
29 | 24 | ```toml
|
30 | 25 | [dependencies]
|
31 | 26 | libc = "0.2"
|
32 | 27 | ```
|
33 | 28 |
|
34 |
| -Next, add this to your crate root: |
| 29 | +## Features |
35 | 30 |
|
36 |
| -```rust |
37 |
| -extern crate libc; |
38 |
| -``` |
| 31 | +* `use_std`: by default `libc` links to the standard library. Disable this |
| 32 | + feature remove this dependency and be able to use `libc` in `#![no_std]` |
| 33 | + crates. |
39 | 34 |
|
40 |
| -Currently libc by default links to the standard library, but if you would |
41 |
| -instead like to use libc in a `#![no_std]` situation or crate you can request |
42 |
| -this via: |
| 35 | +* `extra_traits`: all `struct`s implemented in `libc` are `Copy` and `Clone`. |
| 36 | + This feature derives `Debug, `Eq`, `Hash`, and `PartialEq`. |
43 | 37 |
|
44 |
| -```toml |
45 |
| -[dependencies] |
46 |
| -libc = { version = "0.2", default-features = false } |
47 |
| -``` |
| 38 | +## Rust version support |
48 | 39 |
|
49 |
| -By default libc uses private fields in structs in order to enforce a certain |
50 |
| -memory alignment on them. These structs can be hard to instantiate outside of |
51 |
| -libc. To make libc use `#[repr(align(x))]`, instead of the private fields, |
52 |
| -activate the *align* feature. This requires Rust 1.25 or newer: |
| 40 | +The minimum supported Rust toolchain version is **Rust 1.13.0** . APIs requiring |
| 41 | +newer Rust features are only available on newer Rust toolchains: |
53 | 42 |
|
54 |
| -```toml |
55 |
| -[dependencies] |
56 |
| -libc = { version = "0.2", features = ["align"] } |
57 |
| -``` |
| 43 | +| Feature | Version | |
| 44 | +|----------------------|---------| |
| 45 | +| `union` | 1.19.0 | |
| 46 | +| `const mem::size_of` | 1.24.0 | |
| 47 | +| `repr(align)` | 1.25.0 | |
| 48 | +| `extra_traits` | 1.25.0 | |
| 49 | +| `core::ffi::c_void` | 1.30.0 | |
| 50 | +| `repr(packed(N))` | 1.33.0 | |
58 | 51 |
|
59 |
| -All structs implemented by the libc crate have the `Copy` and `Clone` traits |
60 |
| -implemented for them. The additional traits of `Debug, `Eq`, `Hash`, and |
61 |
| -`PartialEq` can be enabled with the *extra_traits* feature (requires Rust 1.25 |
62 |
| -or newer): |
| 52 | +## Platform support |
63 | 53 |
|
64 |
| -```toml |
65 |
| -[dependencies] |
66 |
| -libc = { version = "0.2", features = ["extra_traits"] } |
67 |
| -``` |
| 54 | +[Platform-specific documentation of libc's master branch for all supported platforms][docs.master]. |
68 | 55 |
|
69 |
| -## What is libc? |
| 56 | +See [`ci/build.sh`](ci/build.sh) for the platforms on which `libc` is |
| 57 | +guaranteed to build for each Rust toolchain. The test-matrix at [Travis-CI], |
| 58 | +[Appveyor], and [Cirrus-CI] show the platforms in which `libc` tests are run. |
70 | 59 |
|
71 |
| -The primary purpose of this crate is to provide all of the definitions necessary |
72 |
| -to easily interoperate with C code (or "C-like" code) on each of the platforms |
73 |
| -that Rust supports. This includes type definitions (e.g. `c_int`), constants |
74 |
| -(e.g. `EINVAL`) as well as function headers (e.g. `malloc`). |
| 60 | +<div class="platform_docs"></div> |
75 | 61 |
|
76 |
| -This crate does not strive to have any form of compatibility across platforms, |
77 |
| -but rather it is simply a straight binding to the system libraries on the |
78 |
| -platform in question. |
| 62 | +## License |
79 | 63 |
|
80 |
| -## Public API |
| 64 | +This project is licensed under either of |
81 | 65 |
|
82 |
| -This crate exports all underlying platform types, functions, and constants under |
83 |
| -the crate root, so all items are accessible as `libc::foo`. The types and values |
84 |
| -of all the exported APIs match the platform that libc is compiled for. |
| 66 | +* [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0) |
| 67 | + ([LICENSE-APACHE](LICENSE-APACHE)) |
85 | 68 |
|
86 |
| -More detailed information about the design of this library can be found in its |
87 |
| -[associated RFC][rfc]. |
| 69 | +* [MIT License](http://opensource.org/licenses/MIT) |
| 70 | + ([LICENSE-MIT](LICENSE-MIT)) |
88 | 71 |
|
89 |
| -[rfc]: https://github.com/rust-lang/rfcs/blob/master/text/1291-promote-libc.md |
| 72 | +at your option. |
| 73 | + |
| 74 | +## Contributing |
| 75 | + |
| 76 | +We welcome all people who want to contribute. Please see the [contributing |
| 77 | +instructions] for more information. |
| 78 | + |
| 79 | +[contributing instructions]: CONTRIBUTING.md |
| 80 | + |
| 81 | +Contributions in any form (issues, pull requests, etc.) to this project |
| 82 | +must adhere to Rust's [Code of Conduct]. |
| 83 | + |
| 84 | +[Code of Conduct]: https://www.rust-lang.org/en-US/conduct.html |
| 85 | + |
| 86 | +Unless you explicitly state otherwise, any contribution intentionally submitted |
| 87 | +for inclusion in `libc` by you, as defined in the Apache-2.0 license, shall be |
| 88 | +dual licensed as above, without any additional terms or conditions. |
90 | 89 |
|
91 |
| -## Adding an API |
92 |
| - |
93 |
| -Want to use an API which currently isn't bound in `libc`? It's quite easy to add |
94 |
| -one! |
95 |
| - |
96 |
| -The internal structure of this crate is designed to minimize the number of |
97 |
| -`#[cfg]` attributes in order to easily be able to add new items which apply |
98 |
| -to all platforms in the future. As a result, the crate is organized |
99 |
| -hierarchically based on platform. Each module has a number of `#[cfg]`'d |
100 |
| -children, but only one is ever actually compiled. Each module then reexports all |
101 |
| -the contents of its children. |
102 |
| - |
103 |
| -This means that for each platform that libc supports, the path from a |
104 |
| -leaf module to the root will contain all bindings for the platform in question. |
105 |
| -Consequently, this indicates where an API should be added! Adding an API at a |
106 |
| -particular level in the hierarchy means that it is supported on all the child |
107 |
| -platforms of that level. For example, when adding a Unix API it should be added |
108 |
| -to `src/unix/mod.rs`, but when adding a Linux-only API it should be added to |
109 |
| -`src/unix/notbsd/linux/mod.rs`. |
110 |
| - |
111 |
| -If you're not 100% sure at what level of the hierarchy an API should be added |
112 |
| -at, fear not! This crate has CI support which tests any binding against all |
113 |
| -platforms supported, so you'll see failures if an API is added at the wrong |
114 |
| -level or has different signatures across platforms. |
115 |
| - |
116 |
| -With that in mind, the steps for adding a new API are: |
117 |
| - |
118 |
| -1. Determine where in the module hierarchy your API should be added. |
119 |
| -2. Add the API. |
120 |
| -3. Send a PR to this repo. |
121 |
| -4. Wait for CI to pass, fixing errors. |
122 |
| -5. Wait for a merge! |
123 |
| - |
124 |
| -### Test before you commit |
125 |
| - |
126 |
| -We have two automated tests running on [Travis](https://travis-ci.org/rust-lang/libc): |
127 |
| - |
128 |
| -1. [`libc-test`](https://github.com/alexcrichton/ctest) |
129 |
| - - `cd libc-test && cargo test` |
130 |
| - - Use the `skip_*()` functions in `build.rs` if you really need a workaround. |
131 |
| -2. Style checker |
132 |
| - - `rustc ci/style.rs && ./style src` |
133 |
| - |
134 |
| -### Releasing your change to crates.io |
135 |
| - |
136 |
| -Now that you've done the amazing job of landing your new API or your new |
137 |
| -platform in this crate, the next step is to get that sweet, sweet usage from |
138 |
| -crates.io! The only next step is to bump the version of libc and then publish |
139 |
| -it. If you'd like to get a release out ASAP you can follow these steps: |
140 |
| - |
141 |
| -1. Update the version number in `Cargo.toml`, you'll just be bumping the patch |
142 |
| - version number. |
143 |
| -2. Run `cargo update` to regenerate the lockfile to encode your version bump in |
144 |
| - the lock file. You may pull in some other updated dependencies, that's ok. |
145 |
| -3. Send a PR to this repository. It should [look like this][example], but it'd |
146 |
| - also be nice to fill out the description with a small rationale for the |
147 |
| - release (any rationale is ok though!) |
148 |
| -4. Once merged the release will be tagged and published by one of the libc crate |
149 |
| - maintainers. |
150 |
| - |
151 |
| -[example]: https://github.com/rust-lang/libc/pull/583 |
152 |
| - |
153 |
| -## Platforms and Documentation |
154 |
| - |
155 |
| -The following platforms are currently tested and have documentation available: |
156 |
| - |
157 |
| -Tested: |
158 |
| - * [`i686-pc-windows-msvc`](https://rust-lang.github.io/libc/i686-pc-windows-msvc/libc/) |
159 |
| - * [`x86_64-pc-windows-msvc`](https://rust-lang.github.io/libc/x86_64-pc-windows-msvc/libc/) |
160 |
| - (Windows) |
161 |
| - * [`i686-pc-windows-gnu`](https://rust-lang.github.io/libc/i686-pc-windows-gnu/libc/) |
162 |
| - * [`x86_64-pc-windows-gnu`](https://rust-lang.github.io/libc/x86_64-pc-windows-gnu/libc/) |
163 |
| - * [`i686-apple-darwin`](https://rust-lang.github.io/libc/i686-apple-darwin/libc/) |
164 |
| - * [`x86_64-apple-darwin`](https://rust-lang.github.io/libc/x86_64-apple-darwin/libc/) |
165 |
| - (OSX) |
166 |
| - * `i386-apple-ios` |
167 |
| - * `x86_64-apple-ios` |
168 |
| - * [`i686-unknown-linux-gnu`](https://rust-lang.github.io/libc/i686-unknown-linux-gnu/libc/) |
169 |
| - * [`x86_64-unknown-linux-gnu`](https://rust-lang.github.io/libc/x86_64-unknown-linux-gnu/libc/) |
170 |
| - (Linux) |
171 |
| - * [`x86_64-unknown-linux-musl`](https://rust-lang.github.io/libc/x86_64-unknown-linux-musl/libc/) |
172 |
| - (Linux MUSL) |
173 |
| - * [`aarch64-unknown-linux-gnu`](https://rust-lang.github.io/libc/aarch64-unknown-linux-gnu/libc/) |
174 |
| - (Linux) |
175 |
| - * `aarch64-unknown-linux-musl` |
176 |
| - (Linux MUSL) |
177 |
| - * [`sparc64-unknown-linux-gnu`](https://rust-lang.github.io/libc/sparc64-unknown-linux-gnu/libc/) |
178 |
| - (Linux) |
179 |
| - * [`mips-unknown-linux-gnu`](https://rust-lang.github.io/libc/mips-unknown-linux-gnu/libc/) |
180 |
| - * [`arm-unknown-linux-gnueabihf`](https://rust-lang.github.io/libc/arm-unknown-linux-gnueabihf/libc/) |
181 |
| - * [`arm-linux-androideabi`](https://rust-lang.github.io/libc/arm-linux-androideabi/libc/) |
182 |
| - (Android) |
183 |
| - * [`x86_64-unknown-freebsd`](https://rust-lang.github.io/libc/x86_64-unknown-freebsd/libc/) |
184 |
| - * [`x86_64-unknown-openbsd`](https://rust-lang.github.io/libc/x86_64-unknown-openbsd/libc/) |
185 |
| - * [`x86_64-rumprun-netbsd`](https://rust-lang.github.io/libc/x86_64-unknown-netbsd/libc/) |
186 |
| - |
187 |
| -The following may be supported, but are not guaranteed to always work: |
188 |
| - |
189 |
| - * `i686-unknown-freebsd` |
190 |
| - * [`x86_64-unknown-bitrig`](https://rust-lang.github.io/libc/x86_64-unknown-bitrig/libc/) |
191 |
| - * [`x86_64-unknown-dragonfly`](https://rust-lang.github.io/libc/x86_64-unknown-dragonfly/libc/) |
192 |
| - * `i686-unknown-haiku` |
193 |
| - * `x86_64-unknown-haiku` |
194 |
| - * [`x86_64-unknown-netbsd`](https://rust-lang.github.io/libc/x86_64-unknown-netbsd/libc/) |
195 |
| - * [`x86_64-sun-solaris`](https://rust-lang.github.io/libc/x86_64-sun-solaris/libc/) |
| 90 | +[Travis-CI]: https://travis-ci.com/rust-lang/libc |
| 91 | +[Travis-CI Status]: https://travis-ci.com/rust-lang/libc.svg?branch=master |
| 92 | +[Appveyor]: https://ci.appveyor.com/project/rust-lang-libs/libc |
| 93 | +[Appveyor Status]: https://ci.appveyor.com/api/projects/status/github/rust-lang/libc?svg=true |
| 94 | +[Cirrus-CI]: https://cirrus-ci.com/github/rust-lang/libc |
| 95 | +[Cirrus-CI Status]: https://api.cirrus-ci.com/github/rust-lang/libc.svg |
| 96 | +[crates.io]: https://crates.io/crates/libc |
| 97 | +[Latest Version]: https://img.shields.io/crates/v/libc.svg |
| 98 | +[Documentation]: https://docs.rs/libc/badge.svg |
| 99 | +[docs.rs]: https://docs.rs/libc |
| 100 | +[License]: https://img.shields.io/crates/l/libc.svg |
| 101 | +[docs.master]: https://rust-lang.github.io/libc |
0 commit comments