diff --git a/lmdb-sys/Cargo.toml b/lmdb-sys/Cargo.toml index 57c1a8c..fc35cf4 100644 --- a/lmdb-sys/Cargo.toml +++ b/lmdb-sys/Cargo.toml @@ -12,7 +12,7 @@ build = "build.rs" name = "lmdb-sys" -[dependencies.rust-bindgen] +[build-dependencies.rust-bindgen] git = "https://github.com/crabtw/rust-bindgen.git" [build-dependencies.pkg-config] diff --git a/lmdb-sys/build.rs b/lmdb-sys/build.rs index dee22ab..9818abb 100644 --- a/lmdb-sys/build.rs +++ b/lmdb-sys/build.rs @@ -1,18 +1,31 @@ extern crate "pkg-config" as pkg_config; +extern crate bindgen; extern crate gcc; +use bindgen::{Bindings, BindgenOptions, LinkType}; use std::default::Default; +use std::io::fs; use std::os; fn main() { - if !pkg_config::find_library("liblmdb").is_ok() { - let mdb = Path::new(os::getenv("CARGO_MANIFEST_DIR").unwrap()) - .join_many(&["mdb", "libraries", "liblmdb"]); + let mdb = Path::new(os::getenv("CARGO_MANIFEST_DIR").unwrap()) + .join_many(&["mdb", "libraries", "liblmdb"]); + if !pkg_config::find_library("liblmdb").is_ok() { gcc::compile_library("liblmdb.a", &Default::default(), &[mdb.join("mdb.c").as_str().unwrap(), mdb.join("midl.c").as_str().unwrap()]); } + + let mut bindgen_opts: BindgenOptions = Default::default(); + bindgen_opts.clang_args.push(mdb.join("lmdb.h").as_str().unwrap().to_string()); + bindgen_opts.links.push(("lmdb".to_string(), LinkType::Default)); + bindgen_opts.builtins = true; + + let bindings: Bindings = Bindings::generate(&bindgen_opts, None, None).unwrap(); + let mut dst = fs::File::create(&Path::new(os::getenv("OUT_DIR").unwrap()) + .join("lmdb.rs")).unwrap(); + bindings.write(&mut dst).unwrap() } diff --git a/lmdb-sys/src/lib.rs b/lmdb-sys/src/lib.rs index 77a6135..881be80 100644 --- a/lmdb-sys/src/lib.rs +++ b/lmdb-sys/src/lib.rs @@ -1,13 +1,16 @@ -#![allow(dead_code, uppercase_variables, non_camel_case_types)] +#![allow( + dead_code, + missing_copy_implementations, + non_camel_case_types, + non_snake_case, + raw_pointer_derive, + )] #![feature(plugin)] -#[plugin] -extern crate bindgen; extern crate libc; -use libc::{size_t, mode_t}; pub use constants::*; mod constants; -bindgen!("../mdb/libraries/liblmdb/lmdb.h", match="lmdb.h", link="lmdb"); +include!(concat!(env!("OUT_DIR"), "/lmdb.rs"));