mirror of
https://github.com/zeromq/libzmq.git
synced 2025-01-09 11:17:34 +01:00
65b33ebefa
* Problem: Android APP fails to load ZMQ since NDK r25.x With the help of the dump of ./configure options (former PR): ``` LIBZMQ (arm) - ./configure options to build 'LIBZMQ': > --quiet > TOOLCHAIN=/tmp/android-ndk-r25/toolchains/llvm/prebuilt/linux-x86_64 > CC=/tmp/android-ndk-r25/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi21-clang > CXX=/tmp/android-ndk-r25/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi21-clang++ > LD=/tmp/android-ndk-r25/toolchains/llvm/prebuilt/linux-x86_64/bin/ld > AS=/tmp/android-ndk-r25/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-as > AR=/tmp/android-ndk-r25/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar > RANLIB=/tmp/android-ndk-r25/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ranlib > STRIP=/tmp/android-ndk-r25/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip > CFLAGS= -D_GNU_SOURCE -D_REENTRANT -D_THREAD_SAFE > CPPFLAGS= -I/home/stephan/git/zproject-android-testing/libzmq/builds/android/prefix/arm/include > CXXFLAGS= > LDFLAGS=-L/home/stephan/git/zproject-android-testing/libzmq/builds/android/prefix/arm/lib -L/tmp/android-ndk-r25/sour\ ces/cxx-stl/llvm-libc++/libs/armeabi-v7a > LIBS=-lc -ldl -lm -llog -lc++_shared > PKG_CONFIG_LIBDIR=/tmp/android-ndk-r25/prebuilt/linux-x86_64/lib/pkgconfig > PKG_CONFIG_PATH=/home/stephan/git/zproject-android-testing/libzmq/builds/android/prefix/arm/lib/pkgconfig > PKG_CONFIG_SYSROOT_DIR=/tmp/android-ndk-r25/toolchains/llvm/prebuilt/linux-x86_64/sysroot > PKG_CONFIG_DIR= > --with-sysroot=/tmp/android-ndk-r25/toolchains/llvm/prebuilt/linux-x86_64/sysroot > --host=arm-linux-androideabi > --prefix=/home/stephan/git/zproject-android-testing/libzmq/builds/android/prefix/arm > --disable-curve > --without-docs ``` We can observe that LDFLAGS has invalid `-L<path_to_libc++_shared.so>`: ``` -L/tmp/android-ndk-r25/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a ``` This path is no more valid, since NDK r25, where one should use LLVM path. Ok, once this is fixed, ./configure requires also the path to libc.so. I don't understand why libc.so is now required, actually, but without this, ./configure fails to build its conftest. Solution: Fix invalid LDFLAGS. Notes: - To be reported to CZMQ/ZYRE via ZPROJECT. - Tested successfully with Android Emulator (x86 & x86_64). - Still need some more work, as execution still fails with physical devices (observed on arm64). - Introduced `ANDROID_STL`, `ANDROID_STL_ROOT` & `ANDROID_LIBC_ROOT`. All are initialized in `android_build_helper.sh`. - New mechanism **MUST** be compatible with former NDK versions.
129 lines
3.4 KiB
Bash
Executable File
129 lines
3.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
set -e
|
|
|
|
function usage {
|
|
echo "Usage ./build.sh [ arm | arm64 | x86 | x86_64 ]"
|
|
}
|
|
|
|
# Use directory of current script as the build directory and working directory
|
|
cd "$( dirname "${BASH_SOURCE[0]}" )"
|
|
ANDROID_BUILD_DIR="${ANDROID_BUILD_DIR:-`pwd`}"
|
|
|
|
# Get access to android_build functions and variables
|
|
source ./android_build_helper.sh
|
|
|
|
# Choose a C++ standard library implementation from the ndk
|
|
export ANDROID_BUILD_CXXSTL="gnustl_shared_49"
|
|
|
|
# Additional flags for LIBTOOL, for LIBZMQ and other dependencies.
|
|
export LIBTOOL_EXTRA_LDFLAGS='-avoid-version'
|
|
|
|
BUILD_ARCH=$1
|
|
if [ -z $BUILD_ARCH ]; then
|
|
usage
|
|
exit 1
|
|
fi
|
|
|
|
case $(uname | tr '[:upper:]' '[:lower:]') in
|
|
linux*)
|
|
export HOST_PLATFORM=linux-x86_64
|
|
;;
|
|
darwin*)
|
|
export HOST_PLATFORM=darwin-x86_64
|
|
;;
|
|
*)
|
|
echo "Unsupported platform"
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
# Set default values used in ci builds
|
|
export NDK_VERSION=${NDK_VERSION:-android-ndk-r25}
|
|
# With NDK r22b, the minimum SDK version range is [16, 31].
|
|
# Since NDK r24, the minimum SDK version range is [19, 31].
|
|
# SDK version 21 is the minimum version for 64-bit builds.
|
|
export MIN_SDK_VERSION=${MIN_SDK_VERSION:-21}
|
|
|
|
# Set up android build environment and set ANDROID_BUILD_OPTS array
|
|
android_build_set_env $BUILD_ARCH
|
|
android_build_env
|
|
android_build_opts
|
|
|
|
# Use a temporary build directory
|
|
cache="/tmp/android_build/${TOOLCHAIN_ARCH}"
|
|
rm -rf "${cache}"
|
|
mkdir -p "${cache}"
|
|
|
|
# Check for environment variable to clear the prefix and do a clean build
|
|
if [[ $ANDROID_BUILD_CLEAN ]]; then
|
|
echo "Doing a clean build (removing previous build and dependencies)..."
|
|
rm -rf "${ANDROID_BUILD_PREFIX}"/*
|
|
fi
|
|
|
|
if [ -z $CURVE ]; then
|
|
CURVE="--disable-curve"
|
|
VERIFY="libzmq.so"
|
|
elif [ $CURVE == "libsodium" ]; then
|
|
CURVE="--with-libsodium=yes"
|
|
VERIFY="libzmq.so libsodium.so"
|
|
##
|
|
# Build libsodium from latest master branch
|
|
|
|
(android_build_verify_so "libsodium.so" &> /dev/null) || {
|
|
rm -rf "${cache}/libsodium"
|
|
(cd "${cache}" && git clone -b stable --depth 1 https://github.com/jedisct1/libsodium.git) || exit 1
|
|
(
|
|
CONFIG_OPTS=()
|
|
CONFIG_OPTS+=("--quiet")
|
|
CONFIG_OPTS+=("${ANDROID_BUILD_OPTS[@]}")
|
|
CONFIG_OPTS+=("--disable-soname-versions")
|
|
|
|
cd "${cache}/libsodium" \
|
|
&& ./autogen.sh \
|
|
&& android_show_configure_opts "LIBSODIUM" "${CONFIG_OPTS[@]}" \
|
|
&& ./configure "${CONFIG_OPTS[@]}" \
|
|
&& make -j 4 \
|
|
&& make install
|
|
) || exit 1
|
|
}
|
|
elif [ $CURVE == "tweetnacl" ]; then
|
|
# Default
|
|
CURVE=""
|
|
VERIFY="libzmq.so"
|
|
fi
|
|
|
|
##
|
|
# Build libzmq from local source
|
|
|
|
(android_build_verify_so ${VERIFY} &> /dev/null) || {
|
|
rm -rf "${cache}/libzmq"
|
|
(cp -r ../.. "${cache}/libzmq" && cd "${cache}/libzmq" && ( make clean || : ))
|
|
|
|
(
|
|
CONFIG_OPTS=()
|
|
CONFIG_OPTS+=("--quiet")
|
|
CONFIG_OPTS+=("${ANDROID_BUILD_OPTS[@]}")
|
|
CONFIG_OPTS+=("${CURVE}")
|
|
CONFIG_OPTS+=("--without-docs")
|
|
|
|
cd "${cache}/libzmq" \
|
|
&& ./autogen.sh \
|
|
&& android_show_configure_opts "LIBZMQ" "${CONFIG_OPTS[@]}" \
|
|
&& ./configure "${CONFIG_OPTS[@]}" \
|
|
&& make -j 4 \
|
|
&& make install
|
|
) || exit 1
|
|
}
|
|
|
|
##
|
|
# Fetch the STL as well.
|
|
|
|
cp "${ANDROID_STL_ROOT}/${ANDROID_STL}" "${ANDROID_BUILD_PREFIX}/lib/."
|
|
|
|
##
|
|
# Verify shared libraries in prefix
|
|
|
|
android_build_verify_so "${VERIFY}" "${ANDROID_STL}"
|
|
echo "libzmq android build succeeded"
|