Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable cross compilation #323

Merged
merged 2 commits into from Aug 28, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 11 additions & 7 deletions librocksdb-sys/build.rs
Expand Up @@ -45,6 +45,8 @@ fn bindgen_rocksdb() {
}

fn build_rocksdb() {
let target = env::var("TARGET").unwrap();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't set env variable "TARGET" we would get a panic. Is it really ok here ? What if get a target from cfg!(target_arch) by default, but if "TARGET" variable was set then get the value from it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cargo build passes the "TARGET" environment variable unconditionally.


let mut config = cc::Build::new();
config.include("rocksdb/include/");
config.include("rocksdb/");
Expand Down Expand Up @@ -90,7 +92,7 @@ fn build_rocksdb() {
.filter(|file| *file != "util/build_version.cc")
.collect::<Vec<&'static str>>();

if cfg!(target_arch = "x86_64") {
if target.contains("x86_64") {
// This is needed to enable hardware CRC32C. Technically, SSE 4.2 is
// only available since Intel Nehalem (about 2010) and AMD Bulldozer
// (about 2011).
Expand All @@ -102,24 +104,24 @@ fn build_rocksdb() {
config.flag("-mpclmul");
}

if cfg!(target_os = "macos") {
if target.contains("darwin") {
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") {
if target.contains("linux") {
config.define("OS_LINUX", Some("1"));
config.define("ROCKSDB_PLATFORM_POSIX", Some("1"));
config.define("ROCKSDB_LIB_IO_POSIX", Some("1"));
// COMMON_FLAGS="$COMMON_FLAGS -fno-builtin-memcmp"
}
if cfg!(target_os = "freebsd") {
if target.contains("freebsd") {
config.define("OS_FREEBSD", Some("1"));
config.define("ROCKSDB_PLATFORM_POSIX", Some("1"));
config.define("ROCKSDB_LIB_IO_POSIX", Some("1"));
}

if cfg!(target_os = "windows") {
if target.contains("windows") {
link("rpcrt4", false);
link("shlwapi", false);
config.define("OS_WIN", Some("1"));
Expand All @@ -144,7 +146,7 @@ fn build_rocksdb() {
lib_sources.push("port/win/win_thread.cc");
}

if cfg!(target_env = "msvc") {
if target.contains("msvc") {
config.flag("-EHsc");
} else {
config.flag("-std=c++11");
Expand All @@ -165,13 +167,15 @@ fn build_rocksdb() {
}

fn build_snappy() {
let target = env::var("TARGET").unwrap();

let mut config = cc::Build::new();
config.include("snappy/");
config.include(".");

config.define("NDEBUG", Some("1"));

if cfg!(target_env = "msvc") {
if target.contains("msvc") {
config.flag("-EHsc");
} else {
config.flag("-std=c++11");
Expand Down