Build on x64-linux fails from not finding aarch64-linux-android-clang

I'm trying to add support for Android to a rust library. I'm building this target on an x64 linux machine (in Github Actions).

The build log shows that rustup target add aarch64-linux-android was in fact called:

info: downloading component 'rust-std' for 'aarch64-linux-android'

But later in my build, when building ring v0.17.7, I get this failure:

error: failed to run custom build command for `ring v0.17.7`

Caused by:
  process didn't exit successfully: `/home/runner/work/Nerdbank.Cryptocurrencies/Nerdbank.Cryptocurrencies/src/nerdbank-zcash-rust/target/release/build/ring-57035c3892a12a66/build-script-build` (exit status: 1)
  --- stdout
  cargo:rerun-if-env-changed=RING_PREGENERATE_ASM
  cargo:rustc-env=RING_CORE_PREFIX=ring_core_0_17_7_
  OPT_LEVEL = Some("3")
  TARGET = Some("aarch64-linux-android")
  HOST = Some("x86_64-unknown-linux-gnu")
  cargo:rerun-if-env-changed=CC_aarch64-linux-android
  CC_aarch64-linux-android = None
  cargo:rerun-if-env-changed=CC_aarch64_linux_android
  CC_aarch64_linux_android = None
  cargo:rerun-if-env-changed=TARGET_CC
  TARGET_CC = None
  cargo:rerun-if-env-changed=CC
  CC = None
  cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some("false")
  cargo:rerun-if-env-changed=CFLAGS_aarch64-linux-android
  CFLAGS_aarch64-linux-android = None
  cargo:rerun-if-env-changed=CFLAGS_aarch64_linux_android
  CFLAGS_aarch64_linux_android = None
  cargo:rerun-if-env-changed=TARGET_CFLAGS
  TARGET_CFLAGS = None
  cargo:rerun-if-env-changed=CFLAGS
  CFLAGS = None
  running: "aarch64-linux-android-clang" "-O3" "-DANDROID" "-ffunction-sections" "-fdata-sections" "-fPIC" "-I" "include" "-I" "/home/runner/work/Nerdbank.Cryptocurrencies/Nerdbank.Cryptocurrencies/src/nerdbank-zcash-rust/target/aarch64-linux-android/release/build/ring-9f13b3838d4b47e7/out" "-Wall" "-Wextra" "-fvisibility=hidden" "-std=c1x" "-pedantic" "-Wall" "-Wextra" "-Wbad-function-cast" "-Wcast-align" "-Wcast-qual" "-Wconversion" "-Wenum-compare" "-Wfloat-equal" "-Wformat=2" "-Winline" "-Winvalid-pch" "-Wmissing-field-initializers" "-Wmissing-include-dirs" "-Wnested-externs" "-Wredundant-decls" "-Wshadow" "-Wsign-compare" "-Wsign-conversion" "-Wstrict-prototypes" "-Wundef" "-Wuninitialized" "-Wwrite-strings" "-g3" "-DNDEBUG" "-o" "/home/runner/work/Nerdbank.Cryptocurrencies/Nerdbank.Cryptocurrencies/src/nerdbank-zcash-rust/target/aarch64-linux-android/release/build/ring-9f13b3838d4b47e7/out/crypto/curve25519/curve25519.o" "-c" "crypto/curve25519/curve25519.c"

  --- stderr


  error occurred: Failed to find tool. Is `aarch64-linux-android-clang` installed?

Why would the build tools not be present after running rustup to add the target?

Since this is on Github Actions, I also tried adding a couple actions to install the Android SDK:

    - name: Set up JDK 17
      uses: actions/setup-java@v3
      with:
        java-version: 17
        distribution: temurin
      if: matrix.os == 'ubuntu-20.04'
    - name: ⚙️ Install Android SDK
      uses: android-actions/setup-android@v3
      with:
        cmdline-tools-version: 10406996
      if: matrix.os == 'ubuntu-20.04'

But the error remains.

Any ideas?

The Rust compiler depends on a C toolchain to provide the linker and any required system libraries. This is not distributed by the Rust project.

The C toolchain for Android is in the Android NDK (not the SDK).

1 Like

Thanks. That's helpful.

Do you (or anyone else) have a suggestion as to what Github Action can install the NDK as needed by rust? I tried this, but it didn't work:

    - uses: nttld/setup-ndk@v1
      with:
        ndk-version: r25c