fork of https://github.com/rust-rocksdb/rust-rocksdb for nextgraph
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
124 lines
3.5 KiB
124 lines
3.5 KiB
8 years ago
|
extern crate gcc;
|
||
|
|
||
|
fn link(name: &str, bundled: bool) {
|
||
|
use std::env::var;
|
||
|
let target = var("TARGET").unwrap();
|
||
|
let target: Vec<_> = target.split('-').collect();
|
||
|
if target.get(2) == Some(&"windows") {
|
||
|
println!("cargo:rustc-link-lib=dylib={}", name);
|
||
|
if bundled && target.get(3) == Some(&"gnu") {
|
||
|
let dir = var("CARGO_MANIFEST_DIR").unwrap();
|
||
|
println!("cargo:rustc-link-search=native={}/{}", dir, target[0]);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
fn build_rocksdb() {
|
||
8 years ago
|
println!("cargo:rerun-if-changed=build.rs");
|
||
|
println!("cargo:rerun-if-changed=rocksdb/");
|
||
|
|
||
8 years ago
|
let mut config = gcc::Config::new();
|
||
|
config.include("rocksdb/include/");
|
||
|
config.include("rocksdb/");
|
||
|
config.include("rocksdb/third-party/gtest-1.7.0/fused-src/");
|
||
|
config.include("snappy/");
|
||
|
config.include(".");
|
||
8 years ago
|
|
||
8 years ago
|
config.define("NDEBUG", Some("1"));
|
||
|
config.define("SNAPPY", Some("1"));
|
||
8 years ago
|
|
||
8 years ago
|
let mut lib_sources = include_str!("rocksdb_lib_sources.txt")
|
||
|
.split(" ")
|
||
|
.collect::<Vec<&'static str>>();
|
||
8 years ago
|
|
||
8 years ago
|
// We have a pregenerated a version of build_version.cc in the local directory
|
||
8 years ago
|
lib_sources = lib_sources.iter()
|
||
|
.cloned()
|
||
|
.filter(|file| *file != "util/build_version.cc")
|
||
8 years ago
|
.collect::<Vec<&'static str>>();
|
||
|
|
||
|
if cfg!(target_os = "macos") {
|
||
|
config.define("OS_MACOSX", Some("1"));
|
||
|
config.define("ROCKSDB_PLATFORM_POSIX", Some("1"));
|
||
|
config.define("ROCKSDB_LIB_IO_POSIX", Some("1"));
|
||
|
|
||
|
}
|
||
|
if cfg!(target_os = "linux") {
|
||
|
config.define("OS_LINUX", Some("1"));
|
||
|
config.define("ROCKSDB_PLATFORM_POSIX", Some("1"));
|
||
|
config.define("ROCKSDB_LIB_IO_POSIX", Some("1"));
|
||
8 years ago
|
// COMMON_FLAGS="$COMMON_FLAGS -fno-builtin-memcmp"
|
||
8 years ago
|
}
|
||
|
if cfg!(target_os = "freebsd") {
|
||
|
config.define("OS_FREEBSD", Some("1"));
|
||
|
config.define("ROCKSDB_PLATFORM_POSIX", Some("1"));
|
||
|
config.define("ROCKSDB_LIB_IO_POSIX", Some("1"));
|
||
|
}
|
||
8 years ago
|
|
||
8 years ago
|
if cfg!(windows) {
|
||
|
link("rpcrt4", false);
|
||
|
config.define("OS_WIN", Some("1"));
|
||
8 years ago
|
|
||
|
// Remove POSIX-specific sources
|
||
8 years ago
|
lib_sources = lib_sources.iter()
|
||
|
.cloned()
|
||
|
.filter(|file| {
|
||
8 years ago
|
match *file {
|
||
|
"port/port_posix.cc" |
|
||
|
"util/env_posix.cc" |
|
||
|
"util/io_posix.cc" => false,
|
||
8 years ago
|
_ => true,
|
||
8 years ago
|
}
|
||
|
})
|
||
|
.collect::<Vec<&'static str>>();
|
||
|
|
||
|
// Add Windows-specific sources
|
||
8 years ago
|
lib_sources.push("port/win/port_win.cc");
|
||
|
lib_sources.push("port/win/env_win.cc");
|
||
|
lib_sources.push("port/win/env_default.cc");
|
||
|
lib_sources.push("port/win/win_logger.cc");
|
||
|
lib_sources.push("port/win/io_win.cc");
|
||
|
}
|
||
|
|
||
|
if cfg!(target_env = "msvc") {
|
||
|
config.flag("-EHsc");
|
||
|
} else {
|
||
|
config.flag("-std=c++11");
|
||
|
}
|
||
8 years ago
|
|
||
|
for file in lib_sources {
|
||
8 years ago
|
let file = "rocksdb/".to_string() + file;
|
||
8 years ago
|
config.file(&file);
|
||
|
}
|
||
|
|
||
8 years ago
|
config.file("build_version.cc");
|
||
8 years ago
|
|
||
8 years ago
|
config.cpp(true);
|
||
|
config.compile("librocksdb.a");
|
||
8 years ago
|
}
|
||
|
|
||
|
fn build_snappy() {
|
||
8 years ago
|
let mut config = gcc::Config::new();
|
||
|
config.include("snappy/");
|
||
|
config.include(".");
|
||
|
|
||
|
config.define("NDEBUG", Some("1"));
|
||
|
|
||
|
if cfg!(target_env = "msvc") {
|
||
|
config.flag("-EHsc");
|
||
|
} else {
|
||
|
config.flag("-std=c++11");
|
||
|
}
|
||
|
|
||
|
config.file("snappy/snappy.cc");
|
||
|
config.file("snappy/snappy-sinksource.cc");
|
||
|
config.file("snappy/snappy-c.cc");
|
||
|
config.cpp(true);
|
||
|
config.compile("libsnappy.a");
|
||
8 years ago
|
}
|
||
|
|
||
|
fn main() {
|
||
8 years ago
|
build_rocksdb();
|
||
|
build_snappy();
|
||
8 years ago
|
}
|