diff options
author | Nathan Froyd <froydnj@gmail.com> | 2017-05-17 10:09:00 -0400 |
---|---|---|
committer | Nathan Froyd <froydnj@gmail.com> | 2017-05-17 11:13:10 -0400 |
commit | 0371a62172803002610fa746a646a9518956c0d4 (patch) | |
tree | 99d205da2b2f6655ae7d4d59eee4894e033a7e9d /components/style/build_gecko.rs | |
parent | 96a03d93b66970b20bf21bef6a3fa53510066eff (diff) | |
download | servo-0371a62172803002610fa746a646a9518956c0d4.tar.gz servo-0371a62172803002610fa746a646a9518956c0d4.zip |
fix general cross compilation
Use the CARGO_CFG_* environment variables for everything instead of
`cfg!`.
Fixes #16879.
Diffstat (limited to 'components/style/build_gecko.rs')
-rw-r--r-- | components/style/build_gecko.rs | 39 |
1 files changed, 22 insertions, 17 deletions
diff --git a/components/style/build_gecko.rs b/components/style/build_gecko.rs index 4a603f0ede2..fa08db83622 100644 --- a/components/style/build_gecko.rs +++ b/components/style/build_gecko.rs @@ -148,40 +148,46 @@ mod bindings { if build_type == BuildType::Debug { builder = builder.clang_arg("-DDEBUG=1").clang_arg("-DJS_DEBUG=1"); } - if cfg!(target_family = "unix") { + // cfg!(...) will check the attributes of the Rust target this file + // is being compiled for. We want the attributes of the target that + // the clang we're going to invoke is being compiled for, which isn't + // necessarily the same thing. Cargo provides the (yet-to-be-documented) + // CARGO_CFG_* environment variables for this purpose. Those variables + // should be used in preference to cfg! checks below. + let target_family = env::var("CARGO_CFG_TARGET_FAMILY").unwrap(); + let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap(); + let target_pointer_width = env::var("CARGO_CFG_TARGET_POINTER_WIDTH").unwrap(); + let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap(); + let target_env = env::var("CARGO_CFG_TARGET_ENV").unwrap(); + + if target_family == "unix" { builder = builder.clang_arg("-DOS_POSIX=1"); } - if cfg!(target_os = "linux") { + if target_os == "linux" { builder = builder.clang_arg("-DOS_LINUX=1"); - // cfg!(target_arch) will tell us the architecture that this .rs - // file is being compiled for. We want the architecture that - // the clang we're going to invoking is compiling for, which - // isn't necessarily the same thing. Cargo provides the - // (undocumented) CARGO_CFG_TARGET_ARCH for this purpose - let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap(); if target_arch == "x86" { builder = builder.clang_arg("-m32"); } else if target_arch == "x86_64" { builder = builder.clang_arg("-m64"); } - } else if cfg!(target_os = "solaris") { + } else if target_os == "solaris" { builder = builder.clang_arg("-DOS_SOLARIS=1"); - } else if cfg!(target_os = "dragonfly") { + } else if target_os == "dragonfly" { builder = builder.clang_arg("-DOS_BSD=1").clang_arg("-DOS_DRAGONFLY=1"); - } else if cfg!(target_os = "freebsd") { + } else if target_os == "freebsd" { builder = builder.clang_arg("-DOS_BSD=1").clang_arg("-DOS_FREEBSD=1"); - } else if cfg!(target_os = "netbsd") { + } else if target_os == "netbsd" { builder = builder.clang_arg("-DOS_BSD=1").clang_arg("-DOS_NETBSD=1"); - } else if cfg!(target_os = "openbsd") { + } else if target_os == "openbsd" { builder = builder.clang_arg("-DOS_BSD=1").clang_arg("-DOS_OPENBSD=1"); - } else if cfg!(target_os = "macos") { + } else if target_os == "macos" { builder = builder.clang_arg("-DOS_MACOSX=1") .clang_arg("-stdlib=libc++") // To disable the fixup bindgen applies which adds search // paths from clang command line in order to avoid potential // conflict with -stdlib=libc++. .clang_arg("--target=x86_64-apple-darwin"); - } else if cfg!(target_env = "msvc") { + } else if target_env == "msvc" { builder = builder.clang_arg("-DOS_WIN=1").clang_arg("-DWIN32=1") // For compatibility with MSVC 2015 .clang_arg("-fms-compatibility-version=19") @@ -193,8 +199,7 @@ mod bindings { // thus not enabled by default with a MSVC-compatibile build) // to exclude hidden symbols from the generated file. .clang_arg("-DHAVE_VISIBILITY_HIDDEN_ATTRIBUTE=1"); - let pointer_width = env::var("CARGO_CFG_TARGET_POINTER_WIDTH").unwrap(); - if pointer_width == "32" { + if target_pointer_width == "32" { builder = builder.clang_arg("--target=i686-pc-win32"); } else { builder = builder.clang_arg("--target=x86_64-pc-win32"); |