From 8dd27d805914d9cbc4dd80641b133ede256c7812 Mon Sep 17 00:00:00 2001 From: Yuri Setiantoko Date: Wed, 24 Jun 2015 21:24:00 +0700 Subject: [PATCH 1/2] add CLANG_INCLUDE_DIR environment hacks - Some linux distro just can't detect correctly when building using rust-bindgen. --- mongo_c_driver_wrapper/build.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mongo_c_driver_wrapper/build.rs b/mongo_c_driver_wrapper/build.rs index adc00e5..e42aefe 100644 --- a/mongo_c_driver_wrapper/build.rs +++ b/mongo_c_driver_wrapper/build.rs @@ -13,6 +13,7 @@ static VERSION: &'static str = "1.1.8"; // Should be the same as the version in fn main() { let out_dir = env::var("OUT_DIR").unwrap(); let current_dir = env::var("CARGO_MANIFEST_DIR").unwrap(); + let driver_path = format!( "mongo-c-driver-{}", VERSION @@ -62,10 +63,15 @@ fn main() { let bindings_rs_path = Path::new(¤t_dir).join("src/bindings.rs"); let mongo_h_path = Path::new(¤t_dir).join(&driver_path).join("src/mongoc/mongoc.h"); let bson_path = Path::new(¤t_dir).join(&driver_path).join("src/libbson/src/bson"); + + // Add include CLANG_INCLUDE_DIR so that several issue in searching + // clang include dir bindgen::builder() .emit_builtins() .header(mongo_h_path.to_str().unwrap()) .clang_arg(format!("-I{}", bson_path.to_str().unwrap())) + .clang_arg(format!("-I{}", env::var("CLANG_INCLUDE_DIR") + .unwrap_or(String::from("/usr/lib/clang/3.6.1/include")))) .generate() .unwrap() .write_to_file(&bindings_rs_path) From f772e1db307ee4e26c0984d2a3378b9295b6b5d6 Mon Sep 17 00:00:00 2001 From: Yuri Setiantoko Date: Wed, 24 Jun 2015 22:58:26 +0700 Subject: [PATCH 2/2] omit default clang include dir path --- mongo_c_driver_wrapper/build.rs | 34 +++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/mongo_c_driver_wrapper/build.rs b/mongo_c_driver_wrapper/build.rs index e42aefe..838fc2d 100644 --- a/mongo_c_driver_wrapper/build.rs +++ b/mongo_c_driver_wrapper/build.rs @@ -66,16 +66,30 @@ fn main() { // Add include CLANG_INCLUDE_DIR so that several issue in searching // clang include dir - bindgen::builder() - .emit_builtins() - .header(mongo_h_path.to_str().unwrap()) - .clang_arg(format!("-I{}", bson_path.to_str().unwrap())) - .clang_arg(format!("-I{}", env::var("CLANG_INCLUDE_DIR") - .unwrap_or(String::from("/usr/lib/clang/3.6.1/include")))) - .generate() - .unwrap() - .write_to_file(&bindings_rs_path) - .unwrap(); + match env::var("CLANG_INCLUDE_DIR") { + Ok(dir) => { + bindgen::builder() + .emit_builtins() + .header(mongo_h_path.to_str().unwrap()) + .clang_arg(format!("-I{}", bson_path.to_str().unwrap())) + .clang_arg(format!("-I{}", dir)) + .generate() + .unwrap() + .write_to_file(&bindings_rs_path) + .unwrap(); + }, + Err(_) => { + bindgen::builder() + .emit_builtins() + .header(mongo_h_path.to_str().unwrap()) + .clang_arg(format!("-I{}", bson_path.to_str().unwrap())) + .generate() + .unwrap() + .write_to_file(&bindings_rs_path) + .unwrap(); + } + } + } // Output to Cargo