|
|
@ -10,85 +10,94 @@ fn main() {
|
|
|
|
.next()
|
|
|
|
.next()
|
|
|
|
.expect("Crate version is not valid");
|
|
|
|
.expect("Crate version is not valid");
|
|
|
|
|
|
|
|
|
|
|
|
pkg_config::Config::new().probe("zlib").expect("Cannot find zlib");
|
|
|
|
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));
|
|
|
|
|
|
|
|
|
|
|
|
if pkg_config::Config::new()
|
|
|
|
let libmongoc_path = out_dir.join("usr/local/lib/libmongoc-static-1.0.a");
|
|
|
|
.atleast_version(mongoc_version)
|
|
|
|
if !libmongoc_path.exists() {
|
|
|
|
.statik(true)
|
|
|
|
// Download and extract driver archive
|
|
|
|
.probe("libmongoc-1.0")
|
|
|
|
let url = format!(
|
|
|
|
.is_err()
|
|
|
|
"https://github.com/mongodb/mongo-c-driver/releases/download/{}/mongo-c-driver-{}.tar.gz",
|
|
|
|
{
|
|
|
|
mongoc_version,
|
|
|
|
let out_dir_var = env::var("OUT_DIR").expect("No out dir");
|
|
|
|
mongoc_version
|
|
|
|
let out_dir = Path::new(&out_dir_var);
|
|
|
|
);
|
|
|
|
let driver_src_path = out_dir.join(format!("mongo-c-driver-{}", 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 libmongoc_path = out_dir.join("usr/local/lib/libmongoc-static-1.0.a");
|
|
|
|
let archive_name = format!("mongo-c-driver-{}.tar.gz", mongoc_version);
|
|
|
|
if !libmongoc_path.exists() {
|
|
|
|
assert!(
|
|
|
|
// Download and extract driver archive
|
|
|
|
Command::new("tar")
|
|
|
|
let url = format!(
|
|
|
|
.current_dir(out_dir)
|
|
|
|
"https://github.com/mongodb/mongo-c-driver/releases/download/{}/mongo-c-driver-{}.tar.gz",
|
|
|
|
.arg("xzf")
|
|
|
|
mongoc_version,
|
|
|
|
.arg(&archive_name)
|
|
|
|
mongoc_version
|
|
|
|
.status()
|
|
|
|
);
|
|
|
|
.expect("Could not run tar")
|
|
|
|
assert!(
|
|
|
|
.success()
|
|
|
|
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);
|
|
|
|
// Set up cmake command
|
|
|
|
assert!(
|
|
|
|
let mut cmake = Command::new("cmake");
|
|
|
|
Command::new("tar")
|
|
|
|
cmake.current_dir(&driver_src_path);
|
|
|
|
.current_dir(out_dir)
|
|
|
|
|
|
|
|
.arg("xzf")
|
|
|
|
|
|
|
|
.arg(&archive_name)
|
|
|
|
|
|
|
|
.status()
|
|
|
|
|
|
|
|
.expect("Could not run tar")
|
|
|
|
|
|
|
|
.success()
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Set up cmake command
|
|
|
|
let pkg = pkg_config::Config::new();
|
|
|
|
let mut cmake = Command::new("cmake");
|
|
|
|
pkg.probe("zlib").expect("Cannot find zlib");
|
|
|
|
cmake.current_dir(&driver_src_path);
|
|
|
|
#[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");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
match pkg.probe("zstd") {
|
|
|
|
|
|
|
|
Ok(_) => {
|
|
|
|
|
|
|
|
cmake.arg("-DENABLE_ZSTD=ON");
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
Err(e) => {
|
|
|
|
|
|
|
|
println!("Zstd not found: {}", e);
|
|
|
|
|
|
|
|
cmake.arg("-DENABLE_ZSTD=OFF");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
cmake.arg("-DENABLE_AUTOMATIC_INIT_AND_CLEANUP=OFF");
|
|
|
|
cmake.arg("-DENABLE_AUTOMATIC_INIT_AND_CLEANUP=OFF");
|
|
|
|
cmake.arg("-DENABLE_SSL=OPENSSL");
|
|
|
|
cmake.arg("-DENABLE_SSL=OPENSSL");
|
|
|
|
cmake.arg("-DENABLE_SASL=OFF");
|
|
|
|
cmake.arg("-DENABLE_SASL=OFF");
|
|
|
|
cmake.arg("-DENABLE_STATIC=ON");
|
|
|
|
cmake.arg("-DENABLE_STATIC=ON");
|
|
|
|
cmake.arg("-DENABLE_BSON=ON");
|
|
|
|
cmake.arg("-DENABLE_BSON=ON");
|
|
|
|
cmake.arg("-DENABLE_ENABLE_EXAMPLES=OFF");
|
|
|
|
cmake.arg("-DENABLE_ENABLE_EXAMPLES=OFF");
|
|
|
|
cmake.arg("-DENABLE_TESTS=OFF");
|
|
|
|
cmake.arg("-DENABLE_TESTS=OFF");
|
|
|
|
cmake.arg("-DENABLE_SHM_COUNTERS=OFF");
|
|
|
|
cmake.arg("-DENABLE_SHM_COUNTERS=OFF");
|
|
|
|
cmake.arg("-DWITH_PIC=ON");
|
|
|
|
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
|
|
|
|
// Run in current dir
|
|
|
|
cmake.arg(".");
|
|
|
|
cmake.arg(".");
|
|
|
|
|
|
|
|
|
|
|
|
// Run cmake command
|
|
|
|
// Run cmake command
|
|
|
|
assert!(cmake.status().expect("Could not run cmake").success());
|
|
|
|
assert!(cmake.status().expect("Could not run cmake").success());
|
|
|
|
|
|
|
|
|
|
|
|
// Set up make install command
|
|
|
|
// Set up make install command
|
|
|
|
let mut make = Command::new("make");
|
|
|
|
let mut make = Command::new("make");
|
|
|
|
make.current_dir(&driver_src_path);
|
|
|
|
make.current_dir(&driver_src_path);
|
|
|
|
make.arg(format!("DESTDIR={}", out_dir.to_string_lossy()));
|
|
|
|
make.arg(format!("DESTDIR={}", out_dir.to_string_lossy()));
|
|
|
|
make.arg("install");
|
|
|
|
make.arg("install");
|
|
|
|
|
|
|
|
|
|
|
|
// Run make command
|
|
|
|
// Run make command
|
|
|
|
assert!(make.status().expect("Could not run make install").success());
|
|
|
|
assert!(make.status().expect("Could not run make install").success());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Output to Cargo
|
|
|
|
// Output to Cargo
|
|
|
|
println!("cargo:rustc-link-search=native={}/usr/local/lib", &out_dir.to_string_lossy());
|
|
|
|
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=bson-static-1.0");
|
|
|
|
println!("cargo:rustc-link-lib=static=mongoc-static-1.0");
|
|
|
|
println!("cargo:rustc-link-lib=static=mongoc-static-1.0");
|
|
|
|
println!("cargo:rustc-link-lib=resolv");
|
|
|
|
println!("cargo:rustc-link-lib=resolv");
|
|
|
|
#[cfg(target_os = "linux")] println!("cargo:rustc-link-lib=icuuc");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|