Upgrade mongoc to 1.17

pull/59/head
Thijs Cadier 4 years ago
parent 9c0b0df99c
commit 8e9751271c

1
.gitignore vendored

@ -1,6 +1,5 @@
target target
Cargo.lock Cargo.lock
mongoc-sys/mongo-c-driver*
ssl_env_vars ssl_env_vars
.idea/ .idea/
.DS_Store .DS_Store

@ -14,10 +14,8 @@ services:
depends_on: depends_on:
- mongodb - mongodb
environment: environment:
CARGO_HOME: "/tmp/_cargo"
RUST_TEST_THREADS: "1" RUST_TEST_THREADS: "1"
RUST_BACKTRACE: "full" RUST_BACKTRACE: "full"
LIBCLANG_PATH: "/usr/lib/llvm-7/lib"
SKIP_SSL_CONNECTION_TESTS: "true" SKIP_SSL_CONNECTION_TESTS: "true"
MONGODB_CONNECTION_STRING: "mongodb://mongodb:27017" MONGODB_CONNECTION_STRING: "mongodb://mongodb:27017"
working_dir: /project working_dir: /project

@ -31,28 +31,14 @@ blocks:
commands: commands:
# Create containers but don't start them yet. We first want to copy the caches onto it # Create containers but don't start them yet. We first want to copy the caches onto it
- docker-compose $COMPOSE_OPTIONS up --no-start - docker-compose $COMPOSE_OPTIONS up --no-start
# Copy cargo cache to main test container
- cache restore v3-cargo-$(checksum Cargo.lock),v3-cargo
- "[ -d \"/tmp/_cargo\" ] && docker cp /tmp/_cargo $CONTAINER_NAME:/tmp/_cargo || echo 'No cache to copy'"
# Copy project to main test container # Copy project to main test container
- cache restore v3-project-$(cat PACKAGES_CHECKSUM),v3-project
- docker cp . $CONTAINER_NAME:/project - docker cp . $CONTAINER_NAME:/project
# Then start the containers so we can run the test on it # Then start the containers so we can run the test on it
- docker-compose $COMPOSE_OPTIONS up -d --no-recreate - docker-compose $COMPOSE_OPTIONS up -d --no-recreate
# Install dependencies
- docker-compose $COMPOSE_OPTIONS exec $CONTAINER_NAME apt-get update
- docker-compose $COMPOSE_OPTIONS exec $CONTAINER_NAME apt-get install -y cmake libssl-dev
jobs: jobs:
- name: Test - name: Test
commands: commands:
- docker-compose $COMPOSE_OPTIONS exec $CONTAINER_NAME cargo test - docker-compose $COMPOSE_OPTIONS exec $CONTAINER_NAME cargo test
epilogue:
always:
commands:
# Pull artifacts from containers and cache them
- rm -rf target
- docker cp $CONTAINER_NAME:/project/target target
- cache store v3-project-$(cat PACKAGES_CHECKSUM) target
# Pull cargo dir and cache it
- rm -rf /tmp/_cargo
- docker cp $CONTAINER_NAME:/tmp/_cargo /tmp/_cargo
- cache store v3-cargo-$(checksum Cargo.lock) /tmp/_cargo

@ -25,7 +25,7 @@ serde_derive = "1.0"
[dependencies.mongoc-sys] [dependencies.mongoc-sys]
path = "mongoc-sys" path = "mongoc-sys"
version = "1.8.2-1" version = "1.17.4"
[dev-dependencies] [dev-dependencies]
chrono = "^0.4" chrono = "^0.4"

@ -21,10 +21,11 @@ The driver currently only builds on Unix, tested on Mac Os X and Linux so far. I
If you have any trouble installing the crate (linking openssl can be If you have any trouble installing the crate (linking openssl can be
tricky) please check out the [installation instructions for the C driver](http://mongoc.org/libmongoc/current/installing.html). tricky) please check out the [installation instructions for the C driver](http://mongoc.org/libmongoc/current/installing.html).
To build on Mac install OpenSSL 1.1: To build on Mac install OpenSSL 1.1 and cmake:
``` ```
brew install openssl@1.1 brew install openssl@1.1
brew install cmake
``` ```
Export these env vars the before you make a clean build: Export these env vars the before you make a clean build:

@ -1,6 +1,6 @@
[package] [package]
name = "mongoc-sys" name = "mongoc-sys"
version = "1.8.2-1" version = "1.17.4"
description = "Sys package with installer and bindings for mongoc" description = "Sys package with installer and bindings for mongoc"
authors = ["Thijs Cadier <thijs@appsignal.com>"] authors = ["Thijs Cadier <thijs@appsignal.com>"]
build = "build.rs" build = "build.rs"
@ -8,12 +8,10 @@ repository = "https://github.com/thijsc/mongo-rust-driver"
links = "mongoc" links = "mongoc"
license = "MIT/Apache-2.0" license = "MIT/Apache-2.0"
categories = ["external-ffi-bindings"] categories = ["external-ffi-bindings"]
exclude = ["mongo-c-driver-*"]
[dependencies] [dependencies]
libc = "0.2" libc = "^0.2"
openssl-sys = "0.9" openssl-sys = "^0.9"
[build-dependencies] [build-dependencies]
pkg-config = "0.3" pkg-config = "^0.3"
vcpkg = "0.2.6"

@ -1,13 +1,16 @@
extern crate pkg_config; extern crate pkg_config;
#[cfg(target_env = "msvc")]
extern crate vcpkg;
use std::env; use std::env;
use std::path::Path;
use std::process::Command;
#[cfg(not(target_env = "msvc"))] fn main() {
fn lin(mongoc_version: &str) { let mongoc_version = env!("CARGO_PKG_VERSION")
use std::path::Path; .split('-')
use std::process::Command; .next()
.expect("Crate version is not valid");
pkg_config::Config::new().probe("zlib").expect("Cannot find zlib");
if pkg_config::Config::new() if pkg_config::Config::new()
.atleast_version(mongoc_version) .atleast_version(mongoc_version)
@ -16,10 +19,10 @@ fn lin(mongoc_version: &str) {
.is_err() .is_err()
{ {
let out_dir_var = env::var("OUT_DIR").expect("No out dir"); let out_dir_var = env::var("OUT_DIR").expect("No out dir");
let out_dir = format!("{}/{}", out_dir_var, mongoc_version); let out_dir = Path::new(&out_dir_var);
let driver_src_path = format!("mongo-c-driver-{}", mongoc_version); let driver_src_path = out_dir.join(format!("mongo-c-driver-{}", mongoc_version));
let libmongoc_path = Path::new(&out_dir).join("lib/libmongoc-1.0.a"); let libmongoc_path = out_dir.join("usr/local/lib/libmongoc-static-1.0.a");
if !libmongoc_path.exists() { if !libmongoc_path.exists() {
// Download and extract driver archive // Download and extract driver archive
let url = format!( let url = format!(
@ -29,6 +32,7 @@ fn lin(mongoc_version: &str) {
); );
assert!( assert!(
Command::new("curl").arg("-O") // Save to disk Command::new("curl").arg("-O") // Save to disk
.current_dir(out_dir)
.arg("-L") // Follow redirects .arg("-L") // Follow redirects
.arg(url) .arg(url)
.status() .status()
@ -39,6 +43,7 @@ fn lin(mongoc_version: &str) {
let archive_name = format!("mongo-c-driver-{}.tar.gz", mongoc_version); let archive_name = format!("mongo-c-driver-{}.tar.gz", mongoc_version);
assert!( assert!(
Command::new("tar") Command::new("tar")
.current_dir(out_dir)
.arg("xzf") .arg("xzf")
.arg(&archive_name) .arg(&archive_name)
.status() .status()
@ -46,97 +51,38 @@ fn lin(mongoc_version: &str) {
.success() .success()
); );
// Configure and install // Set up cmake command
let mut command = Command::new("sh"); let mut cmake = Command::new("cmake");
command.arg("configure"); cmake.current_dir(&driver_src_path);
command.arg("--enable-ssl=openssl");
command.arg("--enable-sasl=no"); cmake.arg("-DENABLE_AUTOMATIC_INIT_AND_CLEANUP=OFF");
command.arg("--enable-static=yes"); cmake.arg("-DENABLE_SSL=OPENSSL");
command.arg("--enable-shared=no"); cmake.arg("-DENABLE_SASL=OFF");
command.arg("--enable-shm-counters=no"); cmake.arg("-DENABLE_STATIC=OFF");
command.arg("--with-libbson=bundled"); cmake.arg("-DENABLE_TESTS=OFF");
command.arg("--with-pic=yes"); cmake.arg("-DWITH_PIC=ON");
command.arg("--with-snappy=no"); cmake.arg("-DWITH_SNAPPY=OFF");
command.arg("--with-zlib=no"); cmake.arg("-DWITH_ZLIB=ON");
command.arg(format!("--prefix={}", &out_dir));
command.current_dir(&driver_src_path); // Run in current dir
cmake.arg(".");
// Enable debug symbols if configured for this profile
if env::var("DEBUG") == Ok("true".to_string()) { // Run cmake command
command.arg("--enable-debug-symbols=yes"); assert!(cmake.status().expect("Could not run cmake").success());
}
// Set up make install command
// Use target that Cargo sets let mut make = Command::new("make");
if let Ok(target) = env::var("TARGET") { make.current_dir(&driver_src_path);
command.arg(format!("--build={}", target)); make.arg(format!("DESTDIR={}", out_dir.to_string_lossy()));
} make.arg("install");
assert!(command.status().expect("Could not run configure").success()); // Run make command
assert!( assert!(make.status().expect("Could not run make install").success());
Command::new("make")
.current_dir(&driver_src_path)
.env("CFLAGS", "-DMONGOC_TRACE")
.status()
.expect("Could not run make")
.success()
);
assert!(
Command::new("make")
.arg("install")
.current_dir(&driver_src_path)
.status()
.expect("Could not run make install")
.success()
);
} }
// Output to Cargo // Output to Cargo
println!("cargo:rustc-link-search=native={}/lib", &out_dir); println!("cargo:rustc-link-search=native={}/usr/local/lib", &out_dir.to_string_lossy());
println!("cargo:rustc-link-lib=static=bson-1.0"); println!("cargo:rustc-link-lib=bson-1.0");
println!("cargo:rustc-link-lib=static=mongoc-1.0"); println!("cargo:rustc-link-lib=mongoc-1.0");
}
}
#[cfg(target_env = "msvc")]
fn win(_mongoc_version: &str) {
use vcpkg;
let mongo_lib = "mongoc-1.0";
let bson_lib = "bson-1.0";
if vcpkg::Config::new()
.emit_includes(true)
.probe("mongo-c-driver")
.is_ok()
{
// Output to Cargo
println!("cargo:rustc-link-lib={}", bson_lib);
println!("cargo:rustc-link-lib={}", mongo_lib);
} else {
if let Ok(bson_dir_lib) = env::var("MONGO_LIB") {
if let Ok(mongo_dir_lib) = env::var("BSON_LIB") {
println!("cargo:rustc-link-search=native={}", bson_dir_lib);
println!("cargo:rustc-link-lib=dylib={}", bson_lib);
println!("cargo:rustc-link-search=native={}", mongo_dir_lib);
println!("cargo:rustc-link-lib=dylib={}", mongo_lib);
} else {
panic!("please define BSON_LIB to {}.lib, \n for example set BSON_LIB=C:\\vcpkg\\packages\\libbson_x64-windows\\lib", bson_lib);
}
} else {
panic!("please define MONGO_LIB to {}.lib, \n for example set MONGO_LIB=C:\\vcpkg\\packages\\mongo-c-driver_x64-windows\\lib", mongo_lib);
} }
}
}
fn main() {
let mongoc_version = env!("CARGO_PKG_VERSION")
.split('-')
.next()
.expect("Crate version is not valid");
#[cfg(target_env = "msvc")]
win(mongoc_version);
#[cfg(not(target_env = "msvc"))]
lin(mongoc_version);
} }

@ -254,3 +254,11 @@ pub mod bindings {
pub const MONGOC_ERROR_WRITE_CONCERN_ERROR: ::libc::c_uint = 64; pub const MONGOC_ERROR_WRITE_CONCERN_ERROR: ::libc::c_uint = 64;
pub const MONGOC_ERROR_DUPLICATE_KEY: ::libc::c_uint = 11000; pub const MONGOC_ERROR_DUPLICATE_KEY: ::libc::c_uint = 11000;
} }
#[cfg(test)]
mod tests {
#[test]
fn run() {
// Just a quick test to make seeing if everything links right easy
}
}

@ -10,7 +10,8 @@ use bson;
use super::Result; use super::Result;
pub struct Bsonc { pub struct Bsonc {
inner: *mut bindings::bson_t inner: *mut bindings::bson_t,
destroy_inner_on_drop: bool
} }
impl Bsonc { impl Bsonc {
@ -18,9 +19,14 @@ impl Bsonc {
Bsonc::from_ptr(unsafe { bindings::bson_new() }) Bsonc::from_ptr(unsafe { bindings::bson_new() })
} }
/// Create a bsonc from a raw pointer. Does not run cleanup
/// logic on drop in this case.
pub fn from_ptr(inner: *const bindings::bson_t) -> Bsonc { pub fn from_ptr(inner: *const bindings::bson_t) -> Bsonc {
assert!(!inner.is_null()); assert!(!inner.is_null());
Bsonc { inner: inner as *mut bindings::bson_t } Bsonc {
inner: inner as *mut bindings::bson_t,
destroy_inner_on_drop: false
}
} }
pub fn from_document(document: &bson::Document) -> Result<Bsonc> { pub fn from_document(document: &bson::Document) -> Result<Bsonc> {
@ -39,7 +45,10 @@ impl Bsonc {
// See: http://mongoc.org/libbson/current/bson_new_from_data.html // See: http://mongoc.org/libbson/current/bson_new_from_data.html
assert!(!inner.is_null()); assert!(!inner.is_null());
Ok(Bsonc{ inner: inner }) Ok(Bsonc{
inner: inner,
destroy_inner_on_drop: true
})
} }
/// Decode a bson from the C side to a document /// Decode a bson from the C side to a document
@ -92,8 +101,10 @@ impl fmt::Debug for Bsonc {
impl Drop for Bsonc { impl Drop for Bsonc {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { if self.destroy_inner_on_drop {
bindings::bson_destroy(self.inner); unsafe {
bindings::bson_destroy(self.inner);
}
} }
} }
} }

@ -38,7 +38,6 @@ fn test_aggregate() {
assert_eq!(Ok(5), total.get_i32("total")); assert_eq!(Ok(5), total.get_i32("total"));
} }
#[cfg_attr(target_os = "windows", ignore)]
#[test] #[test]
fn test_command() { fn test_command() {
let uri = Uri::new(helpers::mongodb_test_connection_string()).unwrap(); let uri = Uri::new(helpers::mongodb_test_connection_string()).unwrap();

@ -93,7 +93,6 @@ fn test_tailing_cursor() {
assert_eq!(25, guard.join().expect("Thread failed")); assert_eq!(25, guard.join().expect("Thread failed"));
} }
#[cfg_attr(target_os = "windows", ignore)]
#[test] #[test]
fn test_batch_cursor() { fn test_batch_cursor() {
let uri = Uri::new(helpers::mongodb_test_connection_string()).unwrap(); let uri = Uri::new(helpers::mongodb_test_connection_string()).unwrap();

@ -7,7 +7,6 @@ use bson::doc;
use mongo_driver::client::{ClientPool,Uri}; use mongo_driver::client::{ClientPool,Uri};
#[cfg_attr(target_os = "windows", ignore)]
#[test] #[test]
fn test_command() { fn test_command() {
let uri = Uri::new(helpers::mongodb_test_connection_string()).unwrap(); let uri = Uri::new(helpers::mongodb_test_connection_string()).unwrap();

Loading…
Cancel
Save