| Alex Crichton | 68fe98b | 2015-01-13 07:53:42 -0800 | [diff] [blame] | 1 | libc |
| 2 | ==== |
| 3 | |
| 4 | A Rust library with native bindings to the types and functions commonly found on |
| 5 | various systems, including libc. |
| 6 | |
| Alex Crichton | b7b90d4 | 2016-02-11 09:33:17 -0800 | [diff] [blame] | 7 | [](https://travis-ci.org/rust-lang/libc) |
| Corey Farwell | 15dcbb5 | 2016-11-26 13:49:49 -0500 | [diff] [blame] | 8 | [](https://ci.appveyor.com/project/rust-lang-libs/libc) |
| Alex Crichton | 68fe98b | 2015-01-13 07:53:42 -0800 | [diff] [blame] | 9 | |
| Alex Crichton | 5289b31 | 2015-10-29 11:57:58 -0700 | [diff] [blame] | 10 | [Documentation](#platforms-and-documentation) |
| Alex Crichton | 78f5aca | 2015-09-18 15:01:16 -0700 | [diff] [blame] | 11 | |
| Alex Crichton | 13418a5 | 2015-10-29 11:54:12 -0700 | [diff] [blame] | 12 | ## Usage |
| 13 | |
| 14 | First, add the following to your `Cargo.toml`: |
| 15 | |
| 16 | ```toml |
| 17 | [dependencies] |
| Alex Crichton | 57ba1fa | 2015-11-03 13:23:16 -0800 | [diff] [blame] | 18 | libc = "0.2" |
| Alex Crichton | 13418a5 | 2015-10-29 11:54:12 -0700 | [diff] [blame] | 19 | ``` |
| 20 | |
| 21 | Next, add this to your crate root: |
| 22 | |
| 23 | ```rust |
| 24 | extern crate libc; |
| 25 | ``` |
| 26 | |
| Alex Crichton | 6d46b6f | 2016-01-20 16:39:37 -0800 | [diff] [blame] | 27 | Currently libc by default links to the standard library, but if you would |
| 28 | instead like to use libc in a `#![no_std]` situation or crate you can request |
| 29 | this via: |
| 30 | |
| 31 | ```toml |
| 32 | [dependencies] |
| 33 | libc = { version = "0.2", default-features = false } |
| 34 | ``` |
| 35 | |
| Alex Crichton | 13418a5 | 2015-10-29 11:54:12 -0700 | [diff] [blame] | 36 | ## What is libc? |
| 37 | |
| 38 | The primary purpose of this crate is to provide all of the definitions necessary |
| 39 | to easily interoperate with C code (or "C-like" code) on each of the platforms |
| 40 | that Rust supports. This includes type definitions (e.g. `c_int`), constants |
| 41 | (e.g. `EINVAL`) as well as function headers (e.g. `malloc`). |
| 42 | |
| 43 | This crate does not strive to have any form of compatibility across platforms, |
| 44 | but rather it is simply a straight binding to the system libraries on the |
| 45 | platform in question. |
| 46 | |
| 47 | ## Public API |
| 48 | |
| 49 | This crate exports all underlying platform types, functions, and constants under |
| 50 | the crate root, so all items are accessible as `libc::foo`. The types and values |
| 51 | of all the exported APIs match the platform that libc is compiled for. |
| 52 | |
| Alex Crichton | bbf73de | 2015-10-29 12:28:25 -0700 | [diff] [blame] | 53 | More detailed information about the design of this library can be found in its |
| 54 | [associated RFC][rfc]. |
| 55 | |
| 56 | [rfc]: https://github.com/rust-lang/rfcs/blob/master/text/1291-promote-libc.md |
| 57 | |
| Alex Crichton | 13418a5 | 2015-10-29 11:54:12 -0700 | [diff] [blame] | 58 | ## Adding an API |
| 59 | |
| 60 | Want to use an API which currently isn't bound in `libc`? It's quite easy to add |
| 61 | one! |
| 62 | |
| 63 | The internal structure of this crate is designed to minimize the number of |
| 64 | `#[cfg]` attributes in order to easily be able to add new items which apply |
| 65 | to all platforms in the future. As a result, the crate is organized |
| 66 | hierarchically based on platform. Each module has a number of `#[cfg]`'d |
| 67 | children, but only one is ever actually compiled. Each module then reexports all |
| 68 | the contents of its children. |
| 69 | |
| 70 | This means that for each platform that libc supports, the path from a |
| 71 | leaf module to the root will contain all bindings for the platform in question. |
| 72 | Consequently, this indicates where an API should be added! Adding an API at a |
| 73 | particular level in the hierarchy means that it is supported on all the child |
| 74 | platforms of that level. For example, when adding a Unix API it should be added |
| 75 | to `src/unix/mod.rs`, but when adding a Linux-only API it should be added to |
| 76 | `src/unix/notbsd/linux/mod.rs`. |
| 77 | |
| 78 | If you're not 100% sure at what level of the hierarchy an API should be added |
| 79 | at, fear not! This crate has CI support which tests any binding against all |
| 80 | platforms supported, so you'll see failures if an API is added at the wrong |
| 81 | level or has different signatures across platforms. |
| 82 | |
| Alex Crichton | 524e137 | 2015-10-29 11:57:29 -0700 | [diff] [blame] | 83 | With that in mind, the steps for adding a new API are: |
| 84 | |
| 85 | 1. Determine where in the module hierarchy your API should be added. |
| 86 | 2. Add the API. |
| 87 | 3. Send a PR to this repo. |
| 88 | 4. Wait for CI to pass, fixing errors. |
| 89 | 5. Wait for a merge! |
| 90 | |
| Kai Noda | cba130b | 2016-04-11 10:47:43 +0800 | [diff] [blame] | 91 | ### Test before you commit |
| 92 | |
| 93 | We have two automated tests running on [Travis](https://travis-ci.org/rust-lang/libc): |
| 94 | |
| 95 | 1. [`libc-test`](https://github.com/alexcrichton/ctest) |
| 96 | - `cd libc-test && cargo run` |
| 97 | - Use the `skip_*()` functions in `build.rs` if you really need a workaround. |
| 98 | 2. Style checker |
| 99 | - `rustc ci/style.rs && ./style src` |
| 100 | |
| Alex Crichton | 97a158b | 2017-04-26 15:44:19 -0700 | [diff] [blame^] | 101 | ### Releasing your change to crates.io |
| 102 | |
| 103 | Now that you've done the amazing job of landing your new API or your new |
| 104 | platform in this crate, the next step is to get that sweet, sweet usage from |
| 105 | crates.io! The only next step is to bump the version of libc and then publish |
| 106 | it. If you'd like to get a release out ASAP you can follow these steps: |
| 107 | |
| 108 | 1. Update the version number in `Cargo.toml`, you'll just be bumping the patch |
| 109 | version number. |
| 110 | 2. Run `cargo update` to regenerate the lockfile to encode your version bump in |
| 111 | the lock file. You may pull in some other updated dependencies, that's ok. |
| 112 | 3. Send a PR to this repository. It should [look like this][example], but it'd |
| 113 | also be nice to fill out the description with a small rationale for the |
| 114 | release (any rationale is ok though!) |
| 115 | 4. Once merged the release will be tagged and published by one of the libc crate |
| 116 | maintainers. |
| 117 | |
| 118 | [example]: https://github.com/rust-lang/libc/pull/583 |
| 119 | |
| Alex Crichton | 13418a5 | 2015-10-29 11:54:12 -0700 | [diff] [blame] | 120 | ## Platforms and Documentation |
| 121 | |
| 122 | The following platforms are currently tested and have documentation available: |
| Alex Crichton | 78f5aca | 2015-09-18 15:01:16 -0700 | [diff] [blame] | 123 | |
| 124 | Tested: |
| Alex Crichton | b7b90d4 | 2016-02-11 09:33:17 -0800 | [diff] [blame] | 125 | * [`i686-pc-windows-msvc`](https://doc.rust-lang.org/libc/i686-pc-windows-msvc/libc/) |
| 126 | * [`x86_64-pc-windows-msvc`](https://doc.rust-lang.org/libc/x86_64-pc-windows-msvc/libc/) |
| Alex Crichton | b1fbefa | 2015-10-29 11:56:13 -0700 | [diff] [blame] | 127 | (Windows) |
| Alex Crichton | b7b90d4 | 2016-02-11 09:33:17 -0800 | [diff] [blame] | 128 | * [`i686-pc-windows-gnu`](https://doc.rust-lang.org/libc/i686-pc-windows-gnu/libc/) |
| 129 | * [`x86_64-pc-windows-gnu`](https://doc.rust-lang.org/libc/x86_64-pc-windows-gnu/libc/) |
| 130 | * [`i686-apple-darwin`](https://doc.rust-lang.org/libc/i686-apple-darwin/libc/) |
| 131 | * [`x86_64-apple-darwin`](https://doc.rust-lang.org/libc/x86_64-apple-darwin/libc/) |
| Alex Crichton | b1fbefa | 2015-10-29 11:56:13 -0700 | [diff] [blame] | 132 | (OSX) |
| Kevin Brothaler | 3800c73 | 2017-01-17 21:38:37 -0400 | [diff] [blame] | 133 | * `i386-apple-ios` |
| A.J. Gardner | e335c50 | 2016-04-01 23:34:09 -0500 | [diff] [blame] | 134 | * `x86_64-apple-ios` |
| Alex Crichton | b7b90d4 | 2016-02-11 09:33:17 -0800 | [diff] [blame] | 135 | * [`i686-unknown-linux-gnu`](https://doc.rust-lang.org/libc/i686-unknown-linux-gnu/libc/) |
| 136 | * [`x86_64-unknown-linux-gnu`](https://doc.rust-lang.org/libc/x86_64-unknown-linux-gnu/libc/) |
| Alex Crichton | b1fbefa | 2015-10-29 11:56:13 -0700 | [diff] [blame] | 137 | (Linux) |
| Alex Crichton | b7b90d4 | 2016-02-11 09:33:17 -0800 | [diff] [blame] | 138 | * [`x86_64-unknown-linux-musl`](https://doc.rust-lang.org/libc/x86_64-unknown-linux-musl/libc/) |
| Alex Crichton | b1fbefa | 2015-10-29 11:56:13 -0700 | [diff] [blame] | 139 | (Linux MUSL) |
| Alex Crichton | b7b90d4 | 2016-02-11 09:33:17 -0800 | [diff] [blame] | 140 | * [`aarch64-unknown-linux-gnu`](https://doc.rust-lang.org/libc/aarch64-unknown-linux-gnu/libc/) |
| 141 | * [`mips-unknown-linux-gnu`](https://doc.rust-lang.org/libc/mips-unknown-linux-gnu/libc/) |
| 142 | * [`arm-unknown-linux-gnueabihf`](https://doc.rust-lang.org/libc/arm-unknown-linux-gnueabihf/libc/) |
| 143 | * [`arm-linux-androideabi`](https://doc.rust-lang.org/libc/arm-linux-androideabi/libc/) |
| Alex Crichton | b1fbefa | 2015-10-29 11:56:13 -0700 | [diff] [blame] | 144 | (Android) |
| Alex Crichton | b7b90d4 | 2016-02-11 09:33:17 -0800 | [diff] [blame] | 145 | * [`x86_64-unknown-freebsd`](https://doc.rust-lang.org/libc/x86_64-unknown-freebsd/libc/) |
| 146 | * [`x86_64-unknown-openbsd`](https://doc.rust-lang.org/libc/x86_64-unknown-openbsd/libc/) |
| 147 | * [`x86_64-rumprun-netbsd`](https://doc.rust-lang.org/libc/x86_64-unknown-netbsd/libc/) |
| Alex Crichton | 78f5aca | 2015-09-18 15:01:16 -0700 | [diff] [blame] | 148 | |
| Alex Crichton | 13418a5 | 2015-10-29 11:54:12 -0700 | [diff] [blame] | 149 | The following may be supported, but are not guaranteed to always work: |
| 150 | |
| Alex Crichton | 13418a5 | 2015-10-29 11:54:12 -0700 | [diff] [blame] | 151 | * `i686-unknown-freebsd` |
| Alex Crichton | b7b90d4 | 2016-02-11 09:33:17 -0800 | [diff] [blame] | 152 | * [`x86_64-unknown-bitrig`](https://doc.rust-lang.org/libc/x86_64-unknown-bitrig/libc/) |
| 153 | * [`x86_64-unknown-dragonfly`](https://doc.rust-lang.org/libc/x86_64-unknown-dragonfly/libc/) |
| Niels Sascha Reedijk | a3ff955 | 2016-02-02 21:21:36 +0100 | [diff] [blame] | 154 | * `i686-unknown-haiku` |
| 155 | * `x86_64-unknown-haiku` |
| Alex Crichton | b7b90d4 | 2016-02-11 09:33:17 -0800 | [diff] [blame] | 156 | * [`x86_64-unknown-netbsd`](https://doc.rust-lang.org/libc/x86_64-unknown-netbsd/libc/) |