Skip to content

Library creation fails with Android NDK r23b #636

Closed
@b-spencer

Description

@b-spencer

Problem

Using fresh installations of Rust installed on x86_64-unknown-linux-gnu (Debian 10) via the rustup method, compiling packages for Android with NDK r23b (the current LTS release) does not work.

Steps

  1. curl -sf -L https://static.rust-lang.org/rustup.sh | sh (fresh install for the local user)

  2. rustup target add aarch64-linux-android

  3. Create an empty library crate that depends on ring:

cargo new --lib hello
echo 'ring = "0.16"' >>hello/Cargo.toml
  1. Compile for the host and all is well:
$ cargo build
    Updating crates.io index
   Compiling libc v0.2.107
   Compiling cc v1.0.72
   Compiling once_cell v1.8.0
   Compiling spin v0.5.2
   Compiling untrusted v0.7.1
   Compiling ring v0.16.20
   Compiling hello v0.1.0 (/home/.../hello)
    Finished dev [unoptimized + debuginfo] target(s) in 7.48s
  1. Compile for aarch64-linux-android the simple, documented way and it fails, but that's because of all the reasons in Build and link issues on Linux hosts with newer Android NDKs #459:
$ cargo build --target aarch64-linux-android
   Compiling untrusted v0.7.1
   Compiling spin v0.5.2
   Compiling once_cell v1.8.0
   Compiling libc v0.2.107
   Compiling ring v0.16.20
error: failed to run custom build command for `ring v0.16.20`

Caused by:
  process didn't exit successfully: `/home/.../hello/target/debug/build/ring-b1c7634ecf998ee6/build-script-build` (exit status: 101)
...
  1. Add all the workarounds from Build and link issues on Linux hosts with newer Android NDKs #459 and it still doesn't work:
$ PATH=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/:$PATH \
  CC_aarch64_linux_android=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android24-clang \
  CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android24-clang \
  cargo build --lib --release --target aarch64-linux-android
   Compiling ring v0.16.20
error: failed to run custom build command for `ring v0.16.20`

Caused by:
  process didn't exit successfully: `/home/.../hello/target/release/build/ring-14a8ac965b8995d8/build-script-build` (exit status: 1)
...
  --- stdout
  running: "aarch64-linux-android-ar" "cq" ...
  ...

  --- stderr

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

The newest versions of the Android NDK simply do not ship GNU binutils and thus there is no aarch64-linux-android-ar to use. No amount of changing paths or environment variables is likely to make this work. I suspect that the rust toolchain will need to use llvm-ar and the other LLVM tools instead if it is to work with the current LTS versions of the Android NDK.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions