Skip to content

Commit 95314f2

Browse files
authored
Rollup merge of rust-lang#74116 - arlosi:aarch64build, r=pietroalbini
Fix cross compilation of LLVM to aarch64 Windows targets When cross-compiling, the LLVM build system recurses to build tools that need to run on the host system. However, since we pass cmake defines to set the compiler and target, LLVM still compiles these tools for the target system, rather than the host. The tools then fail to execute during the LLVM build. This change sets defines for the tools that need to run on the host (llvm-nm, llvm-tablegen, and llvm-config), so that the LLVM build does not attempt to build them, and instead relies on the tools already built. If compiling with clang-cl, adds the `--target` option to specify the target triple. MSVC compilers do not require this, since there is a separate compiler binary for each cross-compilation target. Related issue: rust-lang#72881 Requires LLVM change: rust-lang/llvm-project#67
2 parents 670a8fb + 59f979f commit 95314f2

File tree

3 files changed

+26
-11
lines changed

3 files changed

+26
-11
lines changed

Cargo.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -404,9 +404,9 @@ version = "0.1.0"
404404

405405
[[package]]
406406
name = "cc"
407-
version = "1.0.54"
407+
version = "1.0.57"
408408
source = "registry+https://github.com/rust-lang/crates.io-index"
409-
checksum = "7bbb73db36c1246e9034e307d0fba23f9a2e251faa47ade70c1bd252220c8311"
409+
checksum = "0fde55d2a2bfaa4c9668bbc63f531fbdeee3ffe188f4662511ce2c22b3eedebe"
410410
dependencies = [
411411
"jobserver",
412412
]

src/bootstrap/native.rs

+23-8
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
//! ensure that they're always in place if needed.
1010
1111
use std::env;
12+
use std::env::consts::EXE_EXTENSION;
1213
use std::ffi::OsString;
1314
use std::fs::{self, File};
1415
use std::io;
@@ -252,8 +253,14 @@ impl Step for Llvm {
252253
// FIXME: if the llvm root for the build triple is overridden then we
253254
// should use llvm-tblgen from there, also should verify that it
254255
// actually exists most of the time in normal installs of LLVM.
255-
let host = builder.llvm_out(builder.config.build).join("bin/llvm-tblgen");
256-
cfg.define("CMAKE_CROSSCOMPILING", "True").define("LLVM_TABLEGEN", &host);
256+
let host_bin = builder.llvm_out(builder.config.build).join("bin");
257+
cfg.define("CMAKE_CROSSCOMPILING", "True");
258+
cfg.define("LLVM_TABLEGEN", host_bin.join("llvm-tblgen").with_extension(EXE_EXTENSION));
259+
cfg.define("LLVM_NM", host_bin.join("llvm-nm").with_extension(EXE_EXTENSION));
260+
cfg.define(
261+
"LLVM_CONFIG_PATH",
262+
host_bin.join("llvm-config").with_extension(EXE_EXTENSION),
263+
);
257264

258265
if target.contains("netbsd") {
259266
cfg.define("CMAKE_SYSTEM_NAME", "NetBSD");
@@ -262,8 +269,6 @@ impl Step for Llvm {
262269
} else if target.contains("windows") {
263270
cfg.define("CMAKE_SYSTEM_NAME", "Windows");
264271
}
265-
266-
cfg.define("LLVM_NATIVE_BUILD", builder.llvm_out(builder.config.build).join("build"));
267272
}
268273

269274
if let Some(ref suffix) = builder.config.llvm_version_suffix {
@@ -431,6 +436,9 @@ fn configure_cmake(
431436
cflags.push_str(" -miphoneos-version-min=10.0");
432437
}
433438
}
439+
if builder.config.llvm_clang_cl.is_some() {
440+
cflags.push_str(&format!(" --target={}", target))
441+
}
434442
cfg.define("CMAKE_C_FLAGS", cflags);
435443
let mut cxxflags = builder.cflags(target, GitRepo::Llvm).join(" ");
436444
if builder.config.llvm_static_stdcpp && !target.contains("msvc") && !target.contains("netbsd") {
@@ -439,6 +447,9 @@ fn configure_cmake(
439447
if let Some(ref s) = builder.config.llvm_cxxflags {
440448
cxxflags.push_str(&format!(" {}", s));
441449
}
450+
if builder.config.llvm_clang_cl.is_some() {
451+
cxxflags.push_str(&format!(" --target={}", target))
452+
}
442453
cfg.define("CMAKE_CXX_FLAGS", cxxflags);
443454
if let Some(ar) = builder.ar(target) {
444455
if ar.is_absolute() {
@@ -484,7 +495,7 @@ impl Step for Lld {
484495
run.builder.ensure(Lld { target: run.target });
485496
}
486497

487-
/// Compile LLVM for `target`.
498+
/// Compile LLD for `target`.
488499
fn run(self, builder: &Builder<'_>) -> PathBuf {
489500
if builder.config.dry_run {
490501
return PathBuf::from("lld-out-dir-test-gen");
@@ -521,6 +532,7 @@ impl Step for Lld {
521532
// can't build on a system where your paths require `\` on Windows, but
522533
// there's probably a lot of reasons you can't do that other than this.
523534
let llvm_config_shim = env::current_exe().unwrap().with_file_name("llvm-config-wrapper");
535+
524536
cfg.out_dir(&out_dir)
525537
.profile("Release")
526538
.env("LLVM_CONFIG_REAL", &llvm_config)
@@ -543,7 +555,10 @@ impl Step for Lld {
543555
if target != builder.config.build {
544556
cfg.env("LLVM_CONFIG_SHIM_REPLACE", &builder.config.build)
545557
.env("LLVM_CONFIG_SHIM_REPLACE_WITH", &target)
546-
.define("LLVM_TABLEGEN_EXE", llvm_config.with_file_name("llvm-tblgen"));
558+
.define(
559+
"LLVM_TABLEGEN_EXE",
560+
llvm_config.with_file_name("llvm-tblgen").with_extension(EXE_EXTENSION),
561+
);
547562
}
548563

549564
// Explicitly set C++ standard, because upstream doesn't do so
@@ -595,8 +610,8 @@ impl Step for TestHelpers {
595610
}
596611

597612
// We may have found various cross-compilers a little differently due to our
598-
// extra configuration, so inform gcc of these compilers. Note, though, that
599-
// on MSVC we still need gcc's detection of env vars (ugh).
613+
// extra configuration, so inform cc of these compilers. Note, though, that
614+
// on MSVC we still need cc's detection of env vars (ugh).
600615
if !target.contains("msvc") {
601616
if let Some(ar) = builder.ar(target) {
602617
cfg.archiver(ar);

0 commit comments

Comments
 (0)