xref: /rust-libc-0.2.174/CONTRIBUTING.md (revision fe8470be)
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 [GitHub Actions](https://github.com/rust-lang/libc/actions):
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## Breaking change policy
50
51Sometimes an upstream adds a breaking change to their API e.g. removing outdated items,
52changing the type signature, etc. And we probably should follow that change to build the
53`libc` crate successfully. It's annoying to do the equivalent of semver-major versioning
54for each such change. Instead, we mark the item as deprecated and do the actual change
55after a certain period. The steps are:
56
571. Add `#[deprecated(since = "", note="")]` attribute to the item.
58  - The `since` field should have a next version of `libc`
59    (e.g., if the current version is `0.2.1`, it should be `0.2.2`).
60  - The `note` field should have a reason to deprecate and a tracking issue to call for comments
61    (e.g., "We consider removing this as the upstream removed it.
62    If you're using it, please comment on #XXX").
632. If we don't see any concerns for a while, do the change actually.
64
65## Releasing your change to crates.io
66
67Now that you've done the amazing job of landing your new API or your new
68platform in this crate, the next step is to get that sweet, sweet usage from
69crates.io! The only next step is to bump the version of libc and then publish
70it. If you'd like to get a release out ASAP you can follow these steps:
71
721. Increment the patch version number in `Cargo.toml`.
731. Send a PR to this repository. It should [look like this][example], but it'd
74   also be nice to fill out the description with a small rationale for the
75   release (any rationale is ok though!)
761. Once merged, the release will be tagged and published by one of the libc crate
77   maintainers.
78
79[example]: https://github.com/rust-lang/libc/pull/583
80