#bindings #ffi #code-generation

build bindgen

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

70 releases (32 breaking)

0.47.1 Jan 29, 2019
0.46.0 Dec 29, 2018
0.44.0 Nov 30, 2018
0.37.4 Jul 1, 2018
0.0.2 Nov 21, 2014

#2 in FFI

Download history 6649/week @ 2018-10-17 6482/week @ 2018-10-24 6634/week @ 2018-10-31 7287/week @ 2018-11-07 7027/week @ 2018-11-14 6268/week @ 2018-11-21 6944/week @ 2018-11-28 7940/week @ 2018-12-05 7580/week @ 2018-12-12 6216/week @ 2018-12-19 4796/week @ 2018-12-26 7590/week @ 2019-01-02 9689/week @ 2019-01-09 9485/week @ 2019-01-16 9422/week @ 2019-01-23

31,582 downloads per month
Used in 561 crates (293 directly)

BSD-3-Clause

1MB
19K 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
~83K SLoC

  • build build.rs
  • dev diff 0.1
  • dev shlex 0.1