#bindings #ffi #code-generation

build bindgen

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

75 releases (34 breaking)

0.49.0 Mar 27, 2019
0.47.3 Feb 25, 2019
0.46.0 Dec 29, 2018
0.44.0 Nov 30, 2018
0.0.2 Nov 21, 2014

#1 in FFI

Download history 5740/week @ 2018-12-20 5030/week @ 2018-12-27 8277/week @ 2019-01-03 9746/week @ 2019-01-10 9640/week @ 2019-01-17 9096/week @ 2019-01-24 10142/week @ 2019-01-31 10515/week @ 2019-02-07 11024/week @ 2019-02-14 10441/week @ 2019-02-21 11284/week @ 2019-02-28 13169/week @ 2019-03-07 12399/week @ 2019-03-14 12032/week @ 2019-03-21 11695/week @ 2019-03-28

45,909 downloads per month
Used in 669 crates (338 directly)

BSD-3-Clause

1MB
18K SLoC

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!


lib.rs:

Generate Rust bindings for C and C++ libraries.

Provide a C/C++ header file, receive Rust FFI code to call into C/C++ functions and use types defined in the header.

See the Builder struct for usage.

See the Users Guide for additional documentation. Autogenerated documentation module.

Dependencies

~5MB
~86K SLoC

  • build build.rs
  • dev diff 0.1