Skip to content

Commit ce9e719

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 a5c6a48 commit ce9e719

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/bootstrap/native.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,6 @@ impl Step for Llvm {
429429
// should use llvm-tblgen from there, also should verify that it
430430
// actually exists most of the time in normal installs of LLVM.
431431
let host_bin = builder.llvm_out(builder.config.build).join("bin");
432-
cfg.define("CMAKE_CROSSCOMPILING", "True");
433432
cfg.define("LLVM_TABLEGEN", host_bin.join("llvm-tblgen").with_extension(EXE_EXTENSION));
434433
cfg.define("LLVM_NM", host_bin.join("llvm-nm").with_extension(EXE_EXTENSION));
435434
cfg.define(
@@ -547,6 +546,8 @@ fn configure_cmake(
547546
cfg.target(&target.triple).host(&builder.config.build.triple);
548547

549548
if target != builder.config.build {
549+
cfg.define("CMAKE_CROSSCOMPILING", "True");
550+
550551
if target.contains("netbsd") {
551552
cfg.define("CMAKE_SYSTEM_NAME", "NetBSD");
552553
} else if target.contains("freebsd") {
@@ -564,6 +565,17 @@ fn configure_cmake(
564565
// Since, the LLVM itself makes rather limited use of version checks in
565566
// CMakeFiles (and then only in tests), and so far no issues have been
566567
// reported, the system version is currently left unset.
568+
569+
if target.contains("darwin") {
570+
// Make sure that CMake does not build universal binaries on macOS.
571+
// Explicitly specifiy the one single target architecture.
572+
if target.starts_with("aarch64") {
573+
// macOS uses a different name for building arm64
574+
cfg.define("CMAKE_OSX_ARCHITECTURES", "arm64");
575+
} else {
576+
cfg.define("CMAKE_OSX_ARCHITECTURES", target.triple.split('-').next().unwrap());
577+
}
578+
}
567579
}
568580

569581
let sanitize_cc = |cc: &Path| {

0 commit comments

Comments
 (0)