From a738a9622e041c9bf145883e1c71d4d8cf46a2bb Mon Sep 17 00:00:00 2001 From: Matrix <113445886@qq.com> Date: Sun, 8 Apr 2018 17:41:45 +0800 Subject: [PATCH 1/3] use vcpkg to probe ligmongoc-1.0 under windows --- mongoc-sys/Cargo.toml | 3 +++ mongoc-sys/build.rs | 32 ++++++++++++++++++++++++++------ 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/mongoc-sys/Cargo.toml b/mongoc-sys/Cargo.toml index 4a04fe4..4241b16 100644 --- a/mongoc-sys/Cargo.toml +++ b/mongoc-sys/Cargo.toml @@ -16,3 +16,6 @@ openssl-sys = "0.9" [build-dependencies] pkg-config = "0.3" + +[target.'cfg(target_env = "msvc")'.build-dependencies] +vcpkg = "0.2" diff --git a/mongoc-sys/build.rs b/mongoc-sys/build.rs index a57ccae..e3d0684 100644 --- a/mongoc-sys/build.rs +++ b/mongoc-sys/build.rs @@ -1,9 +1,34 @@ extern crate pkg_config; +#[cfg(target_env = "msvc")] +extern crate vcpkg; use std::env; use std::path::Path; use std::process::Command; +#[cfg(target_env = "msvc")] +fn probe_libmongoc_pkg_config(_: &str) -> bool { + false +} + +#[cfg(target_env = "msvc")] +fn probe_libmongoc_vcpkg() -> bool { + vcpkg::probe_package("libmongoc-1.0").is_ok() +} + +#[cfg(not(target_env = "msvc"))] +fn probe_libmongoc_pkg_config(version: &str) -> bool { + pkg_config::Config::new() + .atleast_version(version) + .statik(true) + .probe("libmongoc-1.0") + .is_ok() +} + +#[cfg(not(target_env = "msvc"))] +fn probe_libmongoc_vcpkg() -> bool { + false +} fn main() { let mongoc_version = env!("CARGO_PKG_VERSION") @@ -11,12 +36,7 @@ fn main() { .next() .expect("Crate version is not valid"); - if pkg_config::Config::new() - .atleast_version(mongoc_version) - .statik(true) - .probe("libmongoc-1.0") - .is_err() - { + if !probe_libmongoc_pkg_config(mongoc_version) && !probe_libmongoc_vcpkg() { let out_dir_var = env::var("OUT_DIR").expect("No out dir"); let out_dir = format!("{}/{}", out_dir_var, mongoc_version); let driver_src_path = format!("mongo-c-driver-{}", mongoc_version); From 561e5d737befb5b7e190ecd84059ff2ff2581341 Mon Sep 17 00:00:00 2001 From: Matrix <113445886@qq.com> Date: Mon, 9 Apr 2018 11:11:21 +0800 Subject: [PATCH 2/3] fix build fail with msvc --- src/bsonc.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/bsonc.rs b/src/bsonc.rs index 45bf2d6..e2034ea 100644 --- a/src/bsonc.rs +++ b/src/bsonc.rs @@ -2,7 +2,7 @@ use std::ffi::CStr; use std::ptr; use std::fmt; use std::slice; -use libc::c_void; +use libc::{c_uint, c_void}; use mongoc::bindings; use bson; @@ -27,12 +27,8 @@ impl Bsonc { let mut buffer = Vec::new(); try!(bson::encode_document(&mut buffer, document)); - let inner = unsafe { - bindings::bson_new_from_data( - buffer[..].as_ptr(), - buffer.len() as u64 - ) - }; + let inner = + unsafe { bindings::bson_new_from_data(buffer[..].as_ptr(), buffer.len() as c_uint) }; // Inner will be null if there was an error converting the data. // We're assuming the bson crate works and therefore assert here. From 1ce395e04d527f11a26d43d18be20ce5298f2feb Mon Sep 17 00:00:00 2001 From: Matrix <113445886@qq.com> Date: Mon, 9 Apr 2018 17:56:18 +0800 Subject: [PATCH 3/3] fix build fail with msvc --- src/bsonc.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/bsonc.rs b/src/bsonc.rs index e2034ea..80e187a 100644 --- a/src/bsonc.rs +++ b/src/bsonc.rs @@ -2,7 +2,7 @@ use std::ffi::CStr; use std::ptr; use std::fmt; use std::slice; -use libc::{c_uint, c_void}; +use libc::c_void; use mongoc::bindings; use bson; @@ -27,8 +27,9 @@ impl Bsonc { let mut buffer = Vec::new(); try!(bson::encode_document(&mut buffer, document)); - let inner = - unsafe { bindings::bson_new_from_data(buffer[..].as_ptr(), buffer.len() as c_uint) }; + let inner = unsafe { + bindings::bson_new_from_data(buffer[..].as_ptr(), (buffer.len() as u32).into()) + }; // Inner will be null if there was an error converting the data. // We're assuming the bson crate works and therefore assert here.