about summary refs log tree commit diff
diff options
context:
space:
mode:
authortopjohnwu <topjohnwu@google.com>2022-06-21 01:31:16 -0700
committertopjohnwu <topjohnwu@gmail.com>2022-07-03 23:49:21 -0700
commitce9e71949cb3b788830b119d8fcfae9e20b62fbd (patch)
tree5980afa5b35e703ca98b2e173440198faa2144de
parenta5c6a48aee84215a9200dfa1c4c6ad88f5721f56 (diff)
downloadrust-ce9e71949cb3b788830b119d8fcfae9e20b62fbd.tar.gz
rust-ce9e71949cb3b788830b119d8fcfae9e20b62fbd.zip
Fix cross compiling on macOS
When cross compiling LLVM on an arm64 machine to x86_64, CMake will
produce universal binaries by default, causing link errors. Explicitly
set CMAKE_OSX_ARCHITECTURES to the one single target architecture.
-rw-r--r--src/bootstrap/native.rs14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/bootstrap/native.rs b/src/bootstrap/native.rs
index 8395be40f9b..c6d6c256c28 100644
--- a/src/bootstrap/native.rs
+++ b/src/bootstrap/native.rs
@@ -429,7 +429,6 @@ impl Step for Llvm {
             //        should use llvm-tblgen from there, also should verify that it
             //        actually exists most of the time in normal installs of LLVM.
             let host_bin = builder.llvm_out(builder.config.build).join("bin");
-            cfg.define("CMAKE_CROSSCOMPILING", "True");
             cfg.define("LLVM_TABLEGEN", host_bin.join("llvm-tblgen").with_extension(EXE_EXTENSION));
             cfg.define("LLVM_NM", host_bin.join("llvm-nm").with_extension(EXE_EXTENSION));
             cfg.define(
@@ -547,6 +546,8 @@ fn configure_cmake(
     cfg.target(&target.triple).host(&builder.config.build.triple);
 
     if target != builder.config.build {
+        cfg.define("CMAKE_CROSSCOMPILING", "True");
+
         if target.contains("netbsd") {
             cfg.define("CMAKE_SYSTEM_NAME", "NetBSD");
         } else if target.contains("freebsd") {
@@ -564,6 +565,17 @@ fn configure_cmake(
         // Since, the LLVM itself makes rather limited use of version checks in
         // CMakeFiles (and then only in tests), and so far no issues have been
         // reported, the system version is currently left unset.
+
+        if target.contains("darwin") {
+            // Make sure that CMake does not build universal binaries on macOS.
+            // Explicitly specifiy the one single target architecture.
+            if target.starts_with("aarch64") {
+                // macOS uses a different name for building arm64
+                cfg.define("CMAKE_OSX_ARCHITECTURES", "arm64");
+            } else {
+                cfg.define("CMAKE_OSX_ARCHITECTURES", target.triple.split('-').next().unwrap());
+            }
+        }
     }
 
     let sanitize_cc = |cc: &Path| {