Commit 341f56cc authored by Kevin Sapper's avatar Kevin Sapper

Problem: Android build is hard to understand

Solution: Modify the build scripts so the user can specify the platform
for which to build, e.g. `./build.sh arm`. This approach originally
significantly reduces the parameters which have to be set before running
the script.

Further the build process is documented in a README now.
parent d5bd1642
...@@ -15,28 +15,28 @@ protocols and more. ...@@ -15,28 +15,28 @@ protocols and more.
## Supported platforms <a name="#platforms"/> ## Supported platforms <a name="#platforms"/>
Libzmq is mainly written in C++98 with some optional C++11-fragments. For Libzmq is mainly written in C++98 with some optional C++11-fragments. For
configuration either autotools or CMake is employed. See below for some lists configuration either autotools or CMake is employed. See below for some lists
of platforms, where libzmq has been successfully compiled on. of platforms, where libzmq has been successfully compiled on.
### Supported platforms with primary CI ### Supported platforms with primary CI
OS and version | Architecture | Compiler and version | Build system | Remarks | OS and version | Architecture | Compiler and version | Build system | Remarks |
-------------- | ------------ | -------------------- | ------------ | ------- |----------------------------------------|-------------------------|-------------------------------|--------------|---------------------------------------------------------------------------------------------------------------------------------------|
Android NDK 11c | ARM | gcc ? | autotools | | Android NDK r20 | arm, arm64, x86, x86_64 | llvm (see NDK) | autotools | DRAFT |
Ubuntu 14.04.5 LTS (trusty) | amd64 | clang 5.0.0 | autotools | STABLE, extras: GSSAPI, PGM, NORM, C++98 mode only | Ubuntu 14.04.5 LTS (trusty) | amd64 | clang 5.0.0 | autotools | STABLE, extras: GSSAPI, PGM, NORM, C++98 mode only |
Ubuntu 14.04.5 LTS (trusty) | amd64 | gcc 4.8.4 | autotools | STABLE, DRAFT, extras: GSSAPI, PGM, NORM, TIPC, IPV6, also POLLER=poll, POLLER=select, also valgrind and address sanitizer executions | Ubuntu 14.04.5 LTS (trusty) | amd64 | gcc 4.8.4 | autotools | STABLE, DRAFT, extras: GSSAPI, PGM, NORM, TIPC, IPV6, also POLLER=poll, POLLER=select, also valgrind and address sanitizer executions |
Ubuntu 14.04.5 LTS (trusty) | amd64 | gcc 4.8.4 | CMake 3.12.2 | STABLE | Ubuntu 14.04.5 LTS (trusty) | amd64 | gcc 4.8.4 | CMake 3.12.2 | STABLE |
Windows Server 2012 R2 | x86 | Visual Studio 2008 | CMake 3.12.2 | DRAFT | Windows Server 2012 R2 | x86 | Visual Studio 2008 | CMake 3.12.2 | DRAFT |
Windows Server 2012 R2 | x86 | Visual Studio 2010 SP1 | CMake 3.12.2 | DRAFT | Windows Server 2012 R2 | x86 | Visual Studio 2010 SP1 | CMake 3.12.2 | DRAFT |
Windows Server 2012 R2 | x86 | Visual Studio 2012 Update 5 | CMake 3.12.2 | DRAFT | Windows Server 2012 R2 | x86 | Visual Studio 2012 Update 5 | CMake 3.12.2 | DRAFT |
Windows Server 2012 R2 | x86, amd64 | Visual Studio 2013 Update 5 | CMake 3.12.2 | DRAFT, STABLE (x86 Release only), also POLLER=epoll | Windows Server 2012 R2 | x86, amd64 | Visual Studio 2013 Update 5 | CMake 3.12.2 | DRAFT, STABLE (x86 Release only), also POLLER=epoll |
Windows Server 2012 R2 | x86 | Visual Studio 2015 Update 3 | CMake 3.12.2 | DRAFT | Windows Server 2012 R2 | x86 | Visual Studio 2015 Update 3 | CMake 3.12.2 | DRAFT |
Windows Server 2016 | x86 | Visual Studio 2017 15.9.6 | CMake 3.13.3 | DRAFT | Windows Server 2016 | x86 | Visual Studio 2017 15.9.6 | CMake 3.13.3 | DRAFT |
cygwin 3.0.0 on Windows Server 2012 R2 | amd64 | gcc 7.4.0 | CMake 3.6.2 | DRAFT | cygwin 3.0.0 on Windows Server 2012 R2 | amd64 | gcc 7.4.0 | CMake 3.6.2 | DRAFT |
MSYS2 ? on Windows Server 2012 R2 | amd64 | gcc 6.4.0 | CMake ? | DRAFT | MSYS2 ? on Windows Server 2012 R2 | amd64 | gcc 6.4.0 | CMake ? | DRAFT |
Mac OS X 10.13 | amd64 | Xcode 9.4.1, Apple LLVM 9.1.0 | autotools | STABLE, DRAFT | Mac OS X 10.13 | amd64 | Xcode 9.4.1, Apple LLVM 9.1.0 | autotools | STABLE, DRAFT |
Mac OS X 10.13 | amd64 | Xcode 9.4.1, Apple LLVM 9.1.0 | CMake 3.11.4 | DRAFT | Mac OS X 10.13 | amd64 | Xcode 9.4.1, Apple LLVM 9.1.0 | CMake 3.11.4 | DRAFT |
Note: the platforms are regularly updated by the service providers, so this information might get out of date Note: the platforms are regularly updated by the service providers, so this information might get out of date
without any changes on the side of libzmq. For Appveyor, refer to https://www.appveyor.com/updates/ regarding without any changes on the side of libzmq. For Appveyor, refer to https://www.appveyor.com/updates/ regarding
...@@ -64,10 +64,10 @@ xUbuntu 18.10 | x86, amd64 | ? | autotools | ...@@ -64,10 +64,10 @@ xUbuntu 18.10 | x86, amd64 | ? | autotools |
### Supported platforms with known active users ### Supported platforms with known active users
At the time of writing, no explicit reports have been available. Please report your experiences by opening a PR At the time of writing, no explicit reports have been available. Please report your experiences by opening a PR
adding an entry or moving an entry from the section below. adding an entry or moving an entry from the section below.
Under "last report", please name either the SHA1 in case of an unreleased version, or the version number in Under "last report", please name either the SHA1 in case of an unreleased version, or the version number in
case of a released version. case of a released version.
OS and version | Architecture | Compiler and version | Build system | Last report | Remarks OS and version | Architecture | Compiler and version | Build system | Last report | Remarks
...@@ -102,11 +102,11 @@ OpenVMS | ? | ? | ? | ...@@ -102,11 +102,11 @@ OpenVMS | ? | ? | ? |
OS and version | Architecture | Compiler and version | Remarks OS and version | Architecture | Compiler and version | Remarks
-------------- | ------------ | -------------------- | ------- -------------- | ------------ | -------------------- | -------
QNX 6.3 | ? | gcc 3.3.5 | see #3371, support was added by a user, but not contributed to upstream QNX 6.3 | ? | gcc 3.3.5 | see #3371, support was added by a user, but not contributed to upstream
Windows 10 | ARM, ARM64 | Visual Studio 2017 | see #3366, probably only minor issues Windows 10 | ARM, ARM64 | Visual Studio 2017 | see #3366, probably only minor issues
For more details, see [here](SupportedPlatforms.md). For more details, see [here](SupportedPlatforms.md).
For some platforms (Linux, Mac OS X), [prebuilt binary packages are supplied by the ZeroMQ organization](#installation). For some platforms (Linux, Mac OS X), [prebuilt binary packages are supplied by the ZeroMQ organization](#installation).
For other platforms, you need to [build your own binaries](#build). For other platforms, you need to [build your own binaries](#build).
## Installation of binary packages <a name="installation"/> ## Installation of binary packages <a name="installation"/>
...@@ -157,6 +157,11 @@ For OSX users, packages are available via brew. ...@@ -157,6 +157,11 @@ For OSX users, packages are available via brew.
To build from sources, see the INSTALL file included with the distribution. To build from sources, see the INSTALL file included with the distribution.
### Android
To build from source, see [REAMDE](./builds/android/README.md) file in the
android build directory.
## Resources ## Resources
Extensive documentation is provided with the distribution. Refer to Extensive documentation is provided with the distribution. Refer to
......
LIBZMQ ANDROID COMPILATION STEPS # Android Build
================================
To launch the docker build:
$ docker build . ## Prerequisites
To launch the android build, you have to first install the android-ndk first in your HOME directory: You need the Android Native Development Kit (NDK) installed. See
[here](https://developer.android.com/ndk) to download it.
$ cd ~ This project is tested against Android NDK version r20.
$ export ANDROID_NDK_VERSION="r10e"
$ wget -q https://dl.google.com/android/ndk/android-ndk-${ANDROID_NDK_VERSION}-linux-x86_64.bin -O android-ndk-${ANDROID_NDK_VERSION}-linux-x86_64.bin
$ #check the hashes before executing this binary
$ md5sum android-ndk-r10e-linux-x86_64.bin
# 19af543b068bdb7f27787c2bc69aba7f android-ndk-r10e-linux-x86_64.bin
$ sha256sum android-ndk-r10e-linux-x86_64.bin
# 102d6723f67ff1384330d12c45854315d6452d6510286f4e5891e00a5a8f1d5a android-ndk-r10e-linux-x86_64.bin
$ chmod +x android-ndk-${ANDROID_NDK_VERSION}-linux-x86_64.bin
$ ./android-ndk-r10e-linux-x86_64.bin
$ export ANDROID_NDK_ROOT=${HOME}/android-ndk-r10e
$ export TOOLCHAIN_NAME=arm-linux-androideabi-4.9
$ export TOOLCHAIN_HOST=arm-linux-androideabi
$ export TOOLCHAIN_PATH=${ANDROID_NDK_ROOT}/toolchains/${TOOLCHAIN_NAME}/prebuilt/linux-x86_64/bin
$ export TOOLCHAIN_ARCH=arm
Then you can launch the build: If you installed version r20 all you have to do is to expose the NDK root
directory as environment variable, e.g:
$ cd ~/libzmq/builds/android export ANDROID_NDK_ROOT=$HOME/android-ndk-r20
$ ./build.sh
Cloning into 'libsodium'...
remote: Counting objects: 15246, done.
remote: Compressing objects: 100% (182/182), done.
Receiving objects: 16% (2440/15246)
[...]
A successful build should finish with the following message and give you back your shell prompt: If you installed another version you have to expose the NDK root directory as
well as the NDK version, e.g:
[...] export ANDROID_NDK_ROOT=$HOME/android-ndk-r17c
make[2]: Leaving directory '/tmp/android_build/arm-linux-androideabi-4.9/libzmq' export NDK_VERSION=android-ndk-r17c
make[1]: Leaving directory '/tmp/android_build/arm-linux-androideabi-4.9/libzmq'
libzmq android build succeeded
$
You will then be able to see libzmq.so compiled in the prefix/ directory: To specify the minimum sdk version set the environment variable below:
$ cd ~/libzmq/builds/android/prefix/arm-linux-androideabi-4.9/lib export MIN_SDK_VERSION=21 # Default value if unset
$ ls
libsodium.a libsodium.la libsodium.so libzmq.a libzmq.la libzmq.so pkgconfig
You can then triple check that they are ARM libs: ## Build
$ cd ~/libzmq/builds/android/prefix/arm-linux-androideabi-4.9/lib In the android directory, run:
$ file libzmq.so
libzmq.so: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /system/bin/linker, not stripped
./build.sh [ arm | arm64 | x86 | x86_64 ]
COMPILE WITH DOCKERFILE
=======================
To launch the docker build with a tagged image as a result:
$ cd ~/libzmq/builds/android
$ docker build -t libzmq-android:`date +"%y%m%d-%H%M%S"` .
$ docker build -t libzmq-android:latest .
If it is successful, it will end by "libzmq android build succeeded" followed by the ContainerID "e53db616aff4":
[...]
make[2]: Leaving directory `/tmp/android_build/arm-linux-androideabi-4.9/libzmq'
make[1]: Leaving directory `/tmp/android_build/arm-linux-androideabi-4.9/libzmq'
libzmq android build succeeded
---> e53db616aff4
Removing intermediate container 8a5f3e34f3da
Successfully built e53db616aff4
$
$ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
libzmq-android 151218-101411 e53db616aff4 18 hours ago 5.495 GB
If you want to collect the artifacts on the build, you can specify a directory in your HOME directory, such as "$HOME/libzmq-android-bins" for example:
$ mkdir -pv $HOME/libzmq-android-bins
$ docker run -v $HOME/libzmq-android-bins:/data libzmq-android:latest "cp -v /home/zmq/libzmq/builds/android/prefix/arm-linux-androideabi-4.9/lib/* /data"
...@@ -69,72 +69,80 @@ function android_build_check_fail { ...@@ -69,72 +69,80 @@ function android_build_check_fail {
fi fi
} }
function android_build_arch {
export TOOLCHAIN_PATH="${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/${HOST_PLATFORM}/bin"
export TOOLCHAIN_HOST=$1
export TOOLCHAIN_COMP=$2
export TOOLCHAIN_CXXSTL=$3
export TOOLCHAIN_ARCH=$4
}
function android_build_env { function android_build_env {
## ##
# Check that necessary environment variables are set # Check that necessary environment variables are set
if [ -z "$ANDROID_NDK_ROOT" ]; then if [ -z "$ANDROID_NDK_ROOT" ]; then
ANDROID_BUILD_FAIL+=("Please set the ANDROID_NDK_ROOT environment variable") ANDROID_BUILD_FAIL+=("Please set the ANDROID_NDK_ROOT environment variable")
ANDROID_BUILD_FAIL+=(" (eg. \"/home/user/android/android-ndk-r20\")") ANDROID_BUILD_FAIL+=(" (eg. \"/home/user/android/android-ndk-r20\")")
fi fi
if [ -z "$TOOLCHAIN_PATH" ]; then if [ -z "$TOOLCHAIN_PATH" ]; then
ANDROID_BUILD_FAIL+=("Please set the TOOLCHAIN_PATH environment variable") ANDROID_BUILD_FAIL+=("Please set the TOOLCHAIN_PATH environment variable")
ANDROID_BUILD_FAIL+=(" (eg. \"/home/user/android/android-ndk-r20/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin\")") ANDROID_BUILD_FAIL+=(" (eg. \"/home/user/android/android-ndk-r20/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin\")")
fi fi
if [ -z "$TOOLCHAIN_HOST" ]; then if [ -z "$TOOLCHAIN_HOST" ]; then
ANDROID_BUILD_FAIL+=("Please set the TOOLCHAIN_HOST environment variable") ANDROID_BUILD_FAIL+=("Please set the TOOLCHAIN_HOST environment variable")
ANDROID_BUILD_FAIL+=(" (eg. \"arm-linux-androideabi\")") ANDROID_BUILD_FAIL+=(" (eg. \"arm-linux-androideabi\")")
fi fi
if [ -z "$TOOLCHAIN_COMP" ]; then if [ -z "$TOOLCHAIN_COMP" ]; then
ANDROID_BUILD_FAIL+=("Please set the TOOLCHAIN_COMP environment variable") ANDROID_BUILD_FAIL+=("Please set the TOOLCHAIN_COMP environment variable")
ANDROID_BUILD_FAIL+=(" (eg. \"armv7a-linux-androideabi\")") ANDROID_BUILD_FAIL+=(" (eg. \"armv7a-linux-androideabi\")")
fi fi
if [ -z "$TOOLCHAIN_CXXSTL" ]; then if [ -z "$TOOLCHAIN_CXXSTL" ]; then
ANDROID_BUILD_FAIL+=("Please set the TOOLCHAIN_CXXSTL environment variable") ANDROID_BUILD_FAIL+=("Please set the TOOLCHAIN_CXXSTL environment variable")
ANDROID_BUILD_FAIL+=(" (eg. \"armeabi-v7abi\")") ANDROID_BUILD_FAIL+=(" (eg. \"armeabi-v7abi\")")
fi fi
if [ -z "$TOOLCHAIN_ARCH" ]; then if [ -z "$TOOLCHAIN_ARCH" ]; then
ANDROID_BUILD_FAIL+=("Please set the TOOLCHAIN_ARCH environment variable") ANDROID_BUILD_FAIL+=("Please set the TOOLCHAIN_ARCH environment variable")
ANDROID_BUILD_FAIL+=(" (eg. \"arm\")") ANDROID_BUILD_FAIL+=(" (eg. \"arm\")")
fi fi
android_build_check_fail android_build_check_fail
## ##
# Check that directories given by environment variables exist # Check that directories given by environment variables exist
if [ ! -d "$ANDROID_NDK_ROOT" ]; then if [ ! -d "$ANDROID_NDK_ROOT" ]; then
ANDROID_BUILD_FAIL+=("The ANDROID_NDK_ROOT directory does not exist") ANDROID_BUILD_FAIL+=("The ANDROID_NDK_ROOT directory does not exist")
ANDROID_BUILD_FAIL+=(" ${ANDROID_NDK_ROOT}") ANDROID_BUILD_FAIL+=(" ${ANDROID_NDK_ROOT}")
fi fi
if [ ! -d "$TOOLCHAIN_PATH" ]; then if [ ! -d "$TOOLCHAIN_PATH" ]; then
ANDROID_BUILD_FAIL+=("The TOOLCHAIN_PATH directory does not exist") ANDROID_BUILD_FAIL+=("The TOOLCHAIN_PATH directory does not exist")
ANDROID_BUILD_FAIL+=(" ${TOOLCHAIN_PATH}") ANDROID_BUILD_FAIL+=(" ${TOOLCHAIN_PATH}")
fi fi
## ##
# Set up some local variables and check them # Set up some local variables and check them
ANDROID_BUILD_SYSROOT="${ANDROID_NDK_ROOT}/platforms/android-${MIN_SDK_VERSION}/arch-${TOOLCHAIN_ARCH}" ANDROID_BUILD_SYSROOT="${ANDROID_NDK_ROOT}/platforms/android-${MIN_SDK_VERSION}/arch-${TOOLCHAIN_ARCH}"
if [ ! -d "$ANDROID_BUILD_SYSROOT" ]; then if [ ! -d "$ANDROID_BUILD_SYSROOT" ]; then
ANDROID_BUILD_FAIL+=("The ANDROID_BUILD_SYSROOT directory does not exist") ANDROID_BUILD_FAIL+=("The ANDROID_BUILD_SYSROOT directory does not exist")
ANDROID_BUILD_FAIL+=(" ${ANDROID_BUILD_SYSROOT}") ANDROID_BUILD_FAIL+=(" ${ANDROID_BUILD_SYSROOT}")
fi fi
ANDROID_BUILD_PREFIX="${ANDROID_BUILD_DIR}/prefix/${TOOLCHAIN_NAME}" ANDROID_BUILD_PREFIX="${ANDROID_BUILD_DIR}/prefix/${TOOLCHAIN_ARCH}"
mkdir -p "$ANDROID_BUILD_PREFIX" || { mkdir -p "$ANDROID_BUILD_PREFIX" || {
ANDROID_BUILD_FAIL+=("Failed to make ANDROID_BUILD_PREFIX directory") ANDROID_BUILD_FAIL+=("Failed to make ANDROID_BUILD_PREFIX directory")
ANDROID_BUILD_FAIL+=(" ${ANDROID_BUILD_PREFIX}") ANDROID_BUILD_FAIL+=(" ${ANDROID_BUILD_PREFIX}")
} }
android_build_check_fail android_build_check_fail
} }
...@@ -147,37 +155,37 @@ function _android_build_opts_process_binaries { ...@@ -147,37 +155,37 @@ function _android_build_opts_process_binaries {
local AR="${TOOLCHAIN_PATH}/${TOOLCHAIN_HOST}-ar" local AR="${TOOLCHAIN_PATH}/${TOOLCHAIN_HOST}-ar"
local RANLIB="${TOOLCHAIN_PATH}/${TOOLCHAIN_HOST}-ranlib" local RANLIB="${TOOLCHAIN_PATH}/${TOOLCHAIN_HOST}-ranlib"
local STRIP="${TOOLCHAIN_PATH}/${TOOLCHAIN_HOST}-strip" local STRIP="${TOOLCHAIN_PATH}/${TOOLCHAIN_HOST}-strip"
if [ ! -x "${CC}" ]; then if [ ! -x "${CC}" ]; then
ANDROID_BUILD_FAIL+=("The CC binary does not exist or is not executable") ANDROID_BUILD_FAIL+=("The CC binary does not exist or is not executable")
ANDROID_BUILD_FAIL+=(" ${CC}") ANDROID_BUILD_FAIL+=(" ${CC}")
fi fi
if [ ! -x "${CXX}" ]; then if [ ! -x "${CXX}" ]; then
ANDROID_BUILD_FAIL+=("The CXX binary does not exist or is not executable") ANDROID_BUILD_FAIL+=("The CXX binary does not exist or is not executable")
ANDROID_BUILD_FAIL+=(" ${CXX}") ANDROID_BUILD_FAIL+=(" ${CXX}")
fi fi
if [ ! -x "${LD}" ]; then if [ ! -x "${LD}" ]; then
ANDROID_BUILD_FAIL+=("The LD binary does not exist or is not executable") ANDROID_BUILD_FAIL+=("The LD binary does not exist or is not executable")
ANDROID_BUILD_FAIL+=(" ${LD}") ANDROID_BUILD_FAIL+=(" ${LD}")
fi fi
if [ ! -x "${AS}" ]; then if [ ! -x "${AS}" ]; then
ANDROID_BUILD_FAIL+=("The AS binary does not exist or is not executable") ANDROID_BUILD_FAIL+=("The AS binary does not exist or is not executable")
ANDROID_BUILD_FAIL+=(" ${AS}") ANDROID_BUILD_FAIL+=(" ${AS}")
fi fi
if [ ! -x "${AR}" ]; then if [ ! -x "${AR}" ]; then
ANDROID_BUILD_FAIL+=("The AR binary does not exist or is not executable") ANDROID_BUILD_FAIL+=("The AR binary does not exist or is not executable")
ANDROID_BUILD_FAIL+=(" ${AR}") ANDROID_BUILD_FAIL+=(" ${AR}")
fi fi
if [ ! -x "${RANLIB}" ]; then if [ ! -x "${RANLIB}" ]; then
ANDROID_BUILD_FAIL+=("The RANLIB binary does not exist or is not executable") ANDROID_BUILD_FAIL+=("The RANLIB binary does not exist or is not executable")
ANDROID_BUILD_FAIL+=(" ${RANLIB}") ANDROID_BUILD_FAIL+=(" ${RANLIB}")
fi fi
if [ ! -x "${STRIP}" ]; then if [ ! -x "${STRIP}" ]; then
ANDROID_BUILD_FAIL+=("The STRIP binary does not exist or is not executable") ANDROID_BUILD_FAIL+=("The STRIP binary does not exist or is not executable")
ANDROID_BUILD_FAIL+=(" ${STRIP}") ANDROID_BUILD_FAIL+=(" ${STRIP}")
...@@ -191,17 +199,17 @@ function _android_build_opts_process_binaries { ...@@ -191,17 +199,17 @@ function _android_build_opts_process_binaries {
ANDROID_BUILD_OPTS+=("AR=${AR}") ANDROID_BUILD_OPTS+=("AR=${AR}")
ANDROID_BUILD_OPTS+=("RANLIB=${RANLIB}") ANDROID_BUILD_OPTS+=("RANLIB=${RANLIB}")
ANDROID_BUILD_OPTS+=("STRIP=${STRIP}") ANDROID_BUILD_OPTS+=("STRIP=${STRIP}")
android_build_check_fail android_build_check_fail
} }
# Set the ANDROID_BUILD_OPTS variable to a bash array of configure options # Set the ANDROID_BUILD_OPTS variable to a bash array of configure options
function android_build_opts { function android_build_opts {
ANDROID_BUILD_OPTS=() ANDROID_BUILD_OPTS=()
_android_build_opts_process_binaries _android_build_opts_process_binaries
local LIBS="-lc -lgcc -ldl -lc++_shared" local LIBS="-lc -lgcc -ldl -lm -llog -lc++_shared"
local LDFLAGS="-L${ANDROID_BUILD_PREFIX}/lib" local LDFLAGS="-L${ANDROID_BUILD_PREFIX}/lib"
LDFLAGS+=" -L${ANDROID_NDK_ROOT}/sources/cxx-stl/llvm-libc++/libs/${TOOLCHAIN_CXXSTL}" LDFLAGS+=" -L${ANDROID_NDK_ROOT}/sources/cxx-stl/llvm-libc++/libs/${TOOLCHAIN_CXXSTL}"
CFLAGS+=" -D_GNU_SOURCE -D_REENTRANT -D_THREAD_SAFE" CFLAGS+=" -D_GNU_SOURCE -D_REENTRANT -D_THREAD_SAFE"
...@@ -212,7 +220,7 @@ function android_build_opts { ...@@ -212,7 +220,7 @@ function android_build_opts {
ANDROID_BUILD_OPTS+=("CXXFLAGS=${CXXFLAGS} ${ANDROID_BUILD_EXTRA_CXXFLAGS}") ANDROID_BUILD_OPTS+=("CXXFLAGS=${CXXFLAGS} ${ANDROID_BUILD_EXTRA_CXXFLAGS}")
ANDROID_BUILD_OPTS+=("LDFLAGS=${LDFLAGS} ${ANDROID_BUILD_EXTRA_LDFLAGS}") ANDROID_BUILD_OPTS+=("LDFLAGS=${LDFLAGS} ${ANDROID_BUILD_EXTRA_LDFLAGS}")
ANDROID_BUILD_OPTS+=("LIBS=${LIBS} ${ANDROID_BUILD_EXTRA_LIBS}") ANDROID_BUILD_OPTS+=("LIBS=${LIBS} ${ANDROID_BUILD_EXTRA_LIBS}")
ANDROID_BUILD_OPTS+=("PKG_CONFIG_LIBDIR=${ANDROID_NDK_ROOT}/prebuilt/${HOST_PLATFORM}/lib/pkgconfig") ANDROID_BUILD_OPTS+=("PKG_CONFIG_LIBDIR=${ANDROID_NDK_ROOT}/prebuilt/${HOST_PLATFORM}/lib/pkgconfig")
ANDROID_BUILD_OPTS+=("PKG_CONFIG_PATH=${ANDROID_BUILD_PREFIX}/lib/pkgconfig") ANDROID_BUILD_OPTS+=("PKG_CONFIG_PATH=${ANDROID_BUILD_PREFIX}/lib/pkgconfig")
ANDROID_BUILD_OPTS+=("PKG_CONFIG_SYSROOT_DIR=${ANDROID_BUILD_SYSROOT}") ANDROID_BUILD_OPTS+=("PKG_CONFIG_SYSROOT_DIR=${ANDROID_BUILD_SYSROOT}")
...@@ -220,7 +228,7 @@ function android_build_opts { ...@@ -220,7 +228,7 @@ function android_build_opts {
ANDROID_BUILD_OPTS+=("--with-sysroot=${ANDROID_BUILD_SYSROOT}") ANDROID_BUILD_OPTS+=("--with-sysroot=${ANDROID_BUILD_SYSROOT}")
ANDROID_BUILD_OPTS+=("--host=${TOOLCHAIN_HOST}") ANDROID_BUILD_OPTS+=("--host=${TOOLCHAIN_HOST}")
ANDROID_BUILD_OPTS+=("--prefix=${ANDROID_BUILD_PREFIX}") ANDROID_BUILD_OPTS+=("--prefix=${ANDROID_BUILD_PREFIX}")
android_build_check_fail android_build_check_fail
} }
...@@ -231,14 +239,14 @@ function android_build_opts { ...@@ -231,14 +239,14 @@ function android_build_opts {
function android_build_verify_so { function android_build_verify_so {
local soname="$1" local soname="$1"
shift # Get rid of first argument - the rest represent dependencies shift # Get rid of first argument - the rest represent dependencies
local sofile="${ANDROID_BUILD_PREFIX}/lib/${soname}" local sofile="${ANDROID_BUILD_PREFIX}/lib/${soname}"
if [ ! -f "${sofile}" ]; then if [ ! -f "${sofile}" ]; then
ANDROID_BUILD_FAIL+=("Found no library named ${soname}") ANDROID_BUILD_FAIL+=("Found no library named ${soname}")
ANDROID_BUILD_FAIL+=(" ${sofile}") ANDROID_BUILD_FAIL+=(" ${sofile}")
fi fi
android_build_check_fail android_build_check_fail
if command -v readelf >/dev/null 2>&1 ; then if command -v readelf >/dev/null 2>&1 ; then
local readelf_bin="readelf" local readelf_bin="readelf"
elif command -v greadelf >/dev/null 2>&1 ; then elif command -v greadelf >/dev/null 2>&1 ; then
...@@ -249,7 +257,7 @@ function android_build_verify_so { ...@@ -249,7 +257,7 @@ function android_build_verify_so {
android_build_check_fail android_build_check_fail
local elfoutput=$(LC_ALL=C $readelf_bin -d ${sofile}) local elfoutput=$(LC_ALL=C $readelf_bin -d ${sofile})
local soname_regexp='soname: \[([[:alnum:]\.]+)\]' local soname_regexp='soname: \[([[:alnum:]\.]+)\]'
if [[ $elfoutput =~ $soname_regexp ]]; then if [[ $elfoutput =~ $soname_regexp ]]; then
local parsed_soname="${BASH_REMATCH[1]}" local parsed_soname="${BASH_REMATCH[1]}"
...@@ -261,13 +269,13 @@ function android_build_verify_so { ...@@ -261,13 +269,13 @@ function android_build_verify_so {
ANDROID_BUILD_FAIL+=("Failed to meaningfully parse readelf output for library ${soname}:") ANDROID_BUILD_FAIL+=("Failed to meaningfully parse readelf output for library ${soname}:")
ANDROID_BUILD_FAIL+=(" ${elfoutput}") ANDROID_BUILD_FAIL+=(" ${elfoutput}")
fi fi
for dep_soname do for dep_soname do
if [[ $elfoutput != *"library: [${dep_soname}]"* ]]; then if [[ $elfoutput != *"library: [${dep_soname}]"* ]]; then
ANDROID_BUILD_FAIL+=("Library ${soname} was expected to be linked to library with soname:") ANDROID_BUILD_FAIL+=("Library ${soname} was expected to be linked to library with soname:")
ANDROID_BUILD_FAIL+=(" ${dep_soname}") ANDROID_BUILD_FAIL+=(" ${dep_soname}")
fi fi
done done
android_build_check_fail android_build_check_fail
} }
#!/usr/bin/env bash #!/usr/bin/env bash
function usage {
echo "Usage ./build.sh [ arm | arm64 | x86 | x86_64 ]"
}
# Use directory of current script as the build directory and working directory # Use directory of current script as the build directory and working directory
cd "$( dirname "${BASH_SOURCE[0]}" )" cd "$( dirname "${BASH_SOURCE[0]}" )"
ANDROID_BUILD_DIR="$(pwd)" ANDROID_BUILD_DIR="$(pwd)"
...@@ -10,12 +14,73 @@ source ${ANDROID_BUILD_DIR}/android_build_helper.sh ...@@ -10,12 +14,73 @@ source ${ANDROID_BUILD_DIR}/android_build_helper.sh
# Choose a C++ standard library implementation from the ndk # Choose a C++ standard library implementation from the ndk
ANDROID_BUILD_CXXSTL="gnustl_shared_49" ANDROID_BUILD_CXXSTL="gnustl_shared_49"
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-r20}
# With NDK r20, the minimum SDK version range is [16, 29].
# SDK version 21 is the minimum version for 64-bit builds.
export MIN_SDK_VERSION=${MIN_SDK_VERSION:-21}
# Set variables for each architecture
HOST_ARM="arm-linux-androideabi"
HOST_ARM64="aarch64-linux-android"
HOST_X86="i686-linux-android"
HOST_X86_64="x86_64-linux-android"
COMP_ARM="armv7a-linux-androideabi${MIN_SDK_VERSION}"
COMP_ARM64="aarch64-linux-android${MIN_SDK_VERSION}"
COMP_X86="i686-linux-android${MIN_SDK_VERSION}"
COMP_X86_64="x86_64-linux-android${MIN_SDK_VERSION}"
CXXSTL_ARM="armeabi-v7a"
CXXSTL_ARM64="arm64-v8a"
CXXSTL_X86="x86"
CXXSTL_X86_64="x86_64"
ARCH_ARM="arm"
ARCH_ARM64="arm64"
ARCH_X86="x86"
ARCH_X86_64="x86_64"
if [ $BUILD_ARCH == "arm" ]; then
android_build_arch $HOST_ARM $COMP_ARM $CXXSTL_ARM $ARCH_ARM
elif [ $BUILD_ARCH == "x86" ]; then
android_build_arch $HOST_X86 $COMP_X86 $CXXSTL_X86 $ARCH_X86
elif [ $BUILD_ARCH == "arm64" ]; then
android_build_arch $HOST_ARM64 $COMP_ARM64 $CXXSTL_ARM64 $ARCH_ARM64
elif [ $BUILD_ARCH == "x86_64" ]; then
android_build_arch $HOST_X86_64 $COMP_X86_64 $CXXSTL_X86_64 $ARCH_X86_64
else
usage
exit 1
fi
# Set up android build environment and set ANDROID_BUILD_OPTS array # Set up android build environment and set ANDROID_BUILD_OPTS array
android_build_env android_build_env
android_build_opts android_build_opts
# Use a temporary build directory # Use a temporary build directory
cache="/tmp/android_build/${TOOLCHAIN_NAME}" cache="/tmp/android_build/${TOOLCHAIN_ARCH}"
rm -rf "${cache}" rm -rf "${cache}"
mkdir -p "${cache}" mkdir -p "${cache}"
...@@ -56,7 +121,7 @@ LIBTOOL_EXTRA_LDFLAGS='-avoid-version' ...@@ -56,7 +121,7 @@ LIBTOOL_EXTRA_LDFLAGS='-avoid-version'
(android_build_verify_so ${VERIFY} &> /dev/null) || { (android_build_verify_so ${VERIFY} &> /dev/null) || {
rm -rf "${cache}/libzmq" rm -rf "${cache}/libzmq"
(cp -r ../.. "${cache}/libzmq" && cd "${cache}/libzmq" && make clean) (cp -r ../.. "${cache}/libzmq" && cd "${cache}/libzmq" && make clean)
(cd "${cache}/libzmq" && ./autogen.sh \ (cd "${cache}/libzmq" && ./autogen.sh \
&& ./configure --quiet "${ANDROID_BUILD_OPTS[@]}" ${CURVE} --without-docs \ && ./configure --quiet "${ANDROID_BUILD_OPTS[@]}" ${CURVE} --without-docs \
&& make -j 4 \ && make -j 4 \
......
#!/usr/bin/env bash #!/usr/bin/env bash
NDK_VERSION=android-ndk-r20 export NDK_VERSION=android-ndk-r20
NDK_ABI_VERSION=4.9 export ANDROID_NDK_ROOT="/tmp/${NDK_VERSION}"
if [ $TRAVIS_OS_NAME == "linux" ] case $(uname | tr '[:upper:]' '[:lower:]') in
then linux*)
HOST_PLATFORM=linux-x86_64 HOST_PLATFORM=linux-x86_64
elif [ $TRAVIS_OS_NAME == "osx" ] ;;
then darwin*)
HOST_PLATFORM=darwin-x86_64 HOST_PLATFORM=darwin-x86_64
else ;;
echo "Unsupported platform $TRAVIS_OS_NAME" *)
echo "Unsupported platform"
exit 1 exit 1
fi ;;
esac
if [ ! -d "/tmp/${NDK_VERSION}" ] ; then if [ ! -d "${ANDROID_NDK_ROOT}" ]; then
export FILENAME=$NDK_VERSION-$HOST_PLATFORM.zip export FILENAME=$NDK_VERSION-$HOST_PLATFORM.zip
(cd '/tmp' \ (cd '/tmp' \
&& wget http://dl.google.com/android/repository/$FILENAME -O $FILENAME \ && wget http://dl.google.com/android/repository/$FILENAME -O $FILENAME &> /dev/null \
&& unzip -q $FILENAME) || exit 1 && unzip -q $FILENAME) || exit 1
unset FILENAME unset FILENAME
fi fi
function _build_arch { ./build.sh "arm"
export ANDROID_NDK_ROOT="/tmp/${NDK_VERSION}" ./build.sh "arm64"
export TOOLCHAIN_PATH="${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/${HOST_PLATFORM}/bin" ./build.sh "x86"
export TOOLCHAIN_HOST=$1 ./build.sh "x86_64"
export TOOLCHAIN_COMP=$2
export TOOLCHAIN_CXXSTL=$3
export TOOLCHAIN_ARCH=$4
export TOOLCHAIN_NAME="${TOOLCHAIN_HOST}-${NDK_ABI_VERSION}"
source ./build.sh
}
# Define the minimum Android API level for the library to run.
# With NDK r20, the minimum SDK version range is [16, 29]
export MIN_SDK_VERSION="21"
HOST_ARM="arm-linux-androideabi"
HOST_ARM64="aarch64-linux-android"
HOST_X86="i686-linux-android"
HOST_X86_64="x86_64-linux-android"
COMP_ARM="armv7a-linux-androideabi${MIN_SDK_VERSION}"
COMP_ARM64="aarch64-linux-android${MIN_SDK_VERSION}"
COMP_X86="i686-linux-android${MIN_SDK_VERSION}"
COMP_X86_64="x86_64-linux-android${MIN_SDK_VERSION}"
CXXSTL_ARM="armeabi-v7a"
CXXSTL_ARM64="arm64-v8a"
CXXSTL_X86="x86"
CXXSTL_X86_64="x86_64"
ARCH_ARM="arm"
ARCH_ARM64="arm64"
ARCH_X86="x86"
ARCH_X86_64="x86_64"
_build_arch $HOST_ARM $COMP_ARM $CXXSTL_ARM $ARCH_ARM
_build_arch $HOST_X86 $COMP_X86 $CXXSTL_X86 $ARCH_X86
if [[ $MIN_SDK_VERSION -ge 21 ]] ; then
_build_arch $HOST_ARM64 $COMP_ARM64 $CXXSTL_ARM64 $ARCH_ARM64
_build_arch $HOST_X86_64 $COMP_X86_64 $CXXSTL_X86_64 $ARCH_X86_64
fi
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment