bbqsrc / cargo-ndk

Compile Rust projects against the Android NDK without hassle
Apache License 2.0
712 stars 64 forks source link

Build failure on for rocksdb dependency on `Ubuntu 22.04` (amd64) machine while cross-compiling for `aarch64-linux-android` #125

Closed timmyjose closed 10 months ago

timmyjose commented 10 months ago

Here is the error message:

Caused by:

  process didn't exit successfully: `/home/expo/workingdir/build/target/release/build/librocksdb-sys-15a888c3efcb2fca/build-script-build` (exit status: 101)

  --- stderr

  /usr/include/stdint.h:26:10: fatal error: 'bits/libc-header-start.h' file not found

  thread 'main' panicked at 'unable to generate rocksdb bindings: ClangDiagnostic("/usr/include/stdint.h:26:10: fatal error: 'bits/libc-header-start.h' file not found\n")', /home/expo/.cargo/registry/src/github.com-1ecc6299db9ec823/librocksdb-sys-0.11.0+8.1.1/build.rs:40:10

  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

For context: I'm building a React Native app which uses a Rust crate (my team is the author, unreleased). This crate uses rocksdb as a dependency.

Cross compiling via:

 cargo ndk --target aarch64-linux-android --platform 21 -- build --release

I bave set ANDROID_NDK_HOME in the build environment:

ANDROID_NDK_HOME directory exists: /home/expo/Android/Sdk/ndk/26.1.10909125

Note that this works on my dev machine (macOS Silicon) with no issues.

bbqsrc commented 10 months ago

If I try to build for aarch64 on my macOS aarch64 system, it does seem to work, but building with 32-bit ARM dies in more exciting ways.

I would recommend running with -vv at the end and dumping the logs. That way you can rebuild the environment and try to run cargo directly with the environment that cargo ndk is setting.

Maybe try adding --bindgen to the command and see if that helps? That feature was added a long time ago and I'm not sure if it's still relevant.

timmyjose commented 10 months ago

@bbqsrc I'll try running the job with -vv and see.I'm also on aarhch64 macOS, and it works without any issues! I suppose I could also spin up an Ubuntu VM and try locally.

Hopefully the logs will give a clue or two. Thanks for the swift response! 🙏

timmyjose commented 10 months ago

@bbqsrc I'll try running the job with -vv and see.I'm also on aarhch64 macOS, and it works without any issues! I suppose I could also spin up an Ubuntu VM and try locally.

Hopefully the logs will give a clue or two. Thanks for the swift response! 🙏

With -vv, I get the following details:

+ cargo ndk --target aarch64-linux-android --platform 21 -- -vv build --release

    Detected NDK v26.1.10909125 (/home/expo/Android/Sdk/ndk/26.1.10909125) [ANDROID_NDK_HOME]

   Exporting CARGO_NDK_CMAKE_TOOLCHAIN_PATH="/home/expo/Android/Sdk/ndk/26.1.10909125/build/cmake/android.toolchain.cmake"

     Setting Android SDK platform level to 21

    Building targets (arm64-v8a)

    Building arm64-v8a (aarch64-linux-android)

   Exporting CARGO_NDK_ANDROID_TARGET="arm64-v8a"

   Exporting CC_aarch64-linux-android="/home/expo/Android/Sdk/ndk/26.1.10909125/toolchains/llvm/prebuilt/linux-x86_64/bin/clang"

   Exporting CFLAGS_aarch64-linux-android="--target=aarch64-linux-android21"

   Exporting CXX_aarch64-linux-android="/home/expo/Android/Sdk/ndk/26.1.10909125/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++"

   Exporting CXXFLAGS_aarch64-linux-android="--target=aarch64-linux-android21"

   Exporting AR_aarch64-linux-android="/home/expo/Android/Sdk/ndk/26.1.10909125/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar"

   Exporting RANLIB_aarch64-linux-android="/home/expo/Android/Sdk/ndk/26.1.10909125/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ranlib"

   Exporting CARGO_TARGET_AARCH64_LINUX_ANDROID_AR="/home/expo/Android/Sdk/ndk/26.1.10909125/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar"

   Exporting CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER="/home/expo/.cargo/bin/cargo-ndk"

   Exporting CARGO_NDK_SYSROOT_PATH="/home/expo/Android/Sdk/ndk/26.1.10909125/toolchains/llvm/prebuilt/linux-x86_64/sysroot"

   Exporting CARGO_NDK_SYSROOT_LIBS_PATH="/home/expo/Android/Sdk/ndk/26.1.10909125/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android"

and the rocksdb compilation part:

   Compiling librocksdb-sys v0.11.0+8.1.1

     Running `CARGO=/home/expo/.rustup/toolchains/nightly-2022-12-10-x86_64-unknown-linux-gnu/bin/cargo CARGO_CRATE_NAME=build_script_build CARGO_MANIFEST_DIR=/home/expo/.cargo/registry/src/github.com-1ecc6299db9ec823/librocksdb-sys-0.11.0+8.1.1 CARGO_PKG_AUTHORS='Karl Hobley <karlhobley10@gmail.com>:Arkadiy Paronyan <arkadiy@ethcore.io>' CARGO_PKG_DESCRIPTION='Native bindings to librocksdb' CARGO_PKG_HOMEPAGE='' CARGO_PKG_LICENSE=MIT/Apache-2.0/BSD-3-Clause CARGO_PKG_LICENSE_FILE='' CARGO_PKG_NAME=librocksdb-sys CARGO_PKG_REPOSITORY='https://github.com/rust-rocksdb/rust-rocksdb' CARGO_PKG_RUST_VERSION=1.60 CARGO_PKG_VERSION=0.11.0+8.1.1 CARGO_PKG_VERSION_MAJOR=0 CARGO_PKG_VERSION_MINOR=11 CARGO_PKG_VERSION_PATCH=0 CARGO_PKG_VERSION_PRE='' LD_LIBRARY_PATH='/home/expo/workingdir/build/target/release/deps:/home/expo/.rustup/toolchains/nightly-2022-12-10-x86_64-unknown-linux-gnu/lib:/home/expo/.rustup/toolchains/nightly-2022-12-10-x86_64-unknown-linux-gnu/lib' rustc --crate-name build_script_build --edition=2018 /home/expo/.cargo/registry/src/github.com-1ecc6299db9ec823/librocksdb-sys-0.11.0+8.1.1/build.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debug-assertions=off --cfg 'feature="bzip2"' --cfg 'feature="bzip2-sys"' --cfg 'feature="default"' --cfg 'feature="libz-sys"' --cfg 'feature="lz4"' --cfg 'feature="lz4-sys"' --cfg 'feature="snappy"' --cfg 'feature="static"' --cfg 'feature="zlib"' --cfg 'feature="zstd"' --cfg 'feature="zstd-sys"' -C metadata=15a888c3efcb2fca -C extra-filename=-15a888c3efcb2fca --out-dir /home/expo/workingdir/build/target/release/build/librocksdb-sys-15a888c3efcb2fca -L dependency=/home/expo/workingdir/build/target/release/deps --extern bindgen=/home/expo/workingdir/build/target/release/deps/libbindgen-9e8fc4bc66280808.rlib --extern cc=/home/expo/workingdir/build/target/release/deps/libcc-8f616a01bfaf8a58.rlib --extern glob=/home/expo/workingdir/build/target/release/deps/libglob-2836ed3c36f62b96.rlib --cap-lints warn`
timmyjose commented 10 months ago

Building it like so worked (was an issue with sysroot, and your --bindgen suggestion was very apropos!):

 SYSROOT_PATH="$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android"
    BINDGEN_EXTRA_CLANG_ARGS="--sysroot ${SYSROOT_PATH}" cargo ndk --bindgen --target aarch64-linux-android --platform 21 -- build --release

Re: https://github.com/rust-rocksdb/rust-rocksdb/issues/598#issuecomment-1891528916

Closing this issue now. Thank you for your help!