#bindings #ffi #code-generation

build bindgen

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

57 releases (25 breaking)

0.40.0 Sep 4, 2018
0.38.0 Aug 15, 2018
0.37.4 Jul 1, 2018
0.35.0 Mar 25, 2018
0.0.2 Nov 21, 2014

#6 in FFI

Download history 3567/week @ 2018-09-17 4351/week @ 2018-09-24 4798/week @ 2018-10-01 5070/week @ 2018-10-08 6164/week @ 2018-10-15 7553/week @ 2018-10-22 6433/week @ 2018-10-29 6512/week @ 2018-11-05 7159/week @ 2018-11-12 7487/week @ 2018-11-19 5970/week @ 2018-11-26 6871/week @ 2018-12-03 6453/week @ 2018-12-10

15,103 downloads per month
Used in 501 crates (259 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

~4.5MB
~77K SLoC

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