| 1 |
# libc - Raw FFI bindings to platforms' system libraries |
| 2 |
|
| 3 |
[![GHA Status]][GitHub Actions] [![Cirrus CI Status]][Cirrus CI] [![Latest Version]][crates.io] [![Documentation]][docs.rs] ![License] |
| 4 |
|
| 5 |
`libc` provides all of the definitions necessary to easily interoperate with C |
| 6 |
code (or "C-like" code) on each of the platforms that Rust supports. This |
| 7 |
includes type definitions (e.g. `c_int`), constants (e.g. `EINVAL`) as well as |
| 8 |
function headers (e.g. `malloc`). |
| 9 |
|
| 10 |
This crate exports all underlying platform types, functions, and constants under |
| 11 |
the crate root, so all items are accessible as `libc::foo`. The types and values |
| 12 |
of all the exported APIs match the platform that libc is compiled for. |
| 13 |
|
| 14 |
Windows API bindings are not included in this crate. If you are looking for |
| 15 |
WinAPI bindings, consider using crates like [windows-sys]. |
| 16 |
|
| 17 |
More detailed information about the design of this library can be found in its |
| 18 |
[associated RFC][rfc]. |
| 19 |
|
| 20 |
[rfc]: https://github.com/rust-lang/rfcs/blob/HEAD/text/1291-promote-libc.md |
| 21 |
[windows-sys]: https://docs.rs/windows-sys |
| 22 |
|
| 23 |
## v1.0 Roadmap |
| 24 |
|
| 25 |
Currently, `libc` has two active branches: `main` for the upcoming v1.0 release, |
| 26 |
and `libc-0.2` for the currently published version. By default all pull requests |
| 27 |
should target `main`; once reviewed, they can be cherry picked to the `libc-0.2` |
| 28 |
branch if needed. |
| 29 |
|
| 30 |
We will stop making new v0.2 releases once v1.0 is released. |
| 31 |
|
| 32 |
See the section in [CONTRIBUTING.md](CONTRIBUTING.md#v10-roadmap) for more |
| 33 |
details. |
| 34 |
|
| 35 |
## Usage |
| 36 |
|
| 37 |
Add the following to your `Cargo.toml`: |
| 38 |
|
| 39 |
```toml |
| 40 |
[dependencies] |
| 41 |
libc = "0.2" |
| 42 |
``` |
| 43 |
|
| 44 |
## Features |
| 45 |
|
| 46 |
* `std`: by default `libc` links to the standard library. Disable this feature |
| 47 |
to remove this dependency and be able to use `libc` in `#![no_std]` crates. |
| 48 |
|
| 49 |
* `extra_traits`: all `struct`s implemented in `libc` are `Copy` and `Clone`. |
| 50 |
This feature derives `Debug`, `Eq`, `Hash`, and `PartialEq`. |
| 51 |
|
| 52 |
The following features are deprecated: |
| 53 |
|
| 54 |
* `use_std`: this is equivalent to `std` |
| 55 |
* `const-extern-fn`: this is now enabled by default |
| 56 |
* `align`: this is now enabled by default |
| 57 |
|
| 58 |
## Rust version support |
| 59 |
|
| 60 |
The minimum supported Rust toolchain version is currently **Rust 1.63**. |
| 61 |
|
| 62 |
Increases to the MSRV are allowed to change without a major (i.e. semver- |
| 63 |
breaking) release in order to avoid a ripple effect in the ecosystem. A policy |
| 64 |
for when this may change is a work in progress. |
| 65 |
|
| 66 |
`libc` may continue to compile with Rust versions older than the current MSRV |
| 67 |
but this is not guaranteed. |
| 68 |
|
| 69 |
## Platform support |
| 70 |
|
| 71 |
You can see the platform(target)-specific docs on [docs.rs], select a platform |
| 72 |
you want to see. |
| 73 |
|
| 74 |
See [`ci/verify-build.sh`](https://github.com/rust-lang/libc/blob/HEAD/ci/verify-build.sh) for |
| 75 |
the platforms on which `libc` is guaranteed to build for each Rust toolchain. |
| 76 |
The test-matrix at [GitHub Actions] and [Cirrus CI] show the platforms in which |
| 77 |
`libc` tests are run. |
| 78 |
|
| 79 |
<div class="platform_docs"></div> |
| 80 |
|
| 81 |
## License |
| 82 |
|
| 83 |
This project is licensed under either of |
| 84 |
|
| 85 |
* [Apache License, Version 2.0](https://www.apache.org/licenses/LICENSE-2.0) |
| 86 |
([LICENSE-APACHE](https://github.com/rust-lang/libc/blob/HEAD/LICENSE-APACHE)) |
| 87 |
|
| 88 |
* [MIT License](https://opensource.org/licenses/MIT) |
| 89 |
([LICENSE-MIT](https://github.com/rust-lang/libc/blob/HEAD/LICENSE-MIT)) |
| 90 |
|
| 91 |
at your option. |
| 92 |
|
| 93 |
## Contributing |
| 94 |
|
| 95 |
We welcome all people who want to contribute. Please see the |
| 96 |
[contributing instructions] for more information. |
| 97 |
|
| 98 |
[contributing instructions]: https://github.com/rust-lang/libc/blob/HEAD/CONTRIBUTING.md |
| 99 |
|
| 100 |
Contributions in any form (issues, pull requests, etc.) to this project must |
| 101 |
adhere to Rust's [Code of Conduct]. |
| 102 |
|
| 103 |
[Code of Conduct]: https://www.rust-lang.org/policies/code-of-conduct |
| 104 |
|
| 105 |
Unless you explicitly state otherwise, any contribution intentionally submitted |
| 106 |
for inclusion in `libc` by you, as defined in the Apache-2.0 license, shall be |
| 107 |
dual licensed as above, without any additional terms or conditions. |
| 108 |
|
| 109 |
[GitHub Actions]: https://github.com/rust-lang/libc/actions |
| 110 |
[GHA Status]: https://github.com/rust-lang/libc/workflows/CI/badge.svg |
| 111 |
[Cirrus CI]: https://cirrus-ci.com/github/rust-lang/libc |
| 112 |
[Cirrus CI Status]: https://api.cirrus-ci.com/github/rust-lang/libc.svg |
| 113 |
[crates.io]: https://crates.io/crates/libc |
| 114 |
[Latest Version]: https://img.shields.io/crates/v/libc.svg |
| 115 |
[Documentation]: https://docs.rs/libc/badge.svg |
| 116 |
[docs.rs]: https://docs.rs/libc |
| 117 |
[License]: https://img.shields.io/crates/l/libc.svg |