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.
93 lines
3.5 KiB
Rust
93 lines
3.5 KiB
Rust
extern crate pkg_config;
|
|
|
|
use std::env;
|
|
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)
|
|
.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));
|
|
|
|
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);
|
|
|
|
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");
|
|
|
|
// 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");
|
|
}
|
|
}
|