Skip to content

Commit cd46bd4

Browse files
authored
Rollup merge of rust-lang#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 7ec4c97 + 7180afb commit cd46bd4

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 !clang_tblgen.exists() {
443+
panic!("unable to find {}", clang_tblgen.display());
444+
}
445+
cfg.define("CLANG_TABLEGEN", clang_tblgen);
446+
}
439447
}
440448

441449
if let Some(ref suffix) = builder.config.llvm_version_suffix {
@@ -526,6 +534,8 @@ fn configure_cmake(
526534
cfg.target(&target.triple).host(&builder.config.build.triple);
527535

528536
if target != builder.config.build {
537+
cfg.define("CMAKE_CROSSCOMPILING", "True");
538+
529539
if target.contains("netbsd") {
530540
cfg.define("CMAKE_SYSTEM_NAME", "NetBSD");
531541
} else if target.contains("freebsd") {
@@ -543,6 +553,17 @@ fn configure_cmake(
543553
// Since, the LLVM itself makes rather limited use of version checks in
544554
// CMakeFiles (and then only in tests), and so far no issues have been
545555
// reported, the system version is currently left unset.
556+
557+
if target.contains("darwin") {
558+
// Make sure that CMake does not build universal binaries on macOS.
559+
// Explicitly specifiy the one single target architecture.
560+
if target.starts_with("aarch64") {
561+
// macOS uses a different name for building arm64
562+
cfg.define("CMAKE_OSX_ARCHITECTURES", "arm64");
563+
} else {
564+
cfg.define("CMAKE_OSX_ARCHITECTURES", target.triple.split('-').next().unwrap());
565+
}
566+
}
546567
}
547568

548569
let sanitize_cc = |cc: &Path| {

0 commit comments

Comments
 (0)