Always print cargo link in sys build

snappy
Thijs Cadier 3 years ago
parent f581295984
commit c9af4825ed

@ -12,81 +12,74 @@ fn main() {
pkg_config::Config::new().probe("zlib").expect("Cannot find zlib"); pkg_config::Config::new().probe("zlib").expect("Cannot find zlib");
if pkg_config::Config::new() let out_dir_var = env::var("OUT_DIR").expect("No out dir");
.atleast_version(mongoc_version) let out_dir = Path::new(&out_dir_var);
.statik(true) let driver_src_path = out_dir.join(format!("mongo-c-driver-{}", mongoc_version));
.probe("libmongoc-static-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"); let libmongoc_path = out_dir.join("usr/local/lib/libmongoc-static-1.0.a");
if !libmongoc_path.exists() { if !libmongoc_path.exists() {
// Download and extract driver archive // Download and extract driver archive
let url = format!( let url = format!(
"https://github.com/mongodb/mongo-c-driver/releases/download/{}/mongo-c-driver-{}.tar.gz", "https://github.com/mongodb/mongo-c-driver/releases/download/{}/mongo-c-driver-{}.tar.gz",
mongoc_version, mongoc_version,
mongoc_version mongoc_version
); );
assert!( assert!(
Command::new("curl").arg("-O") // Save to disk Command::new("curl").arg("-O") // Save to disk
.current_dir(out_dir) .current_dir(out_dir)
.arg("-L") // Follow redirects .arg("-L") // Follow redirects
.arg(url) .arg(url)
.status() .status()
.expect("Could not run curl") .expect("Could not run curl")
.success() .success()
); );
let archive_name = format!("mongo-c-driver-{}.tar.gz", mongoc_version); let archive_name = format!("mongo-c-driver-{}.tar.gz", mongoc_version);
assert!( assert!(
Command::new("tar") Command::new("tar")
.current_dir(out_dir) .current_dir(out_dir)
.arg("xzf") .arg("xzf")
.arg(&archive_name) .arg(&archive_name)
.status() .status()
.expect("Could not run tar") .expect("Could not run tar")
.success() .success()
); );
// Set up cmake command // Set up cmake command
let mut cmake = Command::new("cmake"); let mut cmake = Command::new("cmake");
cmake.current_dir(&driver_src_path); cmake.current_dir(&driver_src_path);
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_SNAPPY=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"); #[cfg(target_os = "linux")] println!("cargo:rustc-link-lib=icuuc");
}
} }

Loading…
Cancel
Save