xref: /rust-libc-0.2.174/CONTRIBUTING.md (revision 3e48e4b2)
183298283Sgnzlbg# Contributing to `libc`
283298283Sgnzlbg
36a4da8f2STrevor GrossWelcome! If you are reading this document, it means you are interested in
46a4da8f2STrevor Grosscontributing to the `libc` crate.
583298283Sgnzlbg
65d234d26STrevor Gross## v1.0 Roadmap
7f8c19f5cSYuki Okushi
85d234d26STrevor Gross`libc` has two active branches: `main` and `libc-0.2`. `main` is for active
95d234d26STrevor Grossdevelopment of the upcoming v1.0 release, and should be the target of all pull
105d234d26STrevor Grossrequests. `libc-0.2` is for updates to the currently released version.
115d234d26STrevor Gross
125d234d26STrevor GrossIf a pull request to `main` is a good candidate for inclusion in an `0.2.x`
135d234d26STrevor Grossrelease, include `@rustbot label stable-nominated` in a comment to propose this.
145d234d26STrevor GrossGood candidates will usually meet the following:
155d234d26STrevor Gross
165d234d26STrevor Gross1. The included changes are non-breaking.
175d234d26STrevor Gross2. The change applies cleanly to both branches.
185d234d26STrevor Gross3. There is a usecase that justifies inclusion in a stable release (all
195d234d26STrevor Gross   additions should always have a usecase, hopefully).
205d234d26STrevor Gross
215d234d26STrevor GrossOnce a `stable-nominated` PR targeting `main` has merged, it can be cherry
225d234d26STrevor Grosspicked to the `libc-0.2` branch. A maintainer will likely do these cherry picks
235d234d26STrevor Grossin a batch.
245d234d26STrevor Gross
255d234d26STrevor GrossAlternatively, you can start this process yourself by creating a new branch
265d234d26STrevor Grossbased on `libc-0.2` and running `git cherry-pick -xe commit-sha-on-main`
275d234d26STrevor Gross(`git
285d234d26STrevor Grosscherry-pick -xe start-sha^..end-sha` if a range of commits is needed).
295d234d26STrevor Gross`git` will automatically add the "cherry picked from commit" note, but try to
305d234d26STrevor Grossadd a backport note so the original PR gets crosslinked:
315d234d26STrevor Gross
325d234d26STrevor Gross```
335d234d26STrevor Gross# ... original commit message ...
345d234d26STrevor Gross
355d234d26STrevor Gross(backport <https://github.com/rust-lang/libc/pull/1234>)             # add manually
365d234d26STrevor Gross(cherry picked from commit 104b6a4ae31c726814c36318dc718470cc96e167) # added by git
375d234d26STrevor Gross```
385d234d26STrevor Gross
395d234d26STrevor GrossOnce the cherry-pick is complete, open a PR targeting `libc-0.2`.
405d234d26STrevor Gross
415d234d26STrevor GrossSee the [tracking issue](https://github.com/rust-lang/libc/issues/3248) for
425d234d26STrevor Grossdetails.
43f8c19f5cSYuki Okushi
4483298283Sgnzlbg## Adding an API
4583298283Sgnzlbg
4683298283SgnzlbgWant to use an API which currently isn't bound in `libc`? It's quite easy to add
4783298283Sgnzlbgone!
4883298283Sgnzlbg
4983298283SgnzlbgThe internal structure of this crate is designed to minimize the number of
506a4da8f2STrevor Gross`#[cfg]` attributes in order to easily be able to add new items which apply to
516a4da8f2STrevor Grossall platforms in the future. As a result, the crate is organized hierarchically
526a4da8f2STrevor Grossbased on platform. Each module has a number of `#[cfg]`'d children, but only one
536a4da8f2STrevor Grossis ever actually compiled. Each module then reexports all the contents of its
546a4da8f2STrevor Grosschildren.
5583298283Sgnzlbg
566a4da8f2STrevor GrossThis means that for each platform that libc supports, the path from a leaf
576a4da8f2STrevor Grossmodule to the root will contain all bindings for the platform in question.
5883298283SgnzlbgConsequently, this indicates where an API should be added! Adding an API at a
5983298283Sgnzlbgparticular level in the hierarchy means that it is supported on all the child
6083298283Sgnzlbgplatforms of that level. For example, when adding a Unix API it should be added
6183298283Sgnzlbgto `src/unix/mod.rs`, but when adding a Linux-only API it should be added to
629a09cb4fSPhilipp Gesang`src/unix/linux_like/linux/mod.rs`.
6383298283Sgnzlbg
6483298283SgnzlbgIf you're not 100% sure at what level of the hierarchy an API should be added
6583298283Sgnzlbgat, fear not! This crate has CI support which tests any binding against all
6683298283Sgnzlbgplatforms supported, so you'll see failures if an API is added at the wrong
6783298283Sgnzlbglevel or has different signatures across platforms.
6883298283Sgnzlbg
690758ff06SThomas de ZeeuwNew symbol(s) (i.e. functions, constants etc.) should also be added to the
700758ff06SThomas de Zeeuwsymbols list(s) found in the `libc-test/semver` directory. These lists keep
710758ff06SThomas de Zeeuwtrack of what symbols are public in the libc crate and ensures they remain
720758ff06SThomas de Zeeuwavailable between changes to the crate. If the new symbol(s) are available on
730758ff06SThomas de Zeeuwall supported Unixes it should be added to `unix.txt` list<sup>1</sup>,
740758ff06SThomas de Zeeuwotherwise they should be added to the OS specific list(s).
750758ff06SThomas de Zeeuw
7683298283SgnzlbgWith that in mind, the steps for adding a new API are:
7783298283Sgnzlbg
7883298283Sgnzlbg1. Determine where in the module hierarchy your API should be added.
790758ff06SThomas de Zeeuw2. Add the API, including adding new symbol(s) to the semver lists.
8083298283Sgnzlbg3. Send a PR to this repo.
8183298283Sgnzlbg4. Wait for CI to pass, fixing errors.
8283298283Sgnzlbg5. Wait for a merge!
8383298283Sgnzlbg
840758ff06SThomas de Zeeuw<sup>1</sup>: Note that this list has nothing to do with any Unix or Posix
855d234d26STrevor Grossstandard, it's just a list shared among all OSs that declare `#[cfg(unix)]`.
860758ff06SThomas de Zeeuw
87bf97671bSYuki Okushi## Test before you commit
8883298283Sgnzlbg
896a4da8f2STrevor GrossWe have two automated tests running on
906a4da8f2STrevor Gross[GitHub Actions](https://github.com/rust-lang/libc/actions):
9183298283Sgnzlbg
92ed757a82SAlex Touchet1. [`libc-test`](https://github.com/gnzlbg/ctest)
9383298283Sgnzlbg  - `cd libc-test && cargo test`
9483298283Sgnzlbg  - Use the `skip_*()` functions in `build.rs` if you really need a workaround.
9583298283Sgnzlbg2. Style checker
96*3e48e4b2STrevor Gross  - [`./ci/style.sh`](https://github.com/rust-lang/libc/blob/main/ci/style.sh)
9783298283Sgnzlbg
98bf97671bSYuki Okushi## Breaking change policy
99bf97671bSYuki Okushi
1006a4da8f2STrevor GrossSometimes an upstream adds a breaking change to their API e.g. removing outdated
1016a4da8f2STrevor Grossitems, changing the type signature, etc. And we probably should follow that
1026a4da8f2STrevor Grosschange to build the `libc` crate successfully. It's annoying to do the
1036a4da8f2STrevor Grossequivalent of semver-major versioning for each such change. Instead, we mark the
1046a4da8f2STrevor Grossitem as deprecated and do the actual change after a certain period. The steps
1056a4da8f2STrevor Grossare:
106bf97671bSYuki Okushi
107bf97671bSYuki Okushi1. Add `#[deprecated(since = "", note="")]` attribute to the item.
1086a4da8f2STrevor Gross  - The `since` field should have a next version of `libc` (e.g., if the current
1096a4da8f2STrevor Gross    version is `0.2.1`, it should be `0.2.2`).
1106a4da8f2STrevor Gross  - The `note` field should have a reason to deprecate and a tracking issue to
1116a4da8f2STrevor Gross    call for comments (e.g., "We consider removing this as the upstream removed
1126a4da8f2STrevor Gross    it. If you're using it, please comment on #XXX").
113bf97671bSYuki Okushi2. If we don't see any concerns for a while, do the change actually.
114bf97671bSYuki Okushi
1157889f955SYuki Okushi## Supported target policy
1167889f955SYuki Okushi
1176a4da8f2STrevor GrossWhen Rust removes a support for a target, the libc crate also may remove the
1185d234d26STrevor Grosssupport at any time.
1197889f955SYuki Okushi
120bf97671bSYuki Okushi## Releasing your change to crates.io
12183298283Sgnzlbg
122a3542611STrevor GrossThis repository uses [release-plz] to handle releases. Once your pull request
123a3542611STrevor Grosshas been merged, a maintainer just needs to verify the generated changelog, then
124a3542611STrevor Grossmerge the bot's release PR. This will automatically publish to crates.io!
12583298283Sgnzlbg
126a3542611STrevor Gross[release-plz]: https://github.com/MarcoIeni/release-plz
127