fix linux cross-compilation, take 2

We were using `cfg!(target_arch)` checks, which are not correct, as
those check the architecture of the compiled build script, not the clang
target.
This commit is contained in:
Nathan Froyd 2017-05-15 17:08:24 -04:00
parent abb2985ffe
commit 536154475c

View file

@ -153,14 +153,16 @@ mod bindings {
} }
if cfg!(target_os = "linux") { if cfg!(target_os = "linux") {
builder = builder.clang_arg("-DOS_LINUX=1"); builder = builder.clang_arg("-DOS_LINUX=1");
// We may be cross-compiling with a clang that defaults to // cfg!(target_arch) will tell us the architecture that this .rs
// a different architecture, so we should explicitly specify // file is being compiled for. We want the architecture that
// the bitness being used here. Specifying --target instead // the clang we're going to invoking is compiling for, which
// leads to difficulties with LLVM search paths. // isn't necessarily the same thing. Cargo provides the
if cfg!(target_arch = "x86") { // (undocumented) CARGO_CFG_TARGET_ARCH for this purpose
builder = builder.clang_arg("-m32") let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap();
} else if cfg!(target_arch = "x86_64") { if target_arch == "x86" {
builder = builder.clang_arg("-m64") builder = builder.clang_arg("-m32");
} else if target_arch == "x86_64" {
builder = builder.clang_arg("-m64");
} }
} else if cfg!(target_os = "solaris") { } else if cfg!(target_os = "solaris") {
builder = builder.clang_arg("-DOS_SOLARIS=1"); builder = builder.clang_arg("-DOS_SOLARIS=1");