Skip to content

Commit 483a299

Browse files
authored
Rollup 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 910b60f + 91c7dd0 commit 483a299

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/bootstrap/native.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,13 +416,19 @@ 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));
421-
cfg.define("LLVM_NM", host_bin.join("llvm-nm").with_extension(EXE_EXTENSION));
422420
cfg.define(
423421
"LLVM_CONFIG_PATH",
424422
host_bin.join("llvm-config").with_extension(EXE_EXTENSION),
425423
);
424+
if builder.config.llvm_clang {
425+
let build_bin = builder.llvm_out(builder.config.build).join("build").join("bin");
426+
let clang_tblgen = build_bin.join("clang-tblgen").with_extension(EXE_EXTENSION);
427+
if !clang_tblgen.exists() {
428+
panic!("unable to find {}", clang_tblgen.display());
429+
}
430+
cfg.define("CLANG_TABLEGEN", clang_tblgen);
431+
}
426432
}
427433

428434
if let Some(ref suffix) = builder.config.llvm_version_suffix {
@@ -513,6 +519,8 @@ fn configure_cmake(
513519
cfg.target(&target.triple).host(&builder.config.build.triple);
514520

515521
if target != builder.config.build {
522+
cfg.define("CMAKE_CROSSCOMPILING", "True");
523+
516524
if target.contains("netbsd") {
517525
cfg.define("CMAKE_SYSTEM_NAME", "NetBSD");
518526
} else if target.contains("freebsd") {
@@ -530,6 +538,17 @@ fn configure_cmake(
530538
// Since, the LLVM itself makes rather limited use of version checks in
531539
// CMakeFiles (and then only in tests), and so far no issues have been
532540
// reported, the system version is currently left unset.
541+
542+
if target.contains("darwin") {
543+
// Make sure that CMake does not build universal binaries on macOS.
544+
// Explicitly specifiy the one single target architecture.
545+
if target.starts_with("aarch64") {
546+
// macOS uses a different name for building arm64
547+
cfg.define("CMAKE_OSX_ARCHITECTURES", "arm64");
548+
} else {
549+
cfg.define("CMAKE_OSX_ARCHITECTURES", target.triple.split('-').next().unwrap());
550+
}
551+
}
533552
}
534553

535554
let sanitize_cc = |cc: &Path| {

0 commit comments

Comments
 (0)