#bindings #ffi #code-generation

build bindgen

Automatically generates Rust FFI bindings to C and C++ libraries

84 releases (37 breaking)

0.52.0 Nov 19, 2019
0.51.0 Jul 26, 2019
0.50.1 Sep 23, 2019
0.49.4 Dec 4, 2019
0.0.2 Nov 21, 2014

#1 in FFI

Download history 20457/week @ 2019-08-21 21121/week @ 2019-08-28 21849/week @ 2019-09-04 22184/week @ 2019-09-11 26513/week @ 2019-09-18 26777/week @ 2019-09-25 26291/week @ 2019-10-02 27801/week @ 2019-10-09 27290/week @ 2019-10-16 28153/week @ 2019-10-23 26554/week @ 2019-10-30 29472/week @ 2019-11-06 29836/week @ 2019-11-13 29891/week @ 2019-11-20 26752/week @ 2019-11-27

115,109 downloads per month
Used in 960 crates (470 directly)

BSD-3-Clause

1MB
19K SLoC

crates.io docs.rs

bindgen

bindgen automatically generates Rust FFI bindings to C (and some C++) libraries.

For example, given the C header doggo.h:

typedef struct Doggo {
    int many;
    char wow;
} Doggo;

void eleven_out_of_ten_majestic_af(Doggo* pupper);

bindgen produces Rust FFI code allowing you to call into the doggo library's functions and use its types:

/* automatically generated by rust-bindgen */

#[repr(C)]
pub struct Doggo {
    pub many: ::std::os::raw::c_int,
    pub wow: ::std::os::raw::c_char,
}

extern "C" {
    pub fn eleven_out_of_ten_majestic_af(pupper: *mut Doggo);
}

Users Guide

📚 Read the bindgen users guide here! 📚

API Reference

API reference documentation is on docs.rs

Contributing

See CONTRIBUTING.md for hacking on bindgen!

Dependencies

~3.5MB
~78K SLoC