#bindings #ffi #code-generation

build bindgen

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

81 releases (36 breaking)

0.51.1 Sep 23, 2019
0.51.0 Jul 26, 2019
0.50.1 Sep 23, 2019
0.49.0 Mar 27, 2019
0.0.2 Nov 21, 2014

#1 in FFI

Download history 13983/week @ 2019-06-11 14780/week @ 2019-06-18 16004/week @ 2019-06-25 14559/week @ 2019-07-02 15952/week @ 2019-07-09 15879/week @ 2019-07-16 18848/week @ 2019-07-23 18194/week @ 2019-07-30 20508/week @ 2019-08-06 20817/week @ 2019-08-13 20959/week @ 2019-08-20 20477/week @ 2019-08-27 22001/week @ 2019-09-03 21707/week @ 2019-09-10 25419/week @ 2019-09-17

82,815 downloads per month
Used in 882 crates (438 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
~81K SLoC