You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mongo-rust-driver/mongoc-sys/build.rs

95 lines
3.6 KiB
Rust

extern crate pkg_config;
10 years ago
use std::env;
use std::path::Path;
use std::process::Command;
10 years ago
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");
6 years ago
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 = Path::new(&out_dir_var);
let driver_src_path = out_dir.join(format!("mongo-c-driver-{}", mongoc_version));
10 years ago
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()
);
10 years ago
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()
);
10 years ago
// 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=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");
cmake.arg("-DWITH_SNAPPY=OFF");
cmake.arg("-DWITH_ZLIB=ON");
cmake.arg("-DENABLE_EXTRA_ALIGNMENT=OFF");
// 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());
}
// 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");
#[cfg(target_os = "linux")] println!("cargo:rustc-link-lib=icuuc");
}
}