From 308c94e9d8f8e0c5cc107fcbb02ed3d90c1eb625 Mon Sep 17 00:00:00 2001 From: "Guilloux Stephan (Ubuntu)" Date: Fri, 18 Nov 2022 17:10:43 +0100 Subject: [PATCH 01/11] Problem: android_download_ndk can be more 'autonomous'. --- builds/android/android_build_helper.sh | 50 +++++++++++++++----------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/builds/android/android_build_helper.sh b/builds/android/android_build_helper.sh index 272c3598..01bf31d0 100644 --- a/builds/android/android_build_helper.sh +++ b/builds/android/android_build_helper.sh @@ -81,8 +81,30 @@ function android_download_ndk { ANDROID_BUILD_FAIL+=(" $(dirname "${ANDROID_NDK_ROOT}/")") fi - if [ -z "${ANDROID_NDK_FILENAME}" ] ; then - ANDROID_BUILD_FAIL+=("Please set the ANDROID_NDK_FILENAME environment variable") + local platform="$(uname | tr '[:upper:]' '[:lower:]')" + local filename + case "${platform}" in + linux*) + if [ "${NDK_NUMBER}" -ge 2300 ] ; then + # Since NDK 23, NDK archives are renamed. + filename=${NDK_VERSION}-linux.zip + else + filename=${NDK_VERSION}-linux-x86_64.zip + fi + ;; + darwin*) + if [ "${NDK_NUMBER}" -ge 2300 ] ; then + # Since NDK 23, NDK archives are renamed. + filename=${NDK_VERSION}-darwin.zip + else + filename=${NDK_VERSION}-darwin-x86_64.zip + fi + ;; + *) android_build_trace "Unsupported platform ('${platform}')" ; exit 1 ;; + esac + + if [ -z "${filename}" ] ; then + ANDROID_BUILD_FAIL+=("Unable to detect NDK filename.") fi android_build_check_fail @@ -90,14 +112,14 @@ function android_download_ndk { android_build_trace "Downloading NDK '${NDK_VERSION}'..." ( cd "$(dirname "${ANDROID_NDK_ROOT}")" \ - && rm -f "${ANDROID_NDK_FILENAME}" \ - && wget -q "http://dl.google.com/android/repository/${ANDROID_NDK_FILENAME}" -O "${ANDROID_NDK_FILENAME}" \ - && android_build_trace "Extracting NDK '${ANDROID_NDK_FILENAME}'..." \ - && unzip -q "${ANDROID_NDK_FILENAME}" \ + && rm -f "${filename}" \ + && wget -q "http://dl.google.com/android/repository/${filename}" -O "${filename}" \ + && android_build_trace "Extracting NDK '${filename}'..." \ + && unzip -q "${filename}" \ && android_build_trace "NDK extracted under '${ANDROID_NDK_ROOT}'." ) || { ANDROID_BUILD_FAIL+=("Failed to install NDK ('${NDK_VERSION}')") - ANDROID_BUILD_FAIL+=(" ${ANDROID_NDK_FILENAME}") + ANDROID_BUILD_FAIL+=(" ${filename}") } android_build_check_fail @@ -106,24 +128,12 @@ function android_download_ndk { function android_build_set_env { BUILD_ARCH=$1 - platform="$(uname | tr '[:upper:]' '[:lower:]')" + local platform="$(uname | tr '[:upper:]' '[:lower:]')" case "${platform}" in linux*) - if [ "${NDK_NUMBER}" -ge 2300 ] ; then - # Since NDK 23, NDK archives are renamed. - export ANDROID_NDK_FILENAME=${NDK_VERSION}-linux.zip - else - export ANDROID_NDK_FILENAME=${NDK_VERSION}-linux-x86_64.zip - fi export ANDROID_BUILD_PLATFORM=linux-x86_64 ;; darwin*) - if [ "${NDK_NUMBER}" -ge 2300 ] ; then - # Since NDK 23, NDK archives are renamed. - export ANDROID_NDK_FILENAME=${NDK_VERSION}-darwin.zip - else - export ANDROID_NDK_FILENAME=${NDK_VERSION}-darwin-x86_64.zip - fi export ANDROID_BUILD_PLATFORM=darwin-x86_64 ;; *) android_build_trace "Unsupported platform ('${platform}')" ; exit 1 ;; From f91e3e41fa2005aa6b690cfcb15fd4a2d18b45fa Mon Sep 17 00:00:00 2001 From: "Guilloux Stephan (Ubuntu)" Date: Fri, 18 Nov 2022 17:21:08 +0100 Subject: [PATCH 02/11] Problem: android_clone_library() review Basically, only local vars renamed. New coming functions will use the same local vars naming. --- builds/android/android_build_helper.sh | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/builds/android/android_build_helper.sh b/builds/android/android_build_helper.sh index 01bf31d0..3e18cd44 100644 --- a/builds/android/android_build_helper.sh +++ b/builds/android/android_build_helper.sh @@ -457,19 +457,19 @@ function android_show_configure_opts { function android_clone_library { local tag="$1" ; shift - local clone_root="$1" ; shift - local clone_url="$1" ; shift - local clone_branch="$1" ; shift + local root="$1" ; shift + local url="$1" ; shift + local branch="$1" ; shift - mkdir -p "$(dirname "${clone_root}")" - if [ -n "${clone_branch}" ] ; then - android_build_trace "Cloning '${clone_url}' (branch '${clone_branch}') under '${clone_root}'." - git clone --quiet --depth 1 -b "${clone_branch}" "${clone_url}" "${clone_root}" + mkdir -p "$(dirname "${root}")" + if [ -n "${branch}" ] ; then + android_build_trace "Cloning '${url}' (branch '${branch}') under '${root}'." + git clone --quiet --depth 1 -b "${branch}" "${url}" "${root}" else - android_build_trace "Cloning '${clone_url}' (default branch) under '${clone_root}'." - git clone --quiet --depth 1 "${clone_url}" "${clone_root}" + android_build_trace "Cloning '${url}' (default branch) under '${root}'." + git clone --quiet --depth 1 "${url}" "${root}" fi - ( cd "${clone_root}" && git log --oneline -n 1) || exit 1 + ( cd "${root}" && git log --oneline -n 1) || exit 1 } # Caller must set CONFIG_OPTS before call. From 3aeadbd1c270f4d541bd9b57ea15daf49783e58d Mon Sep 17 00:00:00 2001 From: "Guilloux Stephan (Ubuntu)" Date: Fri, 18 Nov 2022 17:27:16 +0100 Subject: [PATCH 03/11] Problem: android_build_library can be more robust & generic With these changes, this function is now able to build LIBZMQ but also (almost) CZMQ, ZYRE (and their dependencies) in native or cross compilation modes. --- builds/android/android_build_helper.sh | 50 ++++++++++++++++++-------- 1 file changed, 35 insertions(+), 15 deletions(-) diff --git a/builds/android/android_build_helper.sh b/builds/android/android_build_helper.sh index 3e18cd44..c60d7424 100644 --- a/builds/android/android_build_helper.sh +++ b/builds/android/android_build_helper.sh @@ -472,29 +472,49 @@ function android_clone_library { ( cd "${root}" && git log --oneline -n 1) || exit 1 } -# Caller must set CONFIG_OPTS before call. +# Caller must set CONFIG_OPTS[], before call. function android_build_library { local tag=$1 ; shift - local clone_root=$1 ; shift + local root=$1 ; shift android_build_trace "Cleaning library '${tag}'." ( - cd "${clone_root}" \ - && ( make clean || : ) && \ - rm -f config.status - ) || exit 1 + if [ -n "${ANDROID_BUILD_PREFIX}" ] && [ -d "${ANDROID_BUILD_PREFIX}" ] ; then + # Remove *.la files as they might cause errors with cross compiled libraries + find "${ANDROID_BUILD_PREFIX}" -name '*.la' -exec rm {} + + fi + cd "${root}" \ + && ( make clean || : ) \ + && rm -f config.status + ) &> /dev/null + + android_build_trace "Building library '${tag}'." ( - # Remove *.la files as they might cause errors with cross compiled libraries - find "${ANDROID_BUILD_PREFIX}" -name '*.la' -exec rm {} + + set -e - cd "${clone_root}" \ - && ./autogen.sh \ - && android_show_configure_opts "${tag}" "${CONFIG_OPTS[@]}" \ - && ./configure "${CONFIG_OPTS[@]}" \ - && make -j 4 \ - && make install - ) || exit 1 + android_show_configure_opts "${tag}" "${CONFIG_OPTS[@]}" + + cd "${root}" + if [ -e autogen.sh ]; then + ./autogen.sh 2> /dev/null + fi + if [ -e buildconf ]; then + ./buildconf 2> /dev/null + fi + if [ ! -e autogen.sh ] && [ ! -e buildconf ] && [ ! -e ./configure ] && [ -s ./configure.ac ] ; then + libtoolize --copy --force && \ + aclocal -I . && \ + autoheader && \ + automake --add-missing --copy && \ + autoconf || \ + autoreconf -fiv + fi + + ./configure "${CONFIG_OPTS[@]}" + make -j 4 + make install + ) } ######################################################################## From 91bc18ee16a9c523f828ba20b6ccd21f2596faca Mon Sep 17 00:00:00 2001 From: "Guilloux Stephan (Ubuntu)" Date: Fri, 18 Nov 2022 17:31:00 +0100 Subject: [PATCH 04/11] Enriched Android helpers 2 more functions are added: - android_clone_library(): Similar to android_clone_library(), but fetch a tarball and uncompress it. So far, only .tar.gz and .tgz archives are supported, but could be enhanced easily, if needed. - android_init_dependency_root(): Initialize or check XXX_ROOT, when XXX is a dependency name. Enhanced version of init_android_root() in build.sh (to be dropped, then). This version is now also applicable in CZMQ & ZYRE CI builds scripts for Android. --- builds/android/android_build_helper.sh | 66 ++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/builds/android/android_build_helper.sh b/builds/android/android_build_helper.sh index c60d7424..0b150b01 100644 --- a/builds/android/android_build_helper.sh +++ b/builds/android/android_build_helper.sh @@ -455,6 +455,72 @@ function android_show_configure_opts { echo "" } +# Initialize env variable XXX_ROOT, given dependency name "xxx". +# If XXX_ROOT is not set: +# If ${PROJECT_ROOT}/../xxx exists +# set XXX_ROOT with it. +# Else +# set XXX_ROOT with /tmp/tmp-deps/xxx. +# Else +# Verify that folder XXX_ROOT exists. +function android_init_dependency_root { + local lib_name + lib_name="$1" + local variable_name + variable_name="$(echo "${lib_name}" | tr '[:lower:]' '[:upper:]')_ROOT" + local variable_value + variable_value="$(eval echo "\${${variable_name}}")" + + if [ -z "${PROJECT_ROOT}" ] ; then + android_build_trace "Error: Variable PROJECT_ROOT is not set." + exit 1 + fi + if [ ! -d "${PROJECT_ROOT}" ] ; then + android_build_trace "Error: Cannot find folder '${PROJECT_ROOT}'." + exit 1 + fi + + if [ -z "${variable_value}" ] ; then + if [ -d "${PROJECT_ROOT}/../${lib_name}" ] ; then + eval "export ${variable_name}=\"$(cd "${PROJECT_ROOT}/../${lib_name}" && pwd)\"" + else + eval "export ${variable_name}=\"/tmp/tmp-deps/${lib_name}\"" + fi + variable_value="$(eval echo "\${${variable_name}}")" + elif [ ! -d "${variable_value}" ] ; then + android_build_trace "Error: Folder '${variable_value}' does not exist." + exit 1 + fi + + android_build_trace "${variable_name}=${variable_value}" +} + +function android_download_library { + local tag="$1" ; shift + local root="$1" ; shift + local url="$1" ; shift + local parent="$(dirname "${root}")" + local archive="$(basename "${url}")" + + mkdir -p "${parent}" + cd "${parent}" + + android_build_trace "Downloading ${tag} from '${url}' ..." + rm -f "${archive}" + wget -q "${url}" + case "${archive}" in + *."tar.gz" ) folder="$(basename "${archive}" ".tar.gz")" ;; + *."tgz" ) folder="$(basename "${archive}" ".tgz")" ;; + * ) android_build_trace "Unsupported extension for '${archive}'." ; exit 1 ;; + esac + android_build_trace "Extracting '${archive}' ..." + tar -xzf "${archive}" + if [ ! -d "${root}" ] ; then + mv "${folder}" "${root}" + fi + android_build_trace "${tag} extracted under under '${root}'." +} + function android_clone_library { local tag="$1" ; shift local root="$1" ; shift From 30e950abfd234268956713f9df1406ec4a6c1c8c Mon Sep 17 00:00:00 2001 From: "Guilloux Stephan (Ubuntu)" Date: Fri, 18 Nov 2022 17:49:00 +0100 Subject: [PATCH 05/11] Problem: Android dependencies are downloaded in an hard-coded /tmp/tmp-deps. Solution: Added variable ANDROID_DEPENDENCIES_DIR, and initialize to /tmp/tmp-deps, to avoid clash with existing code. --- builds/android/android_build_helper.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/builds/android/android_build_helper.sh b/builds/android/android_build_helper.sh index 0b150b01..5d6cf12f 100644 --- a/builds/android/android_build_helper.sh +++ b/builds/android/android_build_helper.sh @@ -460,7 +460,7 @@ function android_show_configure_opts { # If ${PROJECT_ROOT}/../xxx exists # set XXX_ROOT with it. # Else -# set XXX_ROOT with /tmp/tmp-deps/xxx. +# set XXX_ROOT with ${ANDROID_DEPENDENCIES_DIR}/xxx. # Else # Verify that folder XXX_ROOT exists. function android_init_dependency_root { @@ -484,7 +484,7 @@ function android_init_dependency_root { if [ -d "${PROJECT_ROOT}/../${lib_name}" ] ; then eval "export ${variable_name}=\"$(cd "${PROJECT_ROOT}/../${lib_name}" && pwd)\"" else - eval "export ${variable_name}=\"/tmp/tmp-deps/${lib_name}\"" + eval "export ${variable_name}=\"${ANDROID_DEPENDENCIES_DIR}/${lib_name}\"" fi variable_value="$(eval echo "\${${variable_name}}")" elif [ ! -d "${variable_value}" ] ; then @@ -592,6 +592,9 @@ if [ -z "$ANDROID_BUILD_DIR" ]; then ANDROID_BUILD_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" fi +# Where to download our dependencies +export ANDROID_DEPENDENCIES_DIR="${ANDROID_DEPENDENCIES_DIR:-/tmp/tmp-deps}" + # Set up a variable to hold the global failure reasons, separated by newlines # (Empty string indicates no failure) ANDROID_BUILD_FAIL=() From 40620f9b7bb270847aee6f6ff1072f79a7fca3f4 Mon Sep 17 00:00:00 2001 From: "Guilloux Stephan (Ubuntu)" Date: Fri, 18 Nov 2022 17:54:34 +0100 Subject: [PATCH 06/11] Android helpers minor fixes. --- builds/android/android_build_helper.sh | 30 ++++++++++++++------------ 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/builds/android/android_build_helper.sh b/builds/android/android_build_helper.sh index 5d6cf12f..d47a905d 100644 --- a/builds/android/android_build_helper.sh +++ b/builds/android/android_build_helper.sh @@ -31,6 +31,7 @@ # ### # +# Courtesy of Joe Eli McIlvain; original code at: # https://github.com/jemc/android_build_helper # android_build_helper.sh # @@ -43,9 +44,11 @@ # To get the latest version of this script, please download from: # https://github.com/jemc/android_build_helper # -# You are free to modify this script, but if you add improvements, -# please consider submitting a pull request to the aforementioned upstream -# repository for the benefit of other users. +# You are free to modify and redistribute this script, but if you add +# improvements, please consider submitting a pull request or patch to the +# aforementioned upstream repository for the benefit of other users. +# +# This script is provided with no express or implied warranties. # ######################################################################## @@ -81,8 +84,10 @@ function android_download_ndk { ANDROID_BUILD_FAIL+=(" $(dirname "${ANDROID_NDK_ROOT}/")") fi - local platform="$(uname | tr '[:upper:]' '[:lower:]')" + android_build_check_fail + local filename + local platform="$(uname | tr '[:upper:]' '[:lower:]')" case "${platform}" in linux*) if [ "${NDK_NUMBER}" -ge 2300 ] ; then @@ -167,9 +172,9 @@ function android_build_set_env { # Since NDK r22 the "platforms" dir got removed if [ -d "${ANDROID_NDK_ROOT}/platforms" ]; then - export ANDROID_BUILD_SYSROOT="${ANDROID_NDK_ROOT}/platforms/android-${MIN_SDK_VERSION}/arch-${TOOLCHAIN_ARCH}" + export ANDROID_BUILD_SYSROOT="${ANDROID_NDK_ROOT}/platforms/android-${MIN_SDK_VERSION}/arch-${TOOLCHAIN_ARCH}" else - export ANDROID_BUILD_SYSROOT="${ANDROID_BUILD_TOOLCHAIN}/sysroot" + export ANDROID_BUILD_SYSROOT="${ANDROID_BUILD_TOOLCHAIN}/sysroot" fi export ANDROID_BUILD_PREFIX="${ANDROID_BUILD_DIR}/prefix/${TOOLCHAIN_ARCH}" @@ -177,10 +182,10 @@ function android_build_set_env { export ANDROID_STL="libc++_shared.so" if [ -x "${ANDROID_NDK_ROOT}/sources/cxx-stl/llvm-libc++/libs/${TOOLCHAIN_ABI}/${ANDROID_STL}" ] ; then export ANDROID_STL_ROOT="${ANDROID_NDK_ROOT}/sources/cxx-stl/llvm-libc++/libs/${TOOLCHAIN_ABI}" - else + else export ANDROID_STL_ROOT="${ANDROID_BUILD_SYSROOT}/usr/lib/${TOOLCHAIN_HOST}" - # NDK 25 requires -L ... + # NDK 25 requires -L ... # I don't understand why, but without it, ./configure fails to build a valid 'conftest'. export ANDROID_LIBC_ROOT="${ANDROID_BUILD_SYSROOT}/usr/lib/${TOOLCHAIN_HOST}/${MIN_SDK_VERSION}" fi @@ -589,7 +594,7 @@ function android_build_library { # Get directory of current script (if not already set) # This directory is also the basis for the build directories the get created. if [ -z "$ANDROID_BUILD_DIR" ]; then - ANDROID_BUILD_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + export ANDROID_BUILD_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" fi # Where to download our dependencies @@ -602,13 +607,10 @@ ANDROID_BUILD_FAIL=() ######################################################################## # Sanity checks ######################################################################## -if [ -z "${NDK_VERSION}" ] ; then - android_build_trace "NDK_VERSION not set !" - exit 1 -fi case "${NDK_VERSION}" in "android-ndk-r"[0-9][0-9] ) : ;; "android-ndk-r"[0-9][0-9][a-z] ) : ;; + "" ) android_build_trace "Variable NDK_VERSION not set." ; exit 1 ;; * ) android_build_trace "Invalid format for NDK_VERSION ('${NDK_VERSION}')" ; exit 1 ;; esac @@ -621,7 +623,7 @@ fi # Compute NDK version into a numeric form: # android-ndk-r21e -> 2105 # android-ndk-r25 -> 2500 -######################################################################## +######################################################################## export NDK_NUMBER="$(( $(echo "${NDK_VERSION}"|sed -e 's|android-ndk-r||g' -e 's|[a-z]||g') * 100 ))" NDK_VERSION_LETTER="$(echo "${NDK_VERSION}"|sed -e 's|android-ndk-r[0-9][0-9]||g'|tr '[:lower:]' '[:upper:]')" if [ -n "${NDK_VERSION_LETTER}" ] ; then From ebe0edaaa91b06d2f2929d157c2439408724ada0 Mon Sep 17 00:00:00 2001 From: "Stephan Guilloux (home)" Date: Sun, 20 Nov 2022 00:19:06 +0100 Subject: [PATCH 07/11] More enhancements and configuration variables to Android CI build scripts. init_dependency_root(): Moved to android_build_helper.sh ANDROID_DEPENDENCIES_DIR: added to specify a storage for dependencies when downloaded automatically. ANDROID_BUILD_DIR: Changed the default in ci_build.sh. ci_build.sh configures these 2 variables to no more use /tmp by default ( except for Android NDK), but a local clone subfolder. This helps to find downloaded dependencies and generated binaries. This avoid to have user permission conflicts, or conflicts with 2 different clones of LIBZMQ (for instance). --- builds/android/build.sh | 86 ++++++++++++++++---------------------- builds/android/ci_build.sh | 17 +++++--- 2 files changed, 48 insertions(+), 55 deletions(-) diff --git a/builds/android/build.sh b/builds/android/build.sh index 8f2ce485..251754bb 100755 --- a/builds/android/build.sh +++ b/builds/android/build.sh @@ -1,10 +1,11 @@ #!/usr/bin/env bash - +# +# Exit if any step fails set -e # Use directory of current script as the working directory cd "$( dirname "${BASH_SOURCE[0]}" )" -LIBZMQ_ROOT="$(cd ../.. && pwd)" +PROJECT_ROOT="$(cd ../.. && pwd)" ######################################################################## # Configuration & tuning options. @@ -25,8 +26,14 @@ export MIN_SDK_VERSION=${MIN_SDK_VERSION:-21} # ${ANDROID_BUILD_DIR}/prefix//lib will contain produced libraries export ANDROID_BUILD_DIR="${ANDROID_BUILD_DIR:-${PWD}}" +# Where to download our dependencies: default to /tmp/tmp-deps +export ANDROID_DEPENDENCIES_DIR="${ANDROID_DEPENDENCIES_DIR:-/tmp/tmp-deps}" + # Clean before processing -export ANDROID_BUILD_CLEAN="${ANDROID_BUILD_CLEAN:-}" +export ANDROID_BUILD_CLEAN="${ANDROID_BUILD_CLEAN:-no}" + +# Set this to 'no', to enable verbose ./configure +export CI_CONFIG_QUIET="${CI_CONFIG_QUIET:-no}" # Select CURVE implementation: # - "" # Do not use any CURVE implementation. @@ -34,12 +41,21 @@ export ANDROID_BUILD_CLEAN="${ANDROID_BUILD_CLEAN:-}" # - "tweetnacl" # Use internal TWEETNACL implementation. export CURVE="${CURVE:-}" +# By default, dependencies will be cloned to /tmp/tmp-deps. +# If you have your own source tree for LIBSODIUM, uncomment +# the line below, and provide its absolute path: +# export LIBSODIUM_ROOT="" + ######################################################################## # Utilities ######################################################################## +# Get access to android_build functions and variables +# Perform some sanity checks and calculate some variables. +source "${PROJECT_ROOT}/builds/android/android_build_helper.sh" + function usage { echo "LIBZMQ - Usage:" - echo " export XXX=yyy" + echo " export XXX=xxx" echo " ./build.sh [ arm | arm64 | x86 | x86_64 ]" echo "" echo "See this file (configuration & tuning options) for details" @@ -47,35 +63,6 @@ function usage { exit 1 } -# Initialize env variable XXX_ROOT, given dependency name "xxx". -# If XXX_ROOT is not set: -# If a folder xxx exists close to current clone, set XXX_ROOT with it. -# Else, set XXX_ROOT with /tmp/tmp-deps/xxx. -# Else -# Verify that folder XXX_ROOT exists. -function init_dependency_root { - local lib_name - lib_name="$1" - local variable_name - variable_name="$(echo "${lib_name}" | tr '[:lower:]' '[:upper:]')_ROOT" - local variable_value - variable_value="$(eval echo "\${${variable_name}}")" - - if [ -z "${variable_value}" ] ; then - if [ -d "${LIBZMQ_ROOT}/../${lib_name}" ] ; then - eval "export ${variable_name}=\"$(cd "${LIBZMQ_ROOT}/../${lib_name}" && pwd)\"" - else - eval "export ${variable_name}=\"/tmp/tmp-deps/${lib_name}\"" - fi - variable_value="$(eval echo "\${${variable_name}}")" - elif [ ! -d "${variable_value}" ] ; then - echo "LIBZMQ - Error: Folder '${variable_value}' does not exist." - exit 1 - fi - - echo "LIBZMQ - ${variable_name}=${variable_value}" -} - ######################################################################## # Sanity checks ######################################################################## @@ -84,7 +71,8 @@ BUILD_ARCH="$1" # Set ROOT path for LIBSODIUM source tree, if CURVE is "libsodium" if [ "${CURVE}x" = "libsodiumx" ] ; then - init_dependency_root "libsodium" + # Check or initialize LIBSODIUM_ROOT + android_init_dependency_root "libsodium" fi ######################################################################## @@ -96,10 +84,6 @@ export ANDROID_BUILD_CXXSTL="gnustl_shared_49" # Additional flags for LIBTOOL, for LIBZMQ and other dependencies. export LIBTOOL_EXTRA_LDFLAGS='-avoid-version' -# Get access to android_build functions and variables -# Perform some sanity checks and calculate some variables. -source ./android_build_helper.sh - # Set up android build environment and set ANDROID_BUILD_OPTS array android_build_set_env "${BUILD_ARCH}" android_download_ndk @@ -107,20 +91,20 @@ android_build_env android_build_opts # Check for environment variable to clear the prefix and do a clean build -if [[ $ANDROID_BUILD_CLEAN ]]; then +if [ "${ANDROID_BUILD_CLEAN}" = "yes" ]; then android_build_trace "Doing a clean build (removing previous build and dependencies)..." - rm -rf "${ANDROID_BUILD_PREFIX:-android-build-prefix-not-set}"/* + rm -rf "${ANDROID_BUILD_PREFIX:?}"/* # Called shells MUST not clean after ourselves ! - export ANDROID_BUILD_CLEAN="" + export ANDROID_BUILD_CLEAN="no" fi -VERIFY=("libzmq.so") +DEPENDENCIES=() if [ -z "${CURVE}" ]; then CURVE="--disable-curve" elif [ "${CURVE}" == "libsodium" ]; then CURVE="--with-libsodium=yes" - VERIFY+=("libsodium.so") + DEPENDENCIES+=("libsodium.so") ## # Build LIBSODIUM from latest STABLE branch @@ -131,8 +115,9 @@ elif [ "${CURVE}" == "libsodium" ]; then ( CONFIG_OPTS=() - CONFIG_OPTS+=("--quiet") + [ "${CI_CONFIG_QUIET}" = "yes" ] && CONFIG_OPTS+=("--quiet") CONFIG_OPTS+=("${ANDROID_BUILD_OPTS[@]}") + CONFIG_OPTS+=("--without-docs") CONFIG_OPTS+=("--disable-soname-versions") android_build_library "LIBSODIUM" "${LIBSODIUM_ROOT}" @@ -146,17 +131,15 @@ fi ## # Build libzmq from local source -(android_build_verify_so "${VERIFY[@]}" &> /dev/null) || { - (cd "${LIBZMQ_ROOT}" && ( make clean || : ) && rm -f ./config.status ) || exit 1 - +(android_build_verify_so "libzmq.so" "${DEPENDENCIES[@]}" &> /dev/null) || { ( CONFIG_OPTS=() - CONFIG_OPTS+=("--quiet") + [ "${CI_CONFIG_QUIET}" = "yes" ] && CONFIG_OPTS+=("--quiet") CONFIG_OPTS+=("${ANDROID_BUILD_OPTS[@]}") CONFIG_OPTS+=("${CURVE}") CONFIG_OPTS+=("--without-docs") - android_build_library "LIBZMQ" "${LIBZMQ_ROOT}" + android_build_library "LIBZMQ" "${PROJECT_ROOT}" ) || exit 1 } @@ -167,6 +150,9 @@ cp "${ANDROID_STL_ROOT}/${ANDROID_STL}" "${ANDROID_BUILD_PREFIX}/lib/." ## # Verify shared libraries in prefix +for library in "libzmq.so" "${DEPENDENCIES[@]}" ; do + android_build_verify_so "${library}" +done -android_build_verify_so "${VERIFY[@]}" "${ANDROID_STL}" +android_build_verify_so "libzmq.so" "${DEPENDENCIES[@]}" "${ANDROID_STL}" android_build_trace "Android build successful" diff --git a/builds/android/ci_build.sh b/builds/android/ci_build.sh index d6b2aca4..4cb27ad4 100755 --- a/builds/android/ci_build.sh +++ b/builds/android/ci_build.sh @@ -10,13 +10,20 @@ cd "$( dirname "${BASH_SOURCE[0]}" )" export NDK_VERSION="${NDK_VERSION:-android-ndk-r25}" export ANDROID_NDK_ROOT="${ANDROID_NDK_ROOT:-/tmp/${NDK_VERSION}}" export MIN_SDK_VERSION=${MIN_SDK_VERSION:-21} -export ANDROID_BUILD_DIR="${ANDROID_BUILD_DIR:-${PWD}}" +export ANDROID_BUILD_DIR="${ANDROID_BUILD_DIR:-${PWD}/.build}" +export ANDROID_BUILD_CLEAN="${ANDROID_BUILD_CLEAN:-yes}" +export ANDROID_DEPENDENCIES_DIR="${ANDROID_DEPENDENCIES_DIR:-${PWD}/.deps}" # Cleanup. -rm -rf /tmp/android_build/ -rm -rf "${PWD}/prefix" -rm -rf /tmp/tmp-deps -mkdir -p /tmp/tmp-deps +if [ "${ANDROID_BUILD_CLEAN}" = "yes" ] ; then + rm -rf "${ANDROID_BUILD_DIR}/prefix" + mkdir -p "${ANDROID_BUILD_DIR}/prefix" + rm -rf "${ANDROID_DEPENDENCIES_DIR}" + mkdir -p "${ANDROID_DEPENDENCIES_DIR}" + + # Called shells MUST not clean after ourselves ! + export ANDROID_BUILD_CLEAN="no" +fi ./build.sh "arm" ./build.sh "arm64" From 9f47e064a1d627bd5db02a8dbfabe77504c68368 Mon Sep 17 00:00:00 2001 From: "Stephan Guilloux (home)" Date: Sun, 20 Nov 2022 00:26:38 +0100 Subject: [PATCH 08/11] Documentation update. --- builds/android/README.md | 72 +++++++++++++++++++++++++++++++++++----- 1 file changed, 64 insertions(+), 8 deletions(-) diff --git a/builds/android/README.md b/builds/android/README.md index aa5ac7d9..273aaba5 100644 --- a/builds/android/README.md +++ b/builds/android/README.md @@ -6,10 +6,24 @@ The last known NDK is automatically downloaded, if not specified otherwise. ## Configuration -This project is tested against Android NDK version r25, but should +Basically, LIBZMQ build for Android, relies on exported variables. +Provided build scripts can mainly be used like + +### Basics + + export XXX=xxx + export YYY=yyy + ... + cd /builds/android + ./ + + +### Android NDK + +LIBZMQ is tested against Android NDK version r25, but should support older ones too. -This project uses NDK `android-ndk-r25`, by default, but you can specify +By default, LIBZMQ uses NDK `android-ndk-r25`, but you can specify a different one: export NDK_VERSION=android-ndk-r23c @@ -18,7 +32,7 @@ If you already have installed your favorite NDK somewhere, all you have to do is to export and set NDK_VERSION and ANDROID_NDK_ROOT environment variables, e.g: - export NDK_VERSION=android-ndk-r23b + export NDK_VERSION="android-ndk-r23b" export ANDROID_NDK_ROOT=$HOME/${NDK_VERSION} **Important:** ANDROID_NDK_ROOT must be an absolute path ! @@ -38,14 +52,34 @@ To specify the build directory set the environment variable below: **Important:** ANDROID_BUILD_ROOT must be an absolute path ! -All libraries will be generated under: +### Android build folder + +All Android libraries will be generated under: ${ANDROID_BUILD_DIR}/prefix//lib -where <_arch_> is one of `arm`, `arm64`, `x86` or `x86_64`. +where is one of `arm`, `arm64`, `x86` or `x86_64`. -You can also check configuration variables in `build.sh` itself, in its -"Configuration & tuning options" comment block. +### Android build cleanup + +You can build your own Android libraries, and place them under +${ANDROID_BUILD_DIR}/prefix//lib, but then, you'll need to +indicate the build scripts to not clean this folder, with the +help of ANDROID_BUILD_CLEAN + + ANDROID_BUILD_CLEAN=no + +### Dependencies + +By default, dependencies are stored under /tmp/tmp-deps, but you +can specify another folder with the help of ANDROID_DEPENDENCIES: + + ANDROID_DEPENDENCIES_DIR=${HOME}/my_dependencies + +If you place your own dependency source trees there, you'll need +to specify ANDROID_BUILD_CLEAN=no too. + +### Cryptographic configuration The variable CURVE accepts 3 different values: @@ -53,6 +87,11 @@ The variable CURVE accepts 3 different values: "libsodium" : LIBZMQ is built with LIBSODIUM encryption support (see below). "tweetnacl" : LIBZMQ is build with embedded encryption support. +### Other configuration variables + +You can also check configuration variables in `build.sh` itself, in its +"Configuration & tuning options" comment block. + ## LIBSODIUM LIBSODIUM is built along with LIBZMQ, when CURVE="libsodium". @@ -69,7 +108,7 @@ official STABLE branch. See chapter [Configuration](#configuration) for configuration options and other details. -Select your prefered parameters: +Select your preferred parameters: export XXX=xxx export YYY=yyy @@ -77,11 +116,28 @@ Select your prefered parameters: And, in the android directory, run: + cd /builds/android ./build.sh [ arm | arm64 | x86 | x86_64 ] Parameter selection and the calls to build.sh can be located in a SHELL script, like in ci_build.sh. +## CI build + +Basically, it will call build.sh once, for each Android target. + +This script accepts the same configuration variables, but some are set +with different default values. For instance, the dependencies are not +downloaded or cloned in /tmp/tmp-deps, but inside LIBZMQ clone. + +It can be used in the same way than build.sh + + export XXX=xxx + export YYY=yyy + cd /builds/android + ./ci_build.sh + + ## Dockerfile An example of Docker file is provided, for Ubuntu 22.04 From 117ddabd0201a19ca20b48533248ee3d9d900e85 Mon Sep 17 00:00:00 2001 From: "Stephan Guilloux (cos)" Date: Mon, 21 Nov 2022 11:23:47 +0100 Subject: [PATCH 09/11] Android minor fix in documentation. --- builds/android/README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/builds/android/README.md b/builds/android/README.md index 273aaba5..7c566e6e 100644 --- a/builds/android/README.md +++ b/builds/android/README.md @@ -6,11 +6,12 @@ The last known NDK is automatically downloaded, if not specified otherwise. ## Configuration -Basically, LIBZMQ build for Android, relies on exported variables. -Provided build scripts can mainly be used like - ### Basics +Basically, LIBZMQ build for Android, relies on exported variables. + +Provided build scripts can mainly be used like + export XXX=xxx export YYY=yyy ... From fcd519ba665d30f4b3dfa790b6b7b0aa4f7ca73e Mon Sep 17 00:00:00 2001 From: "Stephan Guilloux (cos)" Date: Mon, 21 Nov 2022 12:15:38 +0100 Subject: [PATCH 10/11] Android specific documentation update. --- builds/android/README.md | 43 +++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/builds/android/README.md b/builds/android/README.md index 7c566e6e..4969cb6c 100644 --- a/builds/android/README.md +++ b/builds/android/README.md @@ -1,9 +1,11 @@ # Android Build -## Prerequisites +## Preamble The last known NDK is automatically downloaded, if not specified otherwise. +As indicated in the main [README](../../README.md#supported-platforms-with-primary-CI), Android support is still DRAFT. + ## Configuration ### Basics @@ -21,8 +23,7 @@ Provided build scripts can mainly be used like ### Android NDK -LIBZMQ is tested against Android NDK version r25, but should -support older ones too. +LIBZMQ is tested against Android NDK versions r19 to r25. By default, LIBZMQ uses NDK `android-ndk-r25`, but you can specify a different one: @@ -63,22 +64,32 @@ where is one of `arm`, `arm64`, `x86` or `x86_64`. ### Android build cleanup -You can build your own Android libraries, and place them under -${ANDROID_BUILD_DIR}/prefix//lib, but then, you'll need to -indicate the build scripts to not clean this folder, with the -help of ANDROID_BUILD_CLEAN +Build and Dependency storage folders are automatically cleaned, +by ci_build.sh. This can be avoided with the help of - ANDROID_BUILD_CLEAN=no + ANDROID_BUILD_DIR="no" + +If you turn this to "no", make sure to clean what has to be, before +calling `build.sh` or `ci_build.sh`. + +### Prebuilt Android libraries + +Android prebuilt libraries have to be stored under + + ANDROID_BUILD_DIR/prefix//lib + +Do not forget to disable [Android cleanup](#android-build-cleanup). ### Dependencies -By default, dependencies are stored under /tmp/tmp-deps, but you -can specify another folder with the help of ANDROID_DEPENDENCIES: +By default, `build.sh` download dependencies under `/tmp/tmp-deps`. + +You can specify another folder with the help of ANDROID_DEPENDENCIES_DIR: ANDROID_DEPENDENCIES_DIR=${HOME}/my_dependencies -If you place your own dependency source trees there, you'll need -to specify ANDROID_BUILD_CLEAN=no too. +If you place your own dependency source trees there, +do not forget to disable [Android cleanup](#android-build-cleanup). ### Cryptographic configuration @@ -115,7 +126,7 @@ Select your preferred parameters: export YYY=yyy ... -And, in the android directory, run: +and run: cd /builds/android ./build.sh [ arm | arm64 | x86 | x86_64 ] @@ -125,13 +136,13 @@ SHELL script, like in ci_build.sh. ## CI build -Basically, it will call build.sh once, for each Android target. +Basically, it will call `build.sh` once, for each Android target. This script accepts the same configuration variables, but some are set with different default values. For instance, the dependencies are not -downloaded or cloned in /tmp/tmp-deps, but inside LIBZMQ clone. +downloaded or cloned in `/tmp/tmp-deps, but inside LIBZMQ clone. -It can be used in the same way than build.sh +It can be used in the same way as build.sh export XXX=xxx export YYY=yyy From 684ebb2616083a81bc8c5dbf4a843804af2cde75 Mon Sep 17 00:00:00 2001 From: "Stephan Guilloux (cos)" Date: Mon, 21 Nov 2022 12:15:59 +0100 Subject: [PATCH 11/11] Problem: Main documentation refers to Android NDK 24, when 25 is currently in use. Solution: Fix invalid NDK reference. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8f567227..b256936c 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ of platforms, where libzmq has been successfully compiled on. | OS and version | Architecture | Compiler and version | Build system | Remarks | |----------------------------------------|-------------------------|-------------------------------|--------------|---------------------------------------------------------------------------------------------------------------------------------------| -| Android NDK r24 | arm, arm64, x86, x86_64 | llvm (see NDK) | autotools | DRAFT | +| Android NDK r25 | 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 |