libc
Welcome! If you are reading this document, it means you are interested in contributing to the libc
crate.
Want to use an API which currently isn‘t bound in libc
? It’s quite easy to add one!
The internal structure of this crate is designed to minimize the number of #[cfg]
attributes in order to easily be able to add new items which apply to all platforms in the future. As a result, the crate is organized hierarchically based on platform. Each module has a number of #[cfg]
'd children, but only one is ever actually compiled. Each module then reexports all the contents of its children.
This means that for each platform that libc supports, the path from a leaf module to the root will contain all bindings for the platform in question. Consequently, this indicates where an API should be added! Adding an API at a particular level in the hierarchy means that it is supported on all the child platforms of that level. For example, when adding a Unix API it should be added to src/unix/mod.rs
, but when adding a Linux-only API it should be added to src/unix/linux_like/linux/mod.rs
.
If you‘re not 100% sure at what level of the hierarchy an API should be added at, fear not! This crate has CI support which tests any binding against all platforms supported, so you’ll see failures if an API is added at the wrong level or has different signatures across platforms.
With that in mind, the steps for adding a new API are:
We have two automated tests running on Azure Pipelines:
cd libc-test && cargo test
skip_*()
functions in build.rs
if you really need a workaround.rustc ci/style.rs && ./style src
Now that you‘ve done the amazing job of landing your new API or your new platform in this crate, the next step is to get that sweet, sweet usage from crates.io! The only next step is to bump the version of libc and then publish it. If you’d like to get a release out ASAP you can follow these steps:
Cargo.toml
.