Skip to content

Commit 73443a0

Browse files
committed
Auto merge of #98328 - topjohnwu:fix_cross, r=jyn514
Fix several issues during cross compiling - When cross compiling LLVM on an arm64 macOS 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 so that the executables and libraries will be single architecture. - When cross compiling rustc with `llvm.clang = true`, `CLANG_TABLEGEN` has to be set to the host `clang-tblgen` executable to build clang.
2 parents c4693bc + 600026a commit 73443a0

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/bootstrap/native.rs

+22-1
Original file line numberDiff line numberDiff line change
@@ -429,13 +429,21 @@ 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));
433+
// LLVM_NM is required for cross compiling using MSVC
434434
cfg.define("LLVM_NM", host_bin.join("llvm-nm").with_extension(EXE_EXTENSION));
435435
cfg.define(
436436
"LLVM_CONFIG_PATH",
437437
host_bin.join("llvm-config").with_extension(EXE_EXTENSION),
438438
);
439+
if builder.config.llvm_clang {
440+
let build_bin = builder.llvm_out(builder.config.build).join("build").join("bin");
441+
let clang_tblgen = build_bin.join("clang-tblgen").with_extension(EXE_EXTENSION);
442+
if !builder.config.dry_run && !clang_tblgen.exists() {
443+
panic!("unable to find {}", clang_tblgen.display());
444+
}
445+
cfg.define("CLANG_TABLEGEN", clang_tblgen);
446+
}
439447
}
440448

441449
let llvm_version_suffix = if let Some(ref suffix) = builder.config.llvm_version_suffix {
@@ -545,6 +553,8 @@ fn configure_cmake(
545553
cfg.target(&target.triple).host(&builder.config.build.triple);
546554

547555
if target != builder.config.build {
556+
cfg.define("CMAKE_CROSSCOMPILING", "True");
557+
548558
if target.contains("netbsd") {
549559
cfg.define("CMAKE_SYSTEM_NAME", "NetBSD");
550560
} else if target.contains("freebsd") {
@@ -562,6 +572,17 @@ fn configure_cmake(
562572
// Since, the LLVM itself makes rather limited use of version checks in
563573
// CMakeFiles (and then only in tests), and so far no issues have been
564574
// reported, the system version is currently left unset.
575+
576+
if target.contains("darwin") {
577+
// Make sure that CMake does not build universal binaries on macOS.
578+
// Explicitly specifiy the one single target architecture.
579+
if target.starts_with("aarch64") {
580+
// macOS uses a different name for building arm64
581+
cfg.define("CMAKE_OSX_ARCHITECTURES", "arm64");
582+
} else {
583+
cfg.define("CMAKE_OSX_ARCHITECTURES", target.triple.split('-').next().unwrap());
584+
}
585+
}
565586
}
566587

567588
let sanitize_cc = |cc: &Path| {

0 commit comments

Comments
 (0)