vhbit / lmdb-rs

Rust bindings for LMDB
MIT License
114 stars 47 forks source link

Cannot cross-compile liblmdb-sys #33

Closed joerg-krause closed 8 years ago

joerg-krause commented 8 years ago

Unfortunalty, the libmbd Makefile does not allow to override CC and AR: https://github.com/LMDB/lmdb/blob/ad8488cfac644d7a289e428ab3c403c859d844cb/libraries/liblmdb/Makefile#L21-L22.

I am still a novice to Rust. Maybe it's possible to patch the Makefile with build.rs?

xitep commented 8 years ago

don't know if that applies to all make implementations, however, at least with gnu make 3.81 and 4.0 invoking the compilation of lmdb with make CC=quux from within the build.rs seems to do the trick. I have no access to other systems right now.

with the below patch against lmdb-rs you should be able to:

$ export CC=whatever-path-to-my-compiler
$ cargo build

patch:

diff --git a/liblmdb-sys/build.rs b/liblmdb-sys/build.rs
index 130cf56..e93b24c 100755
--- a/liblmdb-sys/build.rs
+++ b/liblmdb-sys/build.rs
@@ -104,6 +104,9 @@ fn main() {
     run(&mut clean_cmd);

     let mut build_cmd = Command::new("make");
+    if let Ok(cc) = env::var("CC") {
+        build_cmd.arg(format!("CC={}", cc));
+    }
     build_cmd.arg("-C").arg(&mdb_root);
     build_cmd.arg("liblmdb.a");
     build_cmd.arg(&format!("XCFLAGS={}", cflags()));

hope this helps, p.

herrernst commented 8 years ago

@xitep thanks, that works. @vhbit Probably it would be a good idea to use the gcc crate for compiling, it takes care of these variables, especially for cross-compiling.

herrernst commented 8 years ago

oh, that was done already, see https://github.com/plietar/lmdb-rs/commit/cf36b6e3a0c8efce2b89558d2721f8d8af8b1ba0 would be great if you could merge this.

xitep commented 8 years ago

indeed, that patch by @plietar looks good to me! what do you think @vhbit?

however, i don't see the following covered (through the gcc crate version) which is supported in the current build.rs:

       if target.contains("dragonfly") {
           cflags.push_str(" -DMDB_DSYNC=O_SYNC");
           cflags.push_str(" -Dfdatasync=fsync");
       }

i have to admit that after having a look into the lmdb sources, i don't understand why we have -Dfdatasync=fsync here; i would expect this rather to be -DMDB_FDATASYNC=fsync.

caring about working out the details @herrernst?

plietar commented 8 years ago

Opened #36

joerg-krause commented 8 years ago

Many thanks!