find local installed libmongoc first

pull/34/head
Matrix 7 years ago
parent 4c9cdbf8e1
commit a1fd155da3

@ -13,3 +13,6 @@ exclude = ["mongo-c-driver-*"]
[dependencies]
libc = "0.2"
openssl-sys = "0.9"
[build-dependencies]
semver = "0.8"

@ -1,10 +1,36 @@
extern crate semver;
use std::env;
use std::path::Path;
use std::process::Command;
use std::str::FromStr;
use semver::Version;
static VERSION: &'static str = "1.8.0"; // Should be the same major version as in the manifest
fn main() {
let mut local_exist = false;
if let Ok(output) = Command::new("pkg-config")
.arg("--modversion")
.arg("libmongoc-1.0")
.output()
{
if output.status.success() {
if let Ok(ref stdout) = String::from_utf8(output.stdout) {
if let Ok(local_version) = Version::from_str(stdout) {
let except_version = Version::from_str(VERSION).unwrap();
if local_version.major == except_version.major &&
local_version.minor == except_version.minor
{
local_exist = true;
}
}
}
}
}
if !local_exist {
let out_dir_var = env::var("OUT_DIR").expect("No out dir");
let out_dir = format!("{}/{}", out_dir_var, VERSION);
let driver_src_path = format!("mongo-c-driver-{}", VERSION);
@ -17,22 +43,24 @@ fn main() {
VERSION,
VERSION
);
assert!(Command::new("curl").arg("-O") // Save to disk
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",
VERSION
.success()
);
assert!(Command::new("tar").arg("xzf")
let archive_name = format!("mongo-c-driver-{}.tar.gz", VERSION);
assert!(
Command::new("tar")
.arg("xzf")
.arg(&archive_name)
.status()
.expect("Could not run tar")
.success());
.success()
);
// Configure and install
let mut command = Command::new("sh");
@ -60,18 +88,24 @@ fn main() {
}
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());
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()
);
}
// Output to Cargo
@ -79,3 +113,4 @@ fn main() {
println!("cargo:rustc-link-lib=static=bson-1.0");
println!("cargo:rustc-link-lib=static=mongoc-1.0");
}
}

Loading…
Cancel
Save