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