Compare commits
33 Commits
Author | SHA1 | Date |
---|---|---|
Thijs Cadier | f69ea92007 | 1 year ago |
Thijs Cadier | 1194acf7ff | 1 year ago |
Thijs Cadier | e7a200e47e | 1 year ago |
Thijs Cadier | 81b452d429 | 1 year ago |
thijsc | d176ca1cf6 | 2 years ago |
Thijs Cadier | 8da4e45e01 | 2 years ago |
thijsc | 74d1f73261 | 2 years ago |
Thijs Cadier | 7fcdeed53c | 4 years ago |
Thijs Cadier | e3bb485807 | 4 years ago |
Thijs Cadier | fa2dd0dbd9 | 4 years ago |
Thijs Cadier | 6b298e17a2 | 4 years ago |
Thijs Cadier | 13ab54f62e | 4 years ago |
Thijs Cadier | f83786cdac | 4 years ago |
Thijs Cadier | d67b74f8c6 | 4 years ago |
Thijs Cadier | a231e250cc | 4 years ago |
Thijs Cadier | f2180f4263 | 4 years ago |
Thijs Cadier | c9af4825ed | 4 years ago |
Thijs Cadier | f581295984 | 4 years ago |
Thijs Cadier | 719a8f52bc | 4 years ago |
Thijs Cadier | 903d387dd5 | 4 years ago |
Thijs Cadier | c24310b49d | 4 years ago |
Thijs Cadier | 219bfb839a | 4 years ago |
Thijs Cadier | 7c09166ebd | 4 years ago |
Thijs Cadier | a38d9bc26e | 4 years ago |
Thijs Cadier | 62930df7fe | 4 years ago |
Thijs Cadier | ce51abf864 | 4 years ago |
Thijs Cadier | 8b32365c05 | 4 years ago |
Thijs Cadier | 7a2baf438b | 4 years ago |
Thijs Cadier | 8e9751271c | 4 years ago |
Thijs Cadier | 9c0b0df99c | 4 years ago |
Thijs Cadier | 25ce6da768 | 4 years ago |
Thijs Cadier | 58cab34895 | 4 years ago |
Thijs Cadier | e5f89793f6 | 4 years ago |
@ -1,6 +1,5 @@
|
||||
target
|
||||
Cargo.lock
|
||||
mongoc-sys/mongo-c-driver*
|
||||
ssl_env_vars
|
||||
.idea/
|
||||
.DS_Store
|
||||
|
@ -0,0 +1,21 @@
|
||||
version: '3.7'
|
||||
|
||||
services:
|
||||
mongodb:
|
||||
image: mongo:latest
|
||||
environment:
|
||||
- MONGO_DATA_DIR=/data/db
|
||||
ports:
|
||||
- "27017:27017"
|
||||
rust:
|
||||
image: rust:latest
|
||||
container_name: "rust"
|
||||
depends_on:
|
||||
- mongodb
|
||||
environment:
|
||||
RUST_TEST_THREADS: "1"
|
||||
RUST_BACKTRACE: "full"
|
||||
SKIP_SSL_CONNECTION_TESTS: "true"
|
||||
MONGODB_CONNECTION_STRING: "mongodb://mongodb:27017"
|
||||
working_dir: /project
|
||||
command: tail -f /dev/null
|
@ -0,0 +1,44 @@
|
||||
version: v1.0
|
||||
name: Mongo Rust Driver tests
|
||||
|
||||
agent:
|
||||
machine:
|
||||
type: e1-standard-8
|
||||
os_image: ubuntu1804
|
||||
|
||||
# Cancel all running and queued workflows before this one
|
||||
auto_cancel:
|
||||
running:
|
||||
# Ignore main AND develop branch as we want it to build all workflows
|
||||
when: "branch != 'main' AND branch != 'develop'"
|
||||
|
||||
global_job_config:
|
||||
env_vars:
|
||||
- name: "CONTAINER_NAME"
|
||||
value: rust
|
||||
- name: "COMPOSE_OPTIONS"
|
||||
value: "-f .semaphore/docker-compose.yml"
|
||||
|
||||
prologue:
|
||||
commands:
|
||||
- checkout
|
||||
|
||||
blocks:
|
||||
- name: Build & Test
|
||||
dependencies: []
|
||||
task:
|
||||
prologue:
|
||||
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 project to main test container
|
||||
- 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 libsasl2-dev libicu-dev
|
||||
jobs:
|
||||
- name: Test
|
||||
commands:
|
||||
- docker-compose $COMPOSE_OPTIONS exec $CONTAINER_NAME cargo test
|
@ -1,9 +0,0 @@
|
||||
language: rust
|
||||
rust:
|
||||
- stable
|
||||
- beta
|
||||
- nightly
|
||||
services:
|
||||
- mongodb
|
||||
env:
|
||||
- SKIP_SSL_CONNECTION_TESTS=true SKIP_EXTENDED_BULK_OPERATION_TESTS=true
|
@ -1,142 +1,103 @@
|
||||
extern crate pkg_config;
|
||||
#[cfg(target_env = "msvc")]
|
||||
extern crate vcpkg;
|
||||
|
||||
use std::env;
|
||||
use std::path::Path;
|
||||
use std::process::Command;
|
||||
|
||||
#[cfg(not(target_env = "msvc"))]
|
||||
fn lin(mongoc_version: &str) {
|
||||
use std::path::Path;
|
||||
use std::process::Command;
|
||||
|
||||
if pkg_config::Config::new()
|
||||
.atleast_version(mongoc_version)
|
||||
.statik(true)
|
||||
.probe("libmongoc-1.0")
|
||||
.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 libmongoc_path = Path::new(&out_dir).join("lib/libmongoc-1.0.a");
|
||||
if !libmongoc_path.exists() {
|
||||
// Download and extract driver archive
|
||||
let url = format!(
|
||||
"https://github.com/mongodb/mongo-c-driver/releases/download/{}/mongo-c-driver-{}.tar.gz",
|
||||
mongoc_version,
|
||||
mongoc_version
|
||||
);
|
||||
assert!(
|
||||
Command::new("curl").arg("-O") // Save to disk
|
||||
.arg("-L") // Follow redirects
|
||||
.arg(url)
|
||||
.status()
|
||||
.expect("Could not run curl")
|
||||
.success()
|
||||
);
|
||||
|
||||
let archive_name = format!("mongo-c-driver-{}.tar.gz", mongoc_version);
|
||||
assert!(
|
||||
Command::new("tar")
|
||||
.arg("xzf")
|
||||
.arg(&archive_name)
|
||||
.status()
|
||||
.expect("Could not run tar")
|
||||
.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));
|
||||
}
|
||||
fn main() {
|
||||
let mongoc_version = env!("CARGO_PKG_VERSION")
|
||||
.split('-')
|
||||
.next()
|
||||
.expect("Crate version is not valid");
|
||||
|
||||
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()
|
||||
);
|
||||
let out_dir_var = env::var("OUT_DIR").expect("No out dir");
|
||||
let out_dir = Path::new(&out_dir_var);
|
||||
let driver_src_path = out_dir.join(format!("mongo-c-driver-{}", mongoc_version));
|
||||
|
||||
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!(
|
||||
"https://github.com/mongodb/mongo-c-driver/releases/download/{}/mongo-c-driver-{}.tar.gz",
|
||||
mongoc_version,
|
||||
mongoc_version
|
||||
);
|
||||
assert!(
|
||||
Command::new("curl").arg("-O") // Save to disk
|
||||
.current_dir(out_dir)
|
||||
.arg("-L") // Follow redirects
|
||||
.arg(url)
|
||||
.status()
|
||||
.expect("Could not run curl")
|
||||
.success()
|
||||
);
|
||||
|
||||
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()
|
||||
.expect("Could not run tar")
|
||||
.success()
|
||||
);
|
||||
|
||||
// Set up cmake command
|
||||
let mut cmake = Command::new("cmake");
|
||||
cmake.current_dir(&driver_src_path);
|
||||
|
||||
let pkg = pkg_config::Config::new();
|
||||
pkg.probe("zlib").expect("Cannot find zlib");
|
||||
#[cfg(target_os = "linux")] pkg.probe("icu-i18n").expect("Cannot find icu");
|
||||
match pkg.probe("snappy") {
|
||||
Ok(_) => {
|
||||
cmake.arg("-DENABLE_SNAPPY=ON");
|
||||
},
|
||||
Err(e) => {
|
||||
println!("Snappy not found: {}", e);
|
||||
cmake.arg("-DENABLE_SNAPPY=OFF");
|
||||
}
|
||||
|
||||
// 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);
|
||||
match pkg.probe("zstd") {
|
||||
Ok(_) => {
|
||||
cmake.arg("-DENABLE_ZSTD=ON");
|
||||
},
|
||||
Err(e) => {
|
||||
println!("Zstd not found: {}", e);
|
||||
cmake.arg("-DENABLE_ZSTD=OFF");
|
||||
}
|
||||
} 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");
|
||||
cmake.arg("-DENABLE_AUTOMATIC_INIT_AND_CLEANUP=OFF");
|
||||
cmake.arg("-DENABLE_SSL=OPENSSL");
|
||||
cmake.arg("-DENABLE_SASL=OFF");
|
||||
cmake.arg("-DENABLE_STATIC=ON");
|
||||
cmake.arg("-DENABLE_BSON=ON");
|
||||
cmake.arg("-DENABLE_ENABLE_EXAMPLES=OFF");
|
||||
cmake.arg("-DENABLE_TESTS=OFF");
|
||||
cmake.arg("-DENABLE_SHM_COUNTERS=OFF");
|
||||
cmake.arg("-DWITH_PIC=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());
|
||||
}
|
||||
|
||||
#[cfg(target_env = "msvc")]
|
||||
win(mongoc_version);
|
||||
#[cfg(not(target_env = "msvc"))]
|
||||
lin(mongoc_version);
|
||||
// Output to Cargo
|
||||
println!("cargo:rustc-link-search=native={}/usr/local/lib", &out_dir.to_string_lossy());
|
||||
println!("cargo:rustc-link-lib=static=bson-static-1.0");
|
||||
println!("cargo:rustc-link-lib=static=mongoc-static-1.0");
|
||||
println!("cargo:rustc-link-lib=resolv");
|
||||
}
|
||||
|
@ -0,0 +1,8 @@
|
||||
use std::env;
|
||||
|
||||
pub fn mongodb_test_connection_string() -> &'static str {
|
||||
match env::var("MONGODB_CONNECTION_STRING") {
|
||||
Ok(value) => Box::leak(value.into_boxed_str()),
|
||||
Err(_) => "mongodb://localhost:27017",
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue