The following tutorial is adapted from this blog post.
What follows is a whirlwind introductory tutorial to using bindgen from inside build.rs. We'll generate bindings to bzip2 (which is available on most systems) on-the-fly.
bindgen
build.rs
bzip2
TL;DR? The full tutorial code is available here.