aws / aws-lc-rs

aws-lc-rs is a cryptographic library using AWS-LC for its cryptographic operations. The library strives to be API-compatible with the popular Rust library named ring.
Other
320 stars 49 forks source link

Android build fails #420

Closed surban closed 6 months ago

surban commented 6 months ago

Problem:

Build for Android using cargo ndk fails.

This is the build output:

    Building armeabi-v7a (armv7-linux-androideabi)
   Compiling aws-lc-sys v0.16.0
The following warnings were emitted during compilation:

warning: aws-lc-sys@0.16.0: Generating bindings - internal bindgen. Platform: armv7-linux-androideabi

error: failed to run custom build command for `aws-lc-sys v0.16.0`

Caused by:
  process didn't exit successfully: `/workspaces/.../debug/build/aws-lc-sys-1435ea6682d6bb76/build-script-main` (exit status: 101)
  --- stdout
  cargo:rerun-if-env-changed=AWS_LC_SYS_NO_PREFIX
  cargo:rerun-if-env-changed=AWS_LC_SYS_INTERNAL_BINDGEN
  cargo:rerun-if-env-changed=AWS_LC_SYS_EXTERNAL_BINDGEN
  cargo:rerun-if-env-changed=AWS_LC_SYS_NO_ASM
  cargo:rerun-if-env-changed=AWS_LC_SYS_CMAKE_BUILDER
  cargo:rerun-if-env-changed=AWS_LC_SYS_STATIC
  cargo:warning=Generating bindings - internal bindgen. Platform: armv7-linux-androideabi
  cargo:rerun-if-env-changed=AWS_LC_SYS_INCLUDES

  --- stderr
  /usr/include/stdint.h:26:10: fatal error: 'bits/libc-header-start.h' file not found
  thread 'main' panicked at /home/rs/.cargo/registry/src/index.crates.io-6f17d22bba15001f/aws-lc-sys-0.16.0/builder/bindgen.rs:104:10:
  Unable to generate bindings.: ClangDiagnostic("/usr/include/stdint.h:26:10: fatal error: 'bits/libc-header-start.h' file not found\n")
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
note: If the build failed due to a missing target, you can run this command:
note: 
note:     rustup target install armv7-linux-androideabi

Relevant details

AWS-LC-SYS for Rust versions or commit: 0.16.0

System information: for linux, below info can be collected by running uname -srvmp

justsmth commented 6 months ago

I'm having trouble reproducing the same error that you're getting. My build is also failing, but it seems to be progressing further than the one you reported.

Your error looks like the message we get when certain clang/llvm libraries are not installed on the host. Verify that you have libclang1 installed. Our User Guide has some instructions for it here, there's also some guidance in bindgen's User Guide (which might be out-dated now?).

Another option would be to install the bindgen-cli and set the AWS_LC_SYS_EXTERNAL_BINDGEN=1 environment variable to force our build to use that instead of our internal bindings generation.

Let me know if either of these options work for you.


Note: We do verify our build in CI for a few android-related targets (arm-linux-androideabi, armv7-linux-androideabi, and aarch64-linux-android) but we build using cross-rs.

justsmth commented 6 months ago

Ok, I was able to get the build succeed on my Ubuntu 22.04 (x86-64) host:

I installed Ubuntu's android-sdk package and downloaded the r26d NDK. I exported the following two environment variables:

export ANDROID_NDK_ROOT=/home/justsmth/android-ndk/android-ndk-r26d
export ANDROID_SDK_ROOT=/usr/lib/android-sdk

From the aws-lc-rs/aws-lc-rs subdirectory, I ran the build command:

❯ cargo ndk --target x86_64-linux-android build
    Building x86_64 (x86_64-linux-android)
   Compiling libc v0.2.154
   Compiling fs_extra v1.3.0
   Compiling dunce v1.0.4
   Compiling paste v1.0.14
   Compiling aws-lc-rs v1.7.1 (/home/justsmth/repos/aws-lc-rs/aws-lc-rs)
   Compiling mirai-annotations v1.12.0
   Compiling untrusted v0.7.1
   Compiling zeroize v1.7.0
   Compiling jobserver v0.1.26
   Compiling cc v1.0.94
   Compiling cmake v0.1.50
   Compiling aws-lc-sys v0.16.0 (/home/justsmth/repos/aws-lc-rs/aws-lc-sys)
warning: aws-lc-sys@0.16.0: Generating bindings - external bindgen. Platform: x86_64-linux-android
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 19.76s

(This was using the "external" bindgen-cli.)