-
-
Save anonymous/1ae9b2100ccd75c3efbb6e4d0c3b6fbd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate make_cmd; | |
use ::make_cmd::make; | |
use ::std::env; | |
use ::std::fs::File; | |
use ::std::io::{BufRead, BufReader, Write, stderr}; | |
use ::std::path::Path; | |
use ::std::process::{exit}; | |
fn main() { | |
let mut stderr = stderr(); | |
let out_dir = env::var("OUT_DIR").unwrap(); | |
let num_jobs = env::var("NUM_JOBS"); | |
let source_path = Path::new("native/rocksdb/"); | |
println!("cargo:rerun-if-changed=build.rs"); | |
println!("cargo:rerun-if-changed={}", source_path.to_str().unwrap()); | |
let mut cmd = make(); | |
cmd.current_dir(source_path) | |
.arg("EXTRA_CFLAGS=-fPIC") | |
.arg("EXTRA_CXXFLAGS=-fPIC") | |
.arg("DISABLE_JEMALLOC=1") | |
.arg(format!("INSTALL_PATH={}", out_dir)); | |
if let Ok(jobs) = num_jobs { | |
cmd.arg(format!("-j{}", jobs)); | |
} | |
cmd.arg("install-static"); | |
match cmd.output() { | |
Ok(out) => if !out.status.success() { | |
let _ = writeln!(&mut stderr, "build failed:\nstdout:\n{}\nstderr:\n{}", String::from_utf8(out.stdout).unwrap(), String::from_utf8(out.stderr).unwrap()); | |
exit(70); | |
}, | |
Err(e) => { | |
let _ = writeln!(&mut stderr, "command execution failed: {:?}", e); | |
exit(70); | |
} | |
} | |
let make_config_path = source_path.join("make_config.mk"); | |
let config = match File::open(&make_config_path) { | |
Ok(c) => c, | |
Err(err) => { | |
let _ = writeln!(&mut stderr, "failed to open configuration file `{}`: {}", make_config_path.to_str().unwrap(), err); | |
exit(78); | |
} | |
}; | |
let config = BufReader::new(config); | |
let mut libs = Vec::new(); | |
for line in config.lines() { | |
let line = line.unwrap(); | |
let mut parts = line.split('='); | |
let key = parts.next().unwrap(); | |
let value = parts.next().unwrap(); | |
match key { | |
"PLATFORM_LDFLAGS" => { | |
let flags = value.split_whitespace(); | |
libs.extend(flags.filter_map(|n| { | |
const PREFIX: &'static str = "-l"; | |
if n.starts_with(PREFIX) { | |
let lib_cur_name = &n[PREFIX.len() ..]; | |
if lib_cur_name == "jemalloc" { | |
return None; | |
} | |
Some(lib_cur_name.to_owned()) | |
} else { | |
None | |
} | |
})); | |
}, | |
_ => {}, | |
} | |
} | |
println!("cargo:rustc-link-search=native={}/lib", out_dir); | |
println!("cargo:rustc-link-lib=static=rocksdb"); | |
for lib_cur in libs { | |
println!("cargo:rustc-link-lib={}", lib_cur); | |
} | |
println!("cargo:rustc-link-lib=c++"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment