From 76087b9aec1e73bccb06e0288e3e019a592ac2ea Mon Sep 17 00:00:00 2001 From: Steve Myers Date: Mon, 14 Jun 2021 22:38:29 -0700 Subject: [PATCH] Add kotlin/aar android device tests --- build.sh | 46 ++++++++++++++++++++++++++++++++++++++++++---- test.sh | 14 ++++++++++++++ 2 files changed, 56 insertions(+), 4 deletions(-) create mode 100755 test.sh diff --git a/build.sh b/build.sh index 6e501db..60f3bef 100755 --- a/build.sh +++ b/build.sh @@ -1,3 +1,6 @@ +#!/usr/bin/env bash +set -eo pipefail -o xtrace + # rust cargo build cargo test --features c-headers -- generate_headers @@ -5,10 +8,45 @@ cargo test --features c-headers -- generate_headers # cc export LD_LIBRARY_PATH=`pwd`/target/debug cc cc/bdk_ffi_test.c -o cc/bdk_ffi_test -L target/debug -l bdk_ffi -l pthread -l dl -l m -valgrind --leak-check=full cc/bdk_ffi_test -#cc/bdk_ffi_test -# bdk-kotlin +# bdk-kotlin jar mkdir -p bdk-kotlin/jar/libs/x86_64_linux cp target/debug/libbdk_ffi.so bdk-kotlin/jar/libs/x86_64_linux -(cd bdk-kotlin && gradle test) + +(cd bdk-kotlin && gradle :jar:build) + +# rust android + +# If ANDROID_NDK_HOME is not set then set it to github actions default +[ -z "$ANDROID_NDK_HOME" ] && export ANDROID_NDK_HOME=$ANDROID_HOME/ndk-bundle + +# Update this line accordingly if you are not building *from* darwin-x86_64 or linux-x86_64 +export PATH=$PATH:$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/`uname | tr '[:upper:]' '[:lower:]'`-x86_64/bin + +# Required for 'ring' dependency to cross-compile to Android platform, must be at least 21 +export CFLAGS="-D__ANDROID_API__=21" + +# IMPORTANT: make sure every target is not a substring of a different one. We check for them with grep later on +BUILD_TARGETS="${BUILD_TARGETS:-aarch64,armv7,x86_64,i686}" + +mkdir -p bdk-kotlin/aar/src/main/jniLibs/ bdk-kotlin/aar/src/main/jniLibs/arm64-v8a bdk-kotlin/aar/src/main/jniLibs/x86_64 bdk-kotlin/aar/src/main/jniLibs/armeabi-v7a bdk-kotlin/aar/src/main/jniLibs/x86 + +if echo $BUILD_TARGETS | grep "aarch64"; then + CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER="aarch64-linux-android21-clang" CC="aarch64-linux-android21-clang" cargo build --target=aarch64-linux-android + cp target/aarch64-linux-android/debug/libbdk_ffi.so bdk-kotlin/aar/src/main/jniLibs/arm64-v8a +fi +if echo $BUILD_TARGETS | grep "x86_64"; then + CARGO_TARGET_X86_64_LINUX_ANDROID_LINKER="x86_64-linux-android21-clang" CC="x86_64-linux-android21-clang" cargo build --target=x86_64-linux-android + cp target/x86_64-linux-android/debug/libbdk_ffi.so bdk-kotlin/aar/src/main/jniLibs/x86_64 +fi +if echo $BUILD_TARGETS | grep "armv7"; then + CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_LINKER="armv7a-linux-androideabi21-clang" CC="armv7a-linux-androideabi21-clang" cargo build --target=armv7-linux-androideabi + cp target/armv7-linux-androideabi/debug/libbdk_ffi.so bdk-kotlin/aar/src/main/jniLibs/armeabi-v7a +fi +if echo $BUILD_TARGETS | grep "i686"; then + CARGO_TARGET_I686_LINUX_ANDROID_LINKER="i686-linux-android21-clang" CC="i686-linux-android21-clang" cargo build --target=i686-linux-android + cp target/i686-linux-android/debug/libbdk_ffi.so bdk-kotlin/aar/src/main/jniLibs/x86 +fi + +# bdk-kotlin aar +(cd bdk-kotlin && gradle :aar:build) diff --git a/test.sh b/test.sh new file mode 100755 index 0000000..da24835 --- /dev/null +++ b/test.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash +set -eo pipefail -o xtrace + +# rust +cargo test --features c-headers -- generate_headers + +# cc +export LD_LIBRARY_PATH=`pwd`/target/debug +valgrind --leak-check=full cc/bdk_ffi_test +#cc/bdk_ffi_test + +# bdk-kotlin +(cd bdk-kotlin && gradle test) +(cd bdk-kotlin && gradle :aar:connectedDebugAndroidTest)