From ef8f09ae522da8634457425bcfad3fafd0c5f008 Mon Sep 17 00:00:00 2001 From: Dan Burkert Date: Sun, 23 Nov 2014 22:18:00 -0800 Subject: [PATCH] Use gcc Cargo helper instead of makefile in lmdb-sys --- .travis.yml | 2 +- README.md | 8 ++++++++ lmdb-sys/Cargo.toml | 3 +++ lmdb-sys/build.rs | 49 +++++++++------------------------------------ 4 files changed, 21 insertions(+), 41 deletions(-) diff --git a/.travis.yml b/.travis.yml index 701725d..76021b7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,4 +7,4 @@ script: - cargo test -v - cargo doc after_script: - - curl http://www.rust-ci.org/artifacts/put?t=$RUSTCI_TOKEN | sh + - mv target/doc . && curl http://www.rust-ci.org/artifacts/put?t=$RUSTCI_TOKEN | sh diff --git a/README.md b/README.md index 78efa90..1982bdc 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,14 @@ Safe Rust bindings for the [Symas Lightning Memory-Mapped Database (LMDB)](http: Provides the minimal amount of abstraction necessary to interact with LMDB safely in Rust. In general, the API is very similar to the LMDB [C-API](http://symas.com/mdb/doc/). +## Building from Source + +```bash +git clone --recursive git@github.com:danburkert/lmdb-rs.git +cd lmdb-rs +cargo build +``` + ## TODO * [x] lmdb-sys. diff --git a/lmdb-sys/Cargo.toml b/lmdb-sys/Cargo.toml index 52b6cb6..807f983 100644 --- a/lmdb-sys/Cargo.toml +++ b/lmdb-sys/Cargo.toml @@ -14,3 +14,6 @@ name = "lmdb-sys" [build-dependencies.pkg-config] pkg-config = "*" + +[build-dependencies.gcc] +gcc = "*" diff --git a/lmdb-sys/build.rs b/lmdb-sys/build.rs index 4742810..2a29122 100644 --- a/lmdb-sys/build.rs +++ b/lmdb-sys/build.rs @@ -1,49 +1,18 @@ extern crate "pkg-config" as pkg_config; +extern crate gcc; -use std::io::process::Command; +use std::default::Default; use std::os; -/// Run a command and ensure a successful result. -fn run_cmd(cmd: &Command) { - assert!(cmd.status().unwrap().success(), - format!("Failed to execute command \"{}\"", cmd)) -} - fn main() { - if pkg_config::find_library("liblmdb").is_ok() { return } - - let base_dir = Path::new(os::getenv("CARGO_MANIFEST_DIR").unwrap()); - let lmdb_dir = base_dir.join_many(&["mdb", "libraries", "liblmdb"]); - let dest_dir = Path::new(os::getenv("OUT_DIR").unwrap()); + if !pkg_config::find_library("liblmdb").is_ok() { - let mut cflags = os::getenv("CFLAGS").unwrap_or(String::new()); - let target = os::getenv("TARGET").unwrap(); + let mdb = Path::new(os::getenv("CARGO_MANIFEST_DIR").unwrap()) + .join_many(&["mdb", "libraries", "liblmdb"]); - if target.contains("i686") { - cflags.push_str(" -m32"); - } else if target.contains("x86_64") { - cflags.push_str(" -m64"); + gcc::compile_library("liblmdb.a", + &Default::default(), + &[mdb.join("mdb.c").as_str().unwrap(), + mdb.join("midl.c").as_str().unwrap()]) } - if !target.contains("i686") { - cflags.push_str(" -fPIC"); - } - - let mut make = Command::new("make"); - make.arg("-C").arg(lmdb_dir.clone()); - - let mut make_build = make.clone(); - make_build.arg("liblmdb.a") - .arg(format!("XCFLAGS={}", cflags)); - - let mut make_clean = make.clone(); - make_clean.arg("clean"); - - run_cmd(&make_clean); - run_cmd(&make_build); - run_cmd(Command::new("cp") - .arg(lmdb_dir.join("liblmdb.a")) - .arg(dest_dir.clone())); - run_cmd(&make_clean); - - println!("cargo:rustc-flags=-L {} -l lmdb:static", dest_dir.display()); }