blob: 255283643508942280c7d5eb14cb65c96dc40c91 [file] [log] [blame] [view]
Alex Crichton68fe98b2015-01-13 07:53:42 -08001libc
2====
3
4A Rust library with native bindings to the types and functions commonly found on
5various systems, including libc.
6
Alex Crichtonb7b90d42016-02-11 09:33:17 -08007[![Build Status](https://travis-ci.org/rust-lang/libc.svg?branch=master)](https://travis-ci.org/rust-lang/libc)
Corey Farwell15dcbb52016-11-26 13:49:49 -05008[![Build status](https://ci.appveyor.com/api/projects/status/github/rust-lang/libc?svg=true)](https://ci.appveyor.com/project/rust-lang-libs/libc)
Alex Crichton68fe98b2015-01-13 07:53:42 -08009
Alex Crichton5289b312015-10-29 11:57:58 -070010[Documentation](#platforms-and-documentation)
Alex Crichton78f5aca2015-09-18 15:01:16 -070011
Alex Crichton13418a52015-10-29 11:54:12 -070012## Usage
13
14First, add the following to your `Cargo.toml`:
15
16```toml
17[dependencies]
Alex Crichton57ba1fa2015-11-03 13:23:16 -080018libc = "0.2"
Alex Crichton13418a52015-10-29 11:54:12 -070019```
20
21Next, add this to your crate root:
22
23```rust
24extern crate libc;
25```
26
Alex Crichton6d46b6f2016-01-20 16:39:37 -080027Currently libc by default links to the standard library, but if you would
28instead like to use libc in a `#![no_std]` situation or crate you can request
29this via:
30
31```toml
32[dependencies]
33libc = { version = "0.2", default-features = false }
34```
35
Alex Crichton13418a52015-10-29 11:54:12 -070036## What is libc?
37
38The primary purpose of this crate is to provide all of the definitions necessary
39to easily interoperate with C code (or "C-like" code) on each of the platforms
40that Rust supports. This includes type definitions (e.g. `c_int`), constants
41(e.g. `EINVAL`) as well as function headers (e.g. `malloc`).
42
43This crate does not strive to have any form of compatibility across platforms,
44but rather it is simply a straight binding to the system libraries on the
45platform in question.
46
47## Public API
48
49This crate exports all underlying platform types, functions, and constants under
50the crate root, so all items are accessible as `libc::foo`. The types and values
51of all the exported APIs match the platform that libc is compiled for.
52
Alex Crichtonbbf73de2015-10-29 12:28:25 -070053More 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 Crichton13418a52015-10-29 11:54:12 -070058## Adding an API
59
60Want to use an API which currently isn't bound in `libc`? It's quite easy to add
61one!
62
63The 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
65to all platforms in the future. As a result, the crate is organized
66hierarchically based on platform. Each module has a number of `#[cfg]`'d
67children, but only one is ever actually compiled. Each module then reexports all
68the contents of its children.
69
70This means that for each platform that libc supports, the path from a
71leaf module to the root will contain all bindings for the platform in question.
72Consequently, this indicates where an API should be added! Adding an API at a
73particular level in the hierarchy means that it is supported on all the child
74platforms of that level. For example, when adding a Unix API it should be added
75to `src/unix/mod.rs`, but when adding a Linux-only API it should be added to
76`src/unix/notbsd/linux/mod.rs`.
77
78If you're not 100% sure at what level of the hierarchy an API should be added
79at, fear not! This crate has CI support which tests any binding against all
80platforms supported, so you'll see failures if an API is added at the wrong
81level or has different signatures across platforms.
82
Alex Crichton524e1372015-10-29 11:57:29 -070083With that in mind, the steps for adding a new API are:
84
851. Determine where in the module hierarchy your API should be added.
862. Add the API.
873. Send a PR to this repo.
884. Wait for CI to pass, fixing errors.
895. Wait for a merge!
90
Kai Nodacba130b2016-04-11 10:47:43 +080091### Test before you commit
92
93We have two automated tests running on [Travis](https://travis-ci.org/rust-lang/libc):
94
951. [`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.
982. Style checker
99 - `rustc ci/style.rs && ./style src`
100
Alex Crichton13418a52015-10-29 11:54:12 -0700101## Platforms and Documentation
102
103The following platforms are currently tested and have documentation available:
Alex Crichton78f5aca2015-09-18 15:01:16 -0700104
105Tested:
Alex Crichtonb7b90d42016-02-11 09:33:17 -0800106 * [`i686-pc-windows-msvc`](https://doc.rust-lang.org/libc/i686-pc-windows-msvc/libc/)
107 * [`x86_64-pc-windows-msvc`](https://doc.rust-lang.org/libc/x86_64-pc-windows-msvc/libc/)
Alex Crichtonb1fbefa2015-10-29 11:56:13 -0700108 (Windows)
Alex Crichtonb7b90d42016-02-11 09:33:17 -0800109 * [`i686-pc-windows-gnu`](https://doc.rust-lang.org/libc/i686-pc-windows-gnu/libc/)
110 * [`x86_64-pc-windows-gnu`](https://doc.rust-lang.org/libc/x86_64-pc-windows-gnu/libc/)
111 * [`i686-apple-darwin`](https://doc.rust-lang.org/libc/i686-apple-darwin/libc/)
112 * [`x86_64-apple-darwin`](https://doc.rust-lang.org/libc/x86_64-apple-darwin/libc/)
Alex Crichtonb1fbefa2015-10-29 11:56:13 -0700113 (OSX)
A.J. Gardnere335c502016-04-01 23:34:09 -0500114 * `i686-apple-ios`
115 * `x86_64-apple-ios`
Alex Crichtonb7b90d42016-02-11 09:33:17 -0800116 * [`i686-unknown-linux-gnu`](https://doc.rust-lang.org/libc/i686-unknown-linux-gnu/libc/)
117 * [`x86_64-unknown-linux-gnu`](https://doc.rust-lang.org/libc/x86_64-unknown-linux-gnu/libc/)
Alex Crichtonb1fbefa2015-10-29 11:56:13 -0700118 (Linux)
Alex Crichtonb7b90d42016-02-11 09:33:17 -0800119 * [`x86_64-unknown-linux-musl`](https://doc.rust-lang.org/libc/x86_64-unknown-linux-musl/libc/)
Alex Crichtonb1fbefa2015-10-29 11:56:13 -0700120 (Linux MUSL)
Alex Crichtonb7b90d42016-02-11 09:33:17 -0800121 * [`aarch64-unknown-linux-gnu`](https://doc.rust-lang.org/libc/aarch64-unknown-linux-gnu/libc/)
122 * [`mips-unknown-linux-gnu`](https://doc.rust-lang.org/libc/mips-unknown-linux-gnu/libc/)
123 * [`arm-unknown-linux-gnueabihf`](https://doc.rust-lang.org/libc/arm-unknown-linux-gnueabihf/libc/)
124 * [`arm-linux-androideabi`](https://doc.rust-lang.org/libc/arm-linux-androideabi/libc/)
Alex Crichtonb1fbefa2015-10-29 11:56:13 -0700125 (Android)
Alex Crichtonb7b90d42016-02-11 09:33:17 -0800126 * [`x86_64-unknown-freebsd`](https://doc.rust-lang.org/libc/x86_64-unknown-freebsd/libc/)
127 * [`x86_64-unknown-openbsd`](https://doc.rust-lang.org/libc/x86_64-unknown-openbsd/libc/)
128 * [`x86_64-rumprun-netbsd`](https://doc.rust-lang.org/libc/x86_64-unknown-netbsd/libc/)
Alex Crichton78f5aca2015-09-18 15:01:16 -0700129
Alex Crichton13418a52015-10-29 11:54:12 -0700130The following may be supported, but are not guaranteed to always work:
131
Alex Crichton13418a52015-10-29 11:54:12 -0700132 * `i686-unknown-freebsd`
Alex Crichtonb7b90d42016-02-11 09:33:17 -0800133 * [`x86_64-unknown-bitrig`](https://doc.rust-lang.org/libc/x86_64-unknown-bitrig/libc/)
134 * [`x86_64-unknown-dragonfly`](https://doc.rust-lang.org/libc/x86_64-unknown-dragonfly/libc/)
Niels Sascha Reedijka3ff9552016-02-02 21:21:36 +0100135 * `i686-unknown-haiku`
136 * `x86_64-unknown-haiku`
Alex Crichtonb7b90d42016-02-11 09:33:17 -0800137 * [`x86_64-unknown-netbsd`](https://doc.rust-lang.org/libc/x86_64-unknown-netbsd/libc/)