Search code examples
rustoperating-systemarm64toolchain

How can I add `aarch64-none-elf` to my Rust toolchain?


While beginning my work on CS140e today I've completed phase 3 of the project (writing C code to speak directly to GPIO pins on a Raspberry Pi 3 which would simply blink an LED) but on phase 4, once I attempt to compile my solution in Rust, rustc seems to not be able to find the aarch64-none-elf target:

➜  phase4 git:(master) ✗ make
+ Building target/aarch64-none-elf/release/libblinky.a [xargo --release]
WARNING: the sysroot can't be built for the Stable channel. Switch to nightly.
warning: `panic` setting is ignored for `test` profile
   Compiling rlibc v1.0.0
error[E0463]: can't find crate for `core`
  |
  = note: the `aarch64-none-elf` target may not be installed

error: aborting due to previous error

For more information about this error, try `rustc --explain E0463`.
error: Could not compile `rlibc`.

To learn more, run the command again with --verbose.
Makefile:35: recipe for target 'target/aarch64-none-elf/release/libblinky.a' failed
make: *** [target/aarch64-none-elf/release/libblinky.a] Error 101

and, indeed, rustc --print target-list doesn't include aarch64-none-elf:

➜  phase4 git:(master) ✗ rustc --print target-list
aarch64-linux-android
aarch64-unknown-cloudabi
aarch64-unknown-freebsd
aarch64-unknown-fuchsia
aarch64-unknown-linux-gnu
aarch64-unknown-linux-musl
aarch64-unknown-openbsd
        ...

Though I have installed the toolchain:

➜  phase4 git:(master) ✗ whereis aarch64-none-elf-gcc
aarch64-none-elf-gcc: /usr/local/bin/aarch64-none-elf/bin/aarch64-none-elf-gcc

Also, I have a custom target file named aarch64-none-elf.json with these contents (presumably passed to xargo when building):

{
  "abi-blacklist": [
    "stdcall",
    "fastcall",
    "vectorcall",
    "thiscall",
    "win64",
    "sysv64"
  ],
  "arch": "aarch64",
  "data-layout": "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128",
  "executables": true,
  "linker": "aarch64-none-elf-ld",
  "linker-flavor": "ld",
  "linker-is-gnu": true,
  "llvm-target": "aarch64-unknown-none",
  "no-compiler-rt": true,
  "features": "+a53,+strict-align",
  "max-atomic-width": 128,
  "os": "none",
  "panic": "abort",
  "panic-strategy": "abort",
  "position-independent-executables": true,
  "target-c-int-width": "32",
  "target-endian": "little",
  "target-pointer-width": "64",
  "disable-redzone": true
}

Solution

  • Turns out all I needed to do was run rustup default nightly and use the nightly version of rustc, as mentioned in the warning and I'm able to get past that error. If anyone want's to explain why this is, that'd be nice.

    ➜  phase4 git:(master) ✗ rustc --version
    rustc 1.30.0-nightly (33b923fd4 2018-08-18)