Skip to content

Commit cda8111

Browse files
committed
Fix compilation for AArch64
1 parent 1bd9a13 commit cda8111

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

build_system/build_sysroot.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,16 @@ pub(crate) fn build_sysroot(
115115
}
116116
}
117117
SysrootKind::Clif => {
118-
build_clif_sysroot_for_triple(channel, target_dir, target_triple);
118+
build_clif_sysroot_for_triple(channel, target_dir, host_triple, None);
119119

120120
if host_triple != target_triple {
121-
build_clif_sysroot_for_triple(channel, target_dir, host_triple);
121+
// When cross-compiling it is often necessary to manually pick the right linker
122+
let linker = if target_triple == "aarch64-unknown-linux-gnu" {
123+
Some("aarch64-linux-gnu-gcc")
124+
} else {
125+
None
126+
};
127+
build_clif_sysroot_for_triple(channel, target_dir, target_triple, linker);
122128
}
123129

124130
// Copy std for the host to the lib dir. This is necessary for the jit mode to find
@@ -133,7 +139,12 @@ pub(crate) fn build_sysroot(
133139
}
134140
}
135141

136-
fn build_clif_sysroot_for_triple(channel: &str, target_dir: &Path, triple: &str) {
142+
fn build_clif_sysroot_for_triple(
143+
channel: &str,
144+
target_dir: &Path,
145+
triple: &str,
146+
linker: Option<&str>,
147+
) {
137148
let build_dir = Path::new("build_sysroot").join("target").join(triple).join(channel);
138149

139150
let keep_sysroot =
@@ -155,6 +166,10 @@ fn build_clif_sysroot_for_triple(channel: &str, target_dir: &Path, triple: &str)
155166
build_cmd.arg("--release");
156167
rustflags.push_str(" -Zmir-opt-level=3");
157168
}
169+
if let Some(linker) = linker {
170+
use std::fmt::Write;
171+
write!(rustflags, " -Clinker={}", linker).unwrap();
172+
}
158173
build_cmd.env("RUSTFLAGS", rustflags);
159174
build_cmd.env(
160175
"RUSTC",

src/lib.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -287,10 +287,12 @@ fn build_isa(sess: &Session, backend_config: &BackendConfig) -> Box<dyn isa::Tar
287287
}
288288
None => {
289289
let mut builder =
290-
cranelift_codegen::isa::lookup_variant(target_triple, variant).unwrap();
291-
// Don't use "haswell" as the default, as it implies `has_lzcnt`.
292-
// macOS CI is still at Ivy Bridge EP, so `lzcnt` is interpreted as `bsr`.
293-
builder.enable("nehalem").unwrap();
290+
cranelift_codegen::isa::lookup_variant(target_triple.clone(), variant).unwrap();
291+
if target_triple.architecture == target_lexicon::Architecture::X86_64 {
292+
// Don't use "haswell" as the default, as it implies `has_lzcnt`.
293+
// macOS CI is still at Ivy Bridge EP, so `lzcnt` is interpreted as `bsr`.
294+
builder.enable("nehalem").unwrap();
295+
}
294296
builder
295297
}
296298
};

0 commit comments

Comments
 (0)