12add0d91Sopenharmony_ci# Contributing to `libc` 22add0d91Sopenharmony_ci 32add0d91Sopenharmony_ciWelcome! If you are reading this document, it means you are interested in contributing 42add0d91Sopenharmony_cito the `libc` crate. 52add0d91Sopenharmony_ci 62add0d91Sopenharmony_ci## Adding an API 72add0d91Sopenharmony_ci 82add0d91Sopenharmony_ciWant to use an API which currently isn't bound in `libc`? It's quite easy to add 92add0d91Sopenharmony_cione! 102add0d91Sopenharmony_ci 112add0d91Sopenharmony_ciThe internal structure of this crate is designed to minimize the number of 122add0d91Sopenharmony_ci`#[cfg]` attributes in order to easily be able to add new items which apply 132add0d91Sopenharmony_cito all platforms in the future. As a result, the crate is organized 142add0d91Sopenharmony_cihierarchically based on platform. Each module has a number of `#[cfg]`'d 152add0d91Sopenharmony_cichildren, but only one is ever actually compiled. Each module then reexports all 162add0d91Sopenharmony_cithe contents of its children. 172add0d91Sopenharmony_ci 182add0d91Sopenharmony_ciThis means that for each platform that libc supports, the path from a 192add0d91Sopenharmony_cileaf module to the root will contain all bindings for the platform in question. 202add0d91Sopenharmony_ciConsequently, this indicates where an API should be added! Adding an API at a 212add0d91Sopenharmony_ciparticular level in the hierarchy means that it is supported on all the child 222add0d91Sopenharmony_ciplatforms of that level. For example, when adding a Unix API it should be added 232add0d91Sopenharmony_cito `src/unix/mod.rs`, but when adding a Linux-only API it should be added to 242add0d91Sopenharmony_ci`src/unix/linux_like/linux/mod.rs`. 252add0d91Sopenharmony_ci 262add0d91Sopenharmony_ciIf you're not 100% sure at what level of the hierarchy an API should be added 272add0d91Sopenharmony_ciat, fear not! This crate has CI support which tests any binding against all 282add0d91Sopenharmony_ciplatforms supported, so you'll see failures if an API is added at the wrong 292add0d91Sopenharmony_cilevel or has different signatures across platforms. 302add0d91Sopenharmony_ci 312add0d91Sopenharmony_ciNew symbol(s) (i.e. functions, constants etc.) should also be added to the 322add0d91Sopenharmony_cisymbols list(s) found in the `libc-test/semver` directory. These lists keep 332add0d91Sopenharmony_citrack of what symbols are public in the libc crate and ensures they remain 342add0d91Sopenharmony_ciavailable between changes to the crate. If the new symbol(s) are available on 352add0d91Sopenharmony_ciall supported Unixes it should be added to `unix.txt` list<sup>1</sup>, 362add0d91Sopenharmony_ciotherwise they should be added to the OS specific list(s). 372add0d91Sopenharmony_ci 382add0d91Sopenharmony_ciWith that in mind, the steps for adding a new API are: 392add0d91Sopenharmony_ci 402add0d91Sopenharmony_ci1. Determine where in the module hierarchy your API should be added. 412add0d91Sopenharmony_ci2. Add the API, including adding new symbol(s) to the semver lists. 422add0d91Sopenharmony_ci3. Send a PR to this repo. 432add0d91Sopenharmony_ci4. Wait for CI to pass, fixing errors. 442add0d91Sopenharmony_ci5. Wait for a merge! 452add0d91Sopenharmony_ci 462add0d91Sopenharmony_ci<sup>1</sup>: Note that this list has nothing to do with any Unix or Posix 472add0d91Sopenharmony_cistandard, it's just a list shared between all OSs that declare `#[cfg(unix)]`. 482add0d91Sopenharmony_ci 492add0d91Sopenharmony_ci## Test before you commit 502add0d91Sopenharmony_ci 512add0d91Sopenharmony_ciWe have two automated tests running on [GitHub Actions](https://github.com/rust-lang/libc/actions): 522add0d91Sopenharmony_ci 532add0d91Sopenharmony_ci1. [`libc-test`](https://github.com/gnzlbg/ctest) 542add0d91Sopenharmony_ci - `cd libc-test && cargo test` 552add0d91Sopenharmony_ci - Use the `skip_*()` functions in `build.rs` if you really need a workaround. 562add0d91Sopenharmony_ci2. Style checker 572add0d91Sopenharmony_ci - `rustc ci/style.rs && ./style src` 582add0d91Sopenharmony_ci 592add0d91Sopenharmony_ci## Breaking change policy 602add0d91Sopenharmony_ci 612add0d91Sopenharmony_ciSometimes an upstream adds a breaking change to their API e.g. removing outdated items, 622add0d91Sopenharmony_cichanging the type signature, etc. And we probably should follow that change to build the 632add0d91Sopenharmony_ci`libc` crate successfully. It's annoying to do the equivalent of semver-major versioning 642add0d91Sopenharmony_cifor each such change. Instead, we mark the item as deprecated and do the actual change 652add0d91Sopenharmony_ciafter a certain period. The steps are: 662add0d91Sopenharmony_ci 672add0d91Sopenharmony_ci1. Add `#[deprecated(since = "", note="")]` attribute to the item. 682add0d91Sopenharmony_ci - The `since` field should have a next version of `libc` 692add0d91Sopenharmony_ci (e.g., if the current version is `0.2.1`, it should be `0.2.2`). 702add0d91Sopenharmony_ci - The `note` field should have a reason to deprecate and a tracking issue to call for comments 712add0d91Sopenharmony_ci (e.g., "We consider removing this as the upstream removed it. 722add0d91Sopenharmony_ci If you're using it, please comment on #XXX"). 732add0d91Sopenharmony_ci2. If we don't see any concerns for a while, do the change actually. 742add0d91Sopenharmony_ci 752add0d91Sopenharmony_ci## Supported target policy 762add0d91Sopenharmony_ci 772add0d91Sopenharmony_ciWhen Rust removes a support for a target, the libc crate also may remove the support anytime. 782add0d91Sopenharmony_ci 792add0d91Sopenharmony_ci## Releasing your change to crates.io 802add0d91Sopenharmony_ci 812add0d91Sopenharmony_ciNow that you've done the amazing job of landing your new API or your new 822add0d91Sopenharmony_ciplatform in this crate, the next step is to get that sweet, sweet usage from 832add0d91Sopenharmony_cicrates.io! The only next step is to bump the version of libc and then publish 842add0d91Sopenharmony_ciit. If you'd like to get a release out ASAP you can follow these steps: 852add0d91Sopenharmony_ci 862add0d91Sopenharmony_ci1. Increment the patch version number in `Cargo.toml` and `libc-test/Cargo.toml`. 872add0d91Sopenharmony_ci1. Send a PR to this repository. It should [look like this][example-pr], but it'd 882add0d91Sopenharmony_ci also be nice to fill out the description with a small rationale for the 892add0d91Sopenharmony_ci release (any rationale is ok though!). 902add0d91Sopenharmony_ci1. Once merged, the release will be tagged and published by one of the libc crate 912add0d91Sopenharmony_ci maintainers. 922add0d91Sopenharmony_ci 932add0d91Sopenharmony_ci[example-pr]: https://github.com/rust-lang/libc/pull/2120 94