#bindings #ffi #code-generation

build bindgen

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

87 releases (38 breaking)

0.53.2 Mar 9, 2020
0.52.0 Nov 19, 2019
0.51.0 Jul 26, 2019
0.49.4 Dec 4, 2019
0.0.2 Nov 21, 2014

#1 in FFI

Download history 29837/week @ 2019-12-14 14691/week @ 2019-12-21 18218/week @ 2019-12-28 32391/week @ 2020-01-04 30426/week @ 2020-01-11 29504/week @ 2020-01-18 29898/week @ 2020-01-25 30146/week @ 2020-02-01 30439/week @ 2020-02-08 32133/week @ 2020-02-15 35279/week @ 2020-02-22 35017/week @ 2020-02-29 39097/week @ 2020-03-07 40591/week @ 2020-03-14 41618/week @ 2020-03-21 34179/week @ 2020-03-28

125,147 downloads per month
Used in 1,199 crates (561 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
~76K SLoC