1# Contributing to `libc`
2
3Welcome! If you are reading this document, it means you are interested in contributing
4to the `libc` crate.
5
6## Adding an API
7
8Want to use an API which currently isn't bound in `libc`? It's quite easy to add
9one!
10
11The internal structure of this crate is designed to minimize the number of
12`#[cfg]` attributes in order to easily be able to add new items which apply
13to all platforms in the future. As a result, the crate is organized
14hierarchically based on platform. Each module has a number of `#[cfg]`'d
15children, but only one is ever actually compiled. Each module then reexports all
16the contents of its children.
17
18This means that for each platform that libc supports, the path from a
19leaf module to the root will contain all bindings for the platform in question.
20Consequently, this indicates where an API should be added! Adding an API at a
21particular level in the hierarchy means that it is supported on all the child
22platforms of that level. For example, when adding a Unix API it should be added
23to `src/unix/mod.rs`, but when adding a Linux-only API it should be added to
24`src/unix/linux_like/linux/mod.rs`.
25
26If you're not 100% sure at what level of the hierarchy an API should be added
27at, fear not! This crate has CI support which tests any binding against all
28platforms supported, so you'll see failures if an API is added at the wrong
29level or has different signatures across platforms.
30
31With that in mind, the steps for adding a new API are:
32
331. Determine where in the module hierarchy your API should be added.
342. Add the API.
353. Send a PR to this repo.
364. Wait for CI to pass, fixing errors.
375. Wait for a merge!
38
39### Test before you commit
40
41We have two automated tests running on [Azure Pipelines](https://dev.azure.com/rust-lang2/libc/_build?definitionId=1&_a=summary):
42
431. [`libc-test`](https://github.com/gnzlbg/ctest)
44  - `cd libc-test && cargo test`
45  - Use the `skip_*()` functions in `build.rs` if you really need a workaround.
462. Style checker
47  - `rustc ci/style.rs && ./style src`
48
49### Releasing your change to crates.io
50
51Now that you've done the amazing job of landing your new API or your new
52platform in this crate, the next step is to get that sweet, sweet usage from
53crates.io! The only next step is to bump the version of libc and then publish
54it. If you'd like to get a release out ASAP you can follow these steps:
55
561. Increment the patch version number in `Cargo.toml`.
571. Send a PR to this repository. It should [look like this][example], but it'd
58   also be nice to fill out the description with a small rationale for the
59   release (any rationale is ok though!)
601. Once merged, the release will be tagged and published by one of the libc crate
61   maintainers.
62
63[example]: https://github.com/rust-lang/libc/pull/583
64