Skip to content

Commit 8fb6c54

Browse files
committed
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.
1 parent d017d59 commit 8fb6c54

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/bootstrap/native.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,6 @@ impl Step for Llvm {
416416
// should use llvm-tblgen from there, also should verify that it
417417
// actually exists most of the time in normal installs of LLVM.
418418
let host_bin = builder.llvm_out(builder.config.build).join("bin");
419-
cfg.define("CMAKE_CROSSCOMPILING", "True");
420419
cfg.define("LLVM_TABLEGEN", host_bin.join("llvm-tblgen").with_extension(EXE_EXTENSION));
421420
cfg.define("LLVM_NM", host_bin.join("llvm-nm").with_extension(EXE_EXTENSION));
422421
cfg.define(
@@ -513,6 +512,8 @@ fn configure_cmake(
513512
cfg.target(&target.triple).host(&builder.config.build.triple);
514513

515514
if target != builder.config.build {
515+
cfg.define("CMAKE_CROSSCOMPILING", "True");
516+
516517
if target.contains("netbsd") {
517518
cfg.define("CMAKE_SYSTEM_NAME", "NetBSD");
518519
} else if target.contains("freebsd") {
@@ -530,6 +531,17 @@ fn configure_cmake(
530531
// Since, the LLVM itself makes rather limited use of version checks in
531532
// CMakeFiles (and then only in tests), and so far no issues have been
532533
// reported, the system version is currently left unset.
534+
535+
if target.contains("darwin") {
536+
// Make sure that CMake does not build universal binaries on macOS.
537+
// Explicitly specifiy the one single target architecture.
538+
if target.starts_with("aarch64") {
539+
// macOS uses a different name for building arm64
540+
cfg.define("CMAKE_OSX_ARCHITECTURES", "arm64");
541+
} else {
542+
cfg.define("CMAKE_OSX_ARCHITECTURES", target.triple.split('-').next().unwrap());
543+
}
544+
}
533545
}
534546

535547
let sanitize_cc = |cc: &Path| {

0 commit comments

Comments
 (0)