Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 64-bit Android ABIs & allow manual ABI selection #3

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ Build secp256k1.
``` bash
# Android
$ ./tools/build_android.sh
# Alternatively you can specify the ABI to build:
$ ARCHS=arm64-v8a ./tools/build_android.sh
# all, armeabi-v7a, arm64-v8a, x86 or x86_64 are supported

# iOS
$ PLATFORM_NAME=iphoneos CONFIGURATION=debug ARCHS=arm64 ./tools/build_ios.sh
Expand Down
9 changes: 8 additions & 1 deletion contrib/bitcoin-core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,14 @@ add_library(${PROJECT_NAME} STATIC
if (NOT ${USE_EXTERNAL_SECP256K1})
if (ANDROID)
add_library(libsecp256k1 STATIC IMPORTED)
set_target_properties(libsecp256k1 PROPERTIES IMPORTED_LOCATION ${PROJECT_SOURCE_DIR}/src/secp256k1/build/android/${ANDROID_ABI}/lib/libsecp256k1.a)

# Ensure we use the lib folder for 32-bit and lib64 folder for 64-bit
if (${CMAKE_ANDROID_ARCH} MATCHES "^(arm|mips|x86)$")
set_target_properties(libsecp256k1 PROPERTIES IMPORTED_LOCATION ${PROJECT_SOURCE_DIR}/src/secp256k1/build/android/${ANDROID_ABI}/lib/libsecp256k1.a)
else()
set_target_properties(libsecp256k1 PROPERTIES IMPORTED_LOCATION ${PROJECT_SOURCE_DIR}/src/secp256k1/build/android/${ANDROID_ABI}/lib64/libsecp256k1.a)
endif()

set_target_properties(libsecp256k1 PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${PROJECT_SOURCE_DIR}/src/secp256k1/include)
elseif(IOS)
add_library(libsecp256k1 STATIC IMPORTED)
Expand Down
36 changes: 30 additions & 6 deletions tools/build_android.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
#!/bin/bash

set -e

if [ -z "$ANDROID_NDK" ]; then
echo "export the ANDROID_NDK environment variable"
exit 1
fi

# Allow the caller to specify which build to run
abiToBuild="all"
if [ -n "$ARCHS" ]; then
abiRegex="^(all|armeabi-v7a|arm64-v8a|x86|x86_64)$"
[[ $ARCHS =~ $abiRegex ]]

if [[ $? == 0 ]]; then
abiToBuild="$ARCHS"
echo "manually selected ABI: $abiToBuild"
else
echo "invalid ARCHS environment variable, the following are accepted: all, armeabi-v7a, arm64-v8a, x86 or x86_64"
exit 1
fi
fi

# Ensure all commands after this point exit upon erroring
set -e

# Get the location of the android NDK build tools to build with
asm=""
if [ "$(uname)" == "Darwin" ]; then
Expand Down Expand Up @@ -66,10 +82,18 @@ build()
make install
}

build armeabi-v7a armv7a-linux-androideabi
build arm64-v8a aarch64-linux-android
build x86 i686-linux-android
build x86-64 x86_64-linux-android
if [[ $abiToBuild == "all" ]] || [[ $abiToBuild == "armeabi-v7a" ]]; then
build armeabi-v7a armv7a-linux-androideabi
fi
if [[ $abiToBuild == "all" ]] || [[ $abiToBuild == "arm64-v8a" ]]; then
build arm64-v8a aarch64-linux-android
fi
if [[ $abiToBuild == "all" ]] || [[ $abiToBuild == "x86" ]]; then
build x86 i686-linux-android
fi
if [[ $abiToBuild == "all" ]] || [[ $abiToBuild == "x86_64" ]]; then
build x86_64 x86_64-linux-android
fi

make clean

Expand Down