• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

.github/workflows/H03-May-2022-153120

cargo-crates/H03-May-2022-516,233433,815

src/H03-May-2022-13,07010,879

tests/H03-May-2022-38,05128,505

.cargo_vcs_info.jsonH A D01-Jan-197074 65

.clippy.tomlH A D29-Nov-197361 32

.gitattributesH A D29-Nov-1973167 54

.gitignoreH A D29-Nov-197321 43

CHANGESH A D29-Nov-197310.5 KiB259182

Cargo.lockH A D01-Jan-197011 KiB441390

Cargo.tomlH A D01-Jan-19701.8 KiB7762

LICENSEH A D29-Nov-197316.3 KiB374293

README.mdH A D29-Nov-19734.1 KiB9365

build.rsH A D29-Nov-19731.9 KiB7155

contributing.mdH A D29-Nov-19731.4 KiB2513

docs.mdH A D29-Nov-197334.7 KiB1,011746

internals.mdH A D29-Nov-19732.3 KiB3120

template.tomlH A D29-Nov-19732.6 KiB15292

README.md

1# `cbindgen`   [![Build Status]][actions] [![Latest Version]][crates.io] [![Api Rustdoc]][rustdoc] [![Rust](https://img.shields.io/badge/rust-1.32%2B-blue.svg?maxAge=3600)](https://github.com/eqrion/cbindgen)
2
3[Build Status]: https://github.com/eqrion/cbindgen/workflows/cbindgen/badge.svg
4[actions]: https://github.com/eqrion/cbindgen/actions
5[Latest Version]: https://img.shields.io/crates/v/cbindgen.svg
6[crates.io]: https://crates.io/crates/cbindgen
7[Api Rustdoc]: https://img.shields.io/badge/api-rustdoc-blue.svg
8[rustdoc]: https://docs.rs/cbindgen
9
10[Read the full user docs here!](docs.md)
11
12cbindgen creates C/C++11 headers for Rust libraries which expose a public C API.
13
14While you could do this by hand, it's not a particularly good use of your time.
15It's also much more likely to be error-prone than machine-generated headers that
16are based on your actual Rust code. The cbindgen developers have also worked
17closely with the developers of Rust to ensure that the headers we generate
18reflect actual guarantees about Rust's type layout and ABI.
19
20C++ headers are nice because we can use operator overloads, constructors, enum
21classes, and templates to make the API more ergonomic and Rust-like. C headers
22are nice because you can be more confident that whoever you're interoperating
23with can handle them. With cbindgen *you don't need to choose*! You can just
24tell it to emit both from the same Rust library.
25
26There are two ways to use cbindgen: as a standalone program, or as a library
27(presumably in your build.rs). There isn't really much practical difference,
28because cbindgen is a simple rust library with no interesting dependencies.
29
30Using it as a program means people building your software will need it
31installed. Using it in your library means people may have to build cbindgen more
32frequently (e.g. every time they update their rust compiler).
33
34It's worth noting that the development of cbindgen has been largely adhoc, as
35features have been added to support the usecases of the maintainers. This means
36cbindgen may randomly fail to support some particular situation simply because
37no one has put in the effort to handle it yet. [Please file an issue if you run
38into such a situation](https://github.com/eqrion/cbindgen/issues/new). Although
39since we all have other jobs, you might need to do the implementation work too
40:)
41
42# Quick Start
43
44To install cbindgen, you just need to run
45
46```text
47cargo install --force cbindgen
48```
49
50(--force just makes it update to the latest cbindgen if it's already installed)
51
52To use cbindgen you need two things:
53
54* A configuration (cbindgen.toml, which can be empty to start)
55* A Rust crate with a public C API
56
57Then all you need to do is run it:
58
59```text
60cbindgen --config cbindgen.toml --crate my_rust_library --output my_header.h
61```
62
63This produces a header file for C++.  For C, add the `--lang c` switch.
64
65See `cbindgen --help` for more options.
66
67[Read the full user docs here!](docs.md)
68
69[Get a template cbindgen.toml here.](template.toml)
70
71# Examples
72
73We don't currently have a nice tailored example application, but [the
74tests](tests/rust/) contain plenty of interesting examples of our features.
75
76You may also find it interesting to browse the projects that are using cbindgen
77in production:
78
79* [milksnake](https://github.com/getsentry/milksnake)
80* [webrender](https://searchfox.org/mozilla-central/source/gfx/webrender_bindings) ([generated header](https://searchfox.org/mozilla-central/source/__GENERATED__/gfx/webrender_bindings/webrender_ffi_generated.h))
81* [stylo](https://searchfox.org/mozilla-central/source/layout/style) ([generated header](https://searchfox.org/mozilla-central/source/__GENERATED__/layout/style/ServoStyleConsts.h))
82* [wgpu-native](https://github.com/gfx-rs/wgpu-native) ([generated header](https://github.com/gfx-rs/wgpu-native/blob/master/ffi/wgpu.h))
83* [etesync-rs](https://github.com/etesync/etesync-rs)
84
85If you're using `cbindgen` and would like to be added to this list, please open
86a pull request!
87
88# Releases
89
90cbindgen doesn't have a fixed release calendar, please file an issue requesting
91a release if there's something fixed in trunk that you need released. Ping
92`@emilio` for increased effect.
93