Merge pull request #59 from appsignal/mongoc_1_17

Upgrade to libmongoc 1.17
static
Thijs Cadier 4 years ago committed by GitHub
commit 8b32365c05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

1
.gitignore vendored

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

@ -2,22 +2,19 @@ version: '3.7'
services:
mongodb:
image: mongo:3.6
image: mongo:latest
environment:
- MONGO_DATA_DIR=/data/db
ports:
- "27017:27017"
command: mongod --smallfiles
rust:
image: rust:latest
container_name: "rust"
depends_on:
- mongodb
environment:
CARGO_HOME: "/tmp/_cargo"
RUST_TEST_THREADS: "1"
RUST_BACKTRACE: "full"
LIBCLANG_PATH: "/usr/lib/llvm-7/lib"
SKIP_SSL_CONNECTION_TESTS: "true"
MONGODB_CONNECTION_STRING: "mongodb://mongodb:27017"
working_dir: /project

@ -31,28 +31,14 @@ blocks:
commands:
# Create containers but don't start them yet. We first want to copy the caches onto it
- 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
- cache restore v3-project-$(cat PACKAGES_CHECKSUM),v3-project
- docker cp . $CONTAINER_NAME:/project
# Then start the containers so we can run the test on it
- 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:
- name: Test
commands:
- 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]
path = "mongoc-sys"
version = "1.8.2-1"
version = "1.17.4"
[dev-dependencies]
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
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 cmake
```
Export these env vars the before you make a clean build:

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

@ -1,14 +1,17 @@
extern crate pkg_config;
#[cfg(target_env = "msvc")]
extern crate vcpkg;
use std::env;
#[cfg(not(target_env = "msvc"))]
fn lin(mongoc_version: &str) {
use std::path::Path;
use std::process::Command;
fn main() {
let mongoc_version = env!("CARGO_PKG_VERSION")
.split('-')
.next()
.expect("Crate version is not valid");
pkg_config::Config::new().probe("zlib").expect("Cannot find zlib");
if pkg_config::Config::new()
.atleast_version(mongoc_version)
.statik(true)
@ -16,10 +19,10 @@ fn lin(mongoc_version: &str) {
.is_err()
{
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);
let out_dir = Path::new(&out_dir_var);
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() {
// Download and extract driver archive
let url = format!(
@ -29,6 +32,7 @@ fn lin(mongoc_version: &str) {
);
assert!(
Command::new("curl").arg("-O") // Save to disk
.current_dir(out_dir)
.arg("-L") // Follow redirects
.arg(url)
.status()
@ -39,6 +43,7 @@ fn lin(mongoc_version: &str) {
let archive_name = format!("mongo-c-driver-{}.tar.gz", mongoc_version);
assert!(
Command::new("tar")
.current_dir(out_dir)
.arg("xzf")
.arg(&archive_name)
.status()
@ -46,97 +51,38 @@ fn lin(mongoc_version: &str) {
.success()
);
// Configure and install
let mut command = Command::new("sh");
command.arg("configure");
command.arg("--enable-ssl=openssl");
command.arg("--enable-sasl=no");
command.arg("--enable-static=yes");
command.arg("--enable-shared=no");
command.arg("--enable-shm-counters=no");
command.arg("--with-libbson=bundled");
command.arg("--with-pic=yes");
command.arg("--with-snappy=no");
command.arg("--with-zlib=no");
command.arg(format!("--prefix={}", &out_dir));
command.current_dir(&driver_src_path);
// Enable debug symbols if configured for this profile
if env::var("DEBUG") == Ok("true".to_string()) {
command.arg("--enable-debug-symbols=yes");
}
// Use target that Cargo sets
if let Ok(target) = env::var("TARGET") {
command.arg(format!("--build={}", target));
// Set up cmake command
let mut cmake = Command::new("cmake");
cmake.current_dir(&driver_src_path);
cmake.arg("-DENABLE_AUTOMATIC_INIT_AND_CLEANUP=OFF");
cmake.arg("-DENABLE_SSL=OPENSSL");
cmake.arg("-DENABLE_SASL=OFF");
cmake.arg("-DENABLE_STATIC=OFF");
cmake.arg("-DENABLE_TESTS=OFF");
cmake.arg("-DWITH_PIC=ON");
cmake.arg("-DWITH_SNAPPY=OFF");
cmake.arg("-DWITH_ZLIB=ON");
// Run in current dir
cmake.arg(".");
// Run cmake command
assert!(cmake.status().expect("Could not run cmake").success());
// Set up make install command
let mut make = Command::new("make");
make.current_dir(&driver_src_path);
make.arg(format!("DESTDIR={}", out_dir.to_string_lossy()));
make.arg("install");
// Run make command
assert!(make.status().expect("Could not run make install").success());
}
assert!(command.status().expect("Could not run configure").success());
assert!(
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
println!("cargo:rustc-link-search=native={}/lib", &out_dir);
println!("cargo:rustc-link-lib=static=bson-1.0");
println!("cargo:rustc-link-lib=static=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);
println!("cargo:rustc-link-search=native={}/usr/local/lib", &out_dir.to_string_lossy());
println!("cargo:rustc-link-lib=bson-1.0");
println!("cargo:rustc-link-lib=mongoc-1.0");
}
}
}
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_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;
pub struct Bsonc {
inner: *mut bindings::bson_t
inner: *mut bindings::bson_t,
destroy_inner_on_drop: bool
}
impl Bsonc {
@ -18,9 +19,14 @@ impl Bsonc {
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 {
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> {
@ -39,7 +45,10 @@ impl Bsonc {
// See: http://mongoc.org/libbson/current/bson_new_from_data.html
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
@ -92,11 +101,13 @@ impl fmt::Debug for Bsonc {
impl Drop for Bsonc {
fn drop(&mut self) {
if self.destroy_inner_on_drop {
unsafe {
bindings::bson_destroy(self.inner);
}
}
}
}
#[cfg(test)]
mod tests {

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

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

Loading…
Cancel
Save