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
......@@ -21,22 +21,22 @@ of platforms, where libzmq has been successfully compiled on.
### Supported platforms with primary CI
OS and version | Architecture | Compiler and version | Build system | Remarks
-------------- | ------------ | -------------------- | ------------ | -------
Android NDK 11c | ARM | gcc ? | autotools |
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 | 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 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, 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 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
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 | CMake 3.11.4 | DRAFT
| OS and version | Architecture | Compiler and version | Build system | Remarks |
|----------------------------------------|-------------------------|-------------------------------|--------------|---------------------------------------------------------------------------------------------------------------------------------------|
| 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 | 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 |
| 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 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 | 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 |
| 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 |
| 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 |
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
......@@ -157,6 +157,11 @@ For OSX users, packages are available via brew.
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
Extensive documentation is provided with the distribution. Refer to
......
LIBZMQ ANDROID COMPILATION STEPS
================================
To launch the docker build:
# Android 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 ~
$ 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
This project is tested against Android NDK version r20.
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
$ ./build.sh
Cloning into 'libsodium'...
remote: Counting objects: 15246, done.
remote: Compressing objects: 100% (182/182), done.
Receiving objects: 16% (2440/15246)
[...]
export ANDROID_NDK_ROOT=$HOME/android-ndk-r20
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:
[...]
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
$
export ANDROID_NDK_ROOT=$HOME/android-ndk-r17c
export NDK_VERSION=android-ndk-r17c
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
$ ls
libsodium.a libsodium.la libsodium.so libzmq.a libzmq.la libzmq.so pkgconfig
export MIN_SDK_VERSION=21 # Default value if unset
You can then triple check that they are ARM libs:
## Build
$ cd ~/libzmq/builds/android/prefix/arm-linux-androideabi-4.9/lib
$ file libzmq.so
libzmq.so: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /system/bin/linker, not stripped
In the android directory, run:
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"
./build.sh [ arm | arm64 | x86 | x86_64 ]
......@@ -69,6 +69,14 @@ function android_build_check_fail {
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 {
##
# Check that necessary environment variables are set
......@@ -128,7 +136,7 @@ function android_build_env {
ANDROID_BUILD_FAIL+=(" ${ANDROID_BUILD_SYSROOT}")
fi
ANDROID_BUILD_PREFIX="${ANDROID_BUILD_DIR}/prefix/${TOOLCHAIN_NAME}"
ANDROID_BUILD_PREFIX="${ANDROID_BUILD_DIR}/prefix/${TOOLCHAIN_ARCH}"
mkdir -p "$ANDROID_BUILD_PREFIX" || {
ANDROID_BUILD_FAIL+=("Failed to make ANDROID_BUILD_PREFIX directory")
......@@ -201,7 +209,7 @@ function android_build_opts {
_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"
LDFLAGS+=" -L${ANDROID_NDK_ROOT}/sources/cxx-stl/llvm-libc++/libs/${TOOLCHAIN_CXXSTL}"
CFLAGS+=" -D_GNU_SOURCE -D_REENTRANT -D_THREAD_SAFE"
......
#!/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
cd "$( dirname "${BASH_SOURCE[0]}" )"
ANDROID_BUILD_DIR="$(pwd)"
......@@ -10,12 +14,73 @@ source ${ANDROID_BUILD_DIR}/android_build_helper.sh
# Choose a C++ standard library implementation from the ndk
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
android_build_env
android_build_opts
# Use a temporary build directory
cache="/tmp/android_build/${TOOLCHAIN_NAME}"
cache="/tmp/android_build/${TOOLCHAIN_ARCH}"
rm -rf "${cache}"
mkdir -p "${cache}"
......
#!/usr/bin/env bash
NDK_VERSION=android-ndk-r20
NDK_ABI_VERSION=4.9
export NDK_VERSION=android-ndk-r20
export ANDROID_NDK_ROOT="/tmp/${NDK_VERSION}"
if [ $TRAVIS_OS_NAME == "linux" ]
then
case $(uname | tr '[:upper:]' '[:lower:]') in
linux*)
HOST_PLATFORM=linux-x86_64
elif [ $TRAVIS_OS_NAME == "osx" ]
then
;;
darwin*)
HOST_PLATFORM=darwin-x86_64
else
echo "Unsupported platform $TRAVIS_OS_NAME"
;;
*)
echo "Unsupported platform"
exit 1
fi
;;
esac
if [ ! -d "/tmp/${NDK_VERSION}" ] ; then
if [ ! -d "${ANDROID_NDK_ROOT}" ]; then
export FILENAME=$NDK_VERSION-$HOST_PLATFORM.zip
(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
unset FILENAME
fi
function _build_arch {
export ANDROID_NDK_ROOT="/tmp/${NDK_VERSION}"
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
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
./build.sh "arm"
./build.sh "arm64"
./build.sh "x86"
./build.sh "x86_64"
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