Execute bindgen in build.rs

without.crypto
Dan Burkert 10 years ago
parent 7ffc6df87f
commit 951ca804e2
  1. 2
      lmdb-sys/Cargo.toml
  2. 19
      lmdb-sys/build.rs
  3. 13
      lmdb-sys/src/lib.rs

@ -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]

@ -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()
}

@ -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"));

Loading…
Cancel
Save