Skip to content

Commit 4c440af

Browse files
authored
Merge pull request #1183 from bjorn3/full_aarch64_support
AArch64 support on Linux
2 parents ae98d5a + 3dc9ec2 commit 4c440af

File tree

6 files changed

+54
-25
lines changed

6 files changed

+54
-25
lines changed

.github/workflows/main.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ jobs:
1919
- os: ubuntu-latest
2020
env:
2121
TARGET_TRIPLE: x86_64-pc-windows-gnu
22+
- os: ubuntu-latest
23+
env:
24+
TARGET_TRIPLE: aarch64-unknown-linux-gnu
2225

2326
steps:
2427
- uses: actions/checkout@v2
@@ -49,12 +52,20 @@ jobs:
4952
sudo apt-get install -y gcc-mingw-w64-x86-64 wine-stable
5053
rustup target add x86_64-pc-windows-gnu
5154
55+
- name: Install AArch64 toolchain and qemu
56+
if: matrix.os == 'ubuntu-latest' && matrix.env.TARGET_TRIPLE == 'aarch64-unknown-linux-gnu'
57+
run: |
58+
sudo apt-get install -y gcc-aarch64-linux-gnu qemu-user
59+
5260
- name: Prepare dependencies
5361
run: |
5462
git config --global user.email "[email protected]"
5563
git config --global user.name "User"
5664
./y.rs prepare
5765
66+
- name: Build
67+
run: ./y.rs build --sysroot none
68+
5869
- name: Test
5970
env:
6071
TARGET_TRIPLE: ${{ matrix.env.TARGET_TRIPLE }}

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"rust-analyzer.diagnostics.disabled": ["unresolved-extern-crate", "unresolved-macro-call"],
44
"rust-analyzer.assist.importGranularity": "module",
55
"rust-analyzer.assist.importEnforceGranularity": true,
6-
"rust-analyzer.assist.importPrefix": "by_crate",
6+
"rust-analyzer.assist.importPrefix": "crate",
77
"rust-analyzer.cargo.runBuildScripts": true,
88
"rust-analyzer.linkedProjects": [
99
"./Cargo.toml",

Cargo.lock

Lines changed: 15 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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",

example/mini_core_hello_world.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ fn main() {
292292
#[cfg(not(any(jit, windows)))]
293293
test_tls();
294294

295-
#[cfg(all(not(jit), target_os = "linux"))]
295+
#[cfg(all(not(jit), target_arch = "x86_64", target_os = "linux"))]
296296
unsafe {
297297
global_asm_test();
298298
}
@@ -303,12 +303,12 @@ fn main() {
303303
assert_eq!(*REF1, *REF2);
304304
}
305305

306-
#[cfg(all(not(jit), target_os = "linux"))]
306+
#[cfg(all(not(jit), target_arch = "x86_64", target_os = "linux"))]
307307
extern "C" {
308308
fn global_asm_test();
309309
}
310310

311-
#[cfg(all(not(jit), target_os = "linux"))]
311+
#[cfg(all(not(jit), target_arch = "x86_64", target_os = "linux"))]
312312
global_asm! {
313313
"
314314
.global global_asm_test

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)