From 135fdd58396b1d7da07fa0659df87340a144cef5 Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Wed, 4 Mar 2020 12:03:20 -0500 Subject: [PATCH] Add iOS testing to Travis --- .travis.yml | 76 +++++++++- README-Travis.md | 132 ++++++++++++++--- contrib/android/install_expat.sh | 8 +- contrib/android/install_ndk.sh | 4 - contrib/android/install_openssl.sh | 6 +- contrib/android/install_tools.sh | 6 + contrib/android/setenv_android.sh | 32 ++--- contrib/ios/15-ios.conf | 41 ++++++ contrib/ios/install_expat.sh | 56 ++++++++ contrib/ios/install_openssl.sh | 44 ++++++ contrib/ios/install_tools.sh | 7 + contrib/ios/setenv_ios.sh | 221 +++++++++++++++++++++++++++++ 12 files changed, 572 insertions(+), 61 deletions(-) create mode 100755 contrib/android/install_tools.sh create mode 100644 contrib/ios/15-ios.conf create mode 100755 contrib/ios/install_expat.sh create mode 100755 contrib/ios/install_openssl.sh create mode 100755 contrib/ios/install_tools.sh create mode 100755 contrib/ios/setenv_ios.sh diff --git a/.travis.yml b/.travis.yml index 41c4b0380..31df4f6ee 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,4 @@ language: c -sudo: false git: depth: 5 @@ -80,6 +79,48 @@ jobs: compiler: clang arch: s390x dist: bionic + - os: osx + osx_image: xcode10 + name: Apple iPhone, OS X, Amd64 + compiler: clang + env: + - TEST_IOS=yes + - AUTOTOOLS_HOST=armv7-apple-ios + - OPENSSL_HOST=ios-cross + - IOS_SDK=iPhoneOS + - IOS_CPU=armv7s + - IOS_PREFIX="$HOME/iPhoneOS-$IOS_CPU" + - os: osx + osx_image: xcode10 + name: Apple iPad, OS X, Amd64 + compiler: clang + env: + - TEST_IOS=yes + - AUTOTOOLS_HOST=aarch64-apple-ios + - OPENSSL_HOST=ios64-cross + - IOS_SDK=iPhoneOS + - IOS_CPU=arm64 + - IOS_PREFIX="$HOME/iPhoneOS-$IOS_CPU" + - os: osx + osx_image: xcode10 + name: Apple TV, OS X, Amd64 + compiler: clang + env: + - TEST_IOS=yes + - AUTOTOOLS_HOST=aarch64-apple-ios + - OPENSSL_HOST=ios64-cross + - IOS_SDK=AppleTVOS + - IOS_PREFIX="$HOME/AppleTVOS" + - os: osx + osx_image: xcode10 + name: Apple Watch, OS X, Amd64 + compiler: clang + env: + - TEST_IOS=yes + - AUTOTOOLS_HOST=armv7-apple-ios + - OPENSSL_HOST=ios-cross + - IOS_SDK=WatchOS + - IOS_PREFIX="$HOME/WatchOS" - os: linux name: Android armv7a, Linux, Amd64 compiler: clang @@ -91,6 +132,7 @@ jobs: - OPENSSL_HOST=android-arm - ANDROID_CPU=armv7a - ANDROID_API=23 + - ANDROID_PREFIX="$HOME/android$ANDROID_API-$ANDROID_CPU" - ANDROID_SDK_ROOT="$HOME/android-sdk" - ANDROID_NDK_ROOT="$HOME/android-ndk" - os: linux @@ -104,6 +146,7 @@ jobs: - OPENSSL_HOST=android-arm64 - ANDROID_CPU=aarch64 - ANDROID_API=23 + - ANDROID_PREFIX="$HOME/android$ANDROID_API-$ANDROID_CPU" - ANDROID_SDK_ROOT="$HOME/android-sdk" - ANDROID_NDK_ROOT="$HOME/android-ndk" - os: linux @@ -117,6 +160,7 @@ jobs: - OPENSSL_HOST=android-x86 - ANDROID_CPU=x86 - ANDROID_API=23 + - ANDROID_PREFIX="$HOME/android$ANDROID_API-$ANDROID_CPU" - ANDROID_SDK_ROOT="$HOME/android-sdk" - ANDROID_NDK_ROOT="$HOME/android-ndk" - os: linux @@ -130,10 +174,15 @@ jobs: - OPENSSL_HOST=android-x86_64 - ANDROID_CPU=x86_64 - ANDROID_API=23 + - ANDROID_PREFIX="$HOME/android$ANDROID_API-$ANDROID_CPU" - ANDROID_SDK_ROOT="$HOME/android-sdk" - ANDROID_NDK_ROOT="$HOME/android-ndk" allow_failures: + - os: osx + name: Apple TV, OS X, Amd64 + - os: osx + name: Apple Watch, OS X, Amd64 - os: linux arch: amd64 name: Android armv7a, Linux, Amd64 @@ -162,18 +211,35 @@ script: ./configure make -j 2 make test + elif [ "$TEST_IOS" = "yes" ]; then + export AUTOTOOLS_BUILD="$(./config.guess)" + export PKG_CONFIG_PATH="$IOS_PREFIX/lib/pkgconfig" + source ./contrib/ios/setenv_ios.sh + ./contrib/ios/install_tools.sh + ./contrib/ios/install_openssl.sh + ./contrib/ios/install_expat.sh + ./configure \ + --build="$AUTOTOOLS_BUILD" --host="$AUTOTOOLS_HOST" \ + --prefix="$IOS_PREFIX" \ + --with-ssl="$IOS_PREFIX" --disable-gost \ + --with-libexpat="$IOS_PREFIX"; + make -j 2 + make install elif [ "$TEST_ANDROID" = "yes" ]; then export AUTOTOOLS_BUILD="$(./config.guess)" + export PKG_CONFIG_PATH="$ANDROID_PREFIX/lib/pkgconfig" ./contrib/android/install_ndk.sh - source ./contrib/android/setenv_android.sh "$ANDROID_CPU" + source ./contrib/android/setenv_android.sh + ./contrib/android/install_tools.sh ./contrib/android/install_openssl.sh ./contrib/android/install_expat.sh ./configure \ --build="$AUTOTOOLS_BUILD" --host="$AUTOTOOLS_HOST" \ - --prefix="$ANDROID_SYSROOT" \ - --with-ssl="$ANDROID_SYSROOT" --disable-gost \ - --with-libexpat="$ANDROID_SYSROOT"; + --prefix="$ANDROID_PREFIX" \ + --with-ssl="$ANDROID_PREFIX" --disable-gost \ + --with-libexpat="$ANDROID_PREFIX"; make -j 2 + make install elif [ "$TRAVIS_OS_NAME" = "osx" ]; then ./configure --enable-debug --disable-flto --with-ssl=/usr/local/opt/openssl/ make -j 2 diff --git a/README-Travis.md b/README-Travis.md index 9e6818a35..8f3a906bf 100644 --- a/README-Travis.md +++ b/README-Travis.md @@ -1,8 +1,10 @@ # Travis Testing -Unbound 1.10 and above leverage Travis CI to increase coverage of compilers and platforms. Compilers include Clang and GCC; while platforms include Android, Linux, and OS X on AMD64, Aarch64, PowerPC and s390x hardware. +Unbound 1.10 and above leverage Travis CI to increase coverage of compilers and platforms. Compilers include Clang and GCC; while platforms include Android, iOS, Linux, and OS X on AMD64, Aarch64, PowerPC and s390x hardware. -Android is tested on armv7a, aarch64, x86 and x86_64. Mips and Mips64 is no longer supported under current NDKs. The Android recipes build and install OpenSSL and Expat, and then builds Unbound. The testing is tailored for Android NDK-r19 and above, and includes NDK-r20 and NDK-r21. +Android is tested on armv7a, aarch64, x86 and x86_64. The Android recipes build and install OpenSSL and Expat, and then builds Unbound. The testing is tailored for Android NDK-r19 and above, and includes NDK-r20 and NDK-r21. Mips and Mips64 are not tested because they are no longer supported under current NDKs. + +iOS is tested for iPhoneOS, WatchOS and AppleTVOS. The testing uses Xcode 10.0 on OS X 10.13. The Unbound Travis configuration file `.travis.yml` does not use top-level keys like `os:` and `compiler:` so there is no matrix expansion. Instead Unbound specifies the exact job to run under the `jobs:` and `include:` keys. @@ -52,15 +54,19 @@ When the Travis script encounters a sanitizer it uses different `CFLAGS` and con if [ "$TEST_UBSAN" = "yes" ]; then export CFLAGS="-DNDEBUG -g2 -O3 -fsanitize=undefined -fno-sanitize-recover" ./configure + make -j 2 + make test elif [ "$TEST_ASAN" = "yes" ]; then export CFLAGS="-DNDEBUG -g2 -O3 -fsanitize=address" ./configure + make -j 2 + make test ... ``` ## Android builds -Travis tests Android builds for the armv7a, aarch64, x86 and x86_64 architectures. The builds are trickier than other builds for several reasons. The testing requires installation of the Android NDK and SDK, it requires a cross-compile, and requires OpenSSL and Expat prerequisites. The Android cross-compiles also require care to set the Autotools triplet, the OpenSSL triplet, the toolchain path, the tool variables, and the sysroot. The steps below detail the pieces of the Android recipes. +Travis tests Android builds for the armv7a, aarch64, x86 and x86_64 architectures. The builds are trickier than other builds for several reasons. The testing requires installation of the Android NDK and SDK, it requires a cross-compile, and requires OpenSSL and Expat prerequisites. The Android cross-compiles also require care to set the Autotools triplet, the OpenSSL triplet, the toolchain path, the tool variables, and the sysroot. The discussion below detail the steps of the Android recipes. ### ANDROID_NDK_ROOT @@ -115,52 +121,136 @@ armv8a|aarch64|arm64|arm64-v8a) CXXFLAGS="-funwind-tables -fexceptions -frtti" ``` +### Tool installation + +The fourth step installs tools needed for OpenSSL, Expat and Unbound. This step is handled in by the script `contrib/android/install_tools.sh`. The tools include curl, tar, zip, unzip and java. + +If you are working from a developer machine you probably already have the necessary tools installed. + ### OpenSSL and Expat -OpenSSL and Expat are built for Android using the scripts `contrib/android/install_openssl.sh` and `contrib/android/install_expat.sh`. The scripts download, configure and install the latest release version of the libraries. The libraries are configured with `--prefix="$ANDROID_SYSROOT"` so the output artifacts are placed in the sysroot `$ANDROID_SYSROOT/usr/lib` directory. (Also see *Developer Workstation* section below). +The fifth step builds OpenSSL and Expat. OpenSSL and Expat are built for Android using the scripts `contrib/android/install_openssl.sh` and `contrib/android/install_expat.sh`. The scripts download, configure and install the latest release version of the libraries. The libraries are configured with `--prefix="$ANDROID_PREFIX"` so the headers are placed in `$ANDROID_PREFIX/include` directory, and the libraries are placed in the `$ANDROID_PREFIX/lib` directory. + +`ANDROID_PREFIX` is the value `$HOME/android$ANDROID_API-$ANDROID_CPU`. The libraries will be installed in `$HOME/android23-armv7a`, `$HOME/android23-aarch64`, etc. For Autotools projects, the appropriate `PKG_CONFIG_PATH` is exported. A typical `PKG_CONFIG_PATH` is `$HOME/android23-armv7a/lib/pkgconfig`. -OpenSSL also uses a custom configuration file called `15-android.conf`. It is a copy of the OpenSSL's project file and located at `contrib/android/15-android.conf`. The Unbound version is copied to the OpenSSL source files after unpacking the OpenSSL distribution. The Unbound version has legacy NDK support removed and some other fixes, like `ANDROID_NDK_ROOT` awareness. The changes mean Unbound's `15-android.conf` will only work with Unbound and with NDK-r19 and above. +OpenSSL also uses a custom configuration file called `15-android.conf`. It is a copy of the OpenSSL's project file and located at `contrib/android/15-android.conf`. The Unbound version is copied to the OpenSSL source files after unpacking the OpenSSL distribution. The Unbound version has legacy NDK support removed and some other fixes, like `ANDROID_NDK_ROOT` awareness. The changes mean Unbound's `15-android.conf` will only work with Unbound, with NDK-r19 and above, and a properly set environment. OpenSSL is configured with `no-engine`. If you want to include OpenSSL engines then edit `contrib/android/install_openssl.sh` and remove the config option. ### Android build -Once all the variables are set and OpenSSL and Expat are built, then the Travis script configures and builds Unbound. The recipe looks as follows. +Finally, once OpenSSL and Expat are built, then the Travis script configures and builds Unbound. The recipe looks as follows. ``` elif [ "$TEST_ANDROID" = "yes" ]; then export AUTOTOOLS_BUILD="$(./config.guess)" + export PKG_CONFIG_PATH="$ANDROID_PREFIX/lib/pkgconfig" ./contrib/android/install_ndk.sh - source ./contrib/android/setenv_android.sh "$ANDROID_CPU" + source ./contrib/android/setenv_android.sh + ./contrib/android/install_tools.sh ./contrib/android/install_openssl.sh ./contrib/android/install_expat.sh ./configure \ --build="$AUTOTOOLS_BUILD" --host="$AUTOTOOLS_HOST" \ - --prefix="$ANDROID_SYSROOT" \ - --with-ssl="$ANDROID_SYSROOT" --disable-gost \ - --with-libexpat="$ANDROID_SYSROOT"; + --prefix="$ANDROID_PREFIX" \ + --with-ssl="$ANDROID_PREFIX" --disable-gost \ + --with-libexpat="$ANDROID_PREFIX"; make -j 2 + make install ``` Travis only smoke tests an Android build using a compile and link. The self tests are not run. TODO: figure out how to fire up an emulator, push the tests to the device and run them. -Note the `--prefix="$ANDROID_SYSROOT"` used by OpenSSL, Expat and Unbound. This is a hack that makes it easy to find libraries and headers because `CFLAGS` and `CXXFLAGS` already use `--sysroot="$ANDROID_SYSROOT"`. By performing a `make install` and installing into `$ANDROID_SYSROOT`, all the libraries needed by Unbound are present without extra flags or searching. (Also see *Developer Workstation* section below). - ### Android flags -`contrib/android/setenv_android.sh` uses specific flags for `CFLAGS` and `CXXFLAGS`. The flags are not arbitrary, and they are taken from the `ndk-build` tool. It is important to use the same flags across projects to avoid subtle problems due to mixing and matching different flags. +`contrib/android/setenv_android.sh` uses specific flags for `CFLAGS` and `CXXFLAGS`. They are taken from `ndk-build`, so we consider them the official flag set. It is important to use the same flags across projects to avoid subtle problems due to mixing and matching different flags. -`CXXFLAGS` includes `-fexceptions` and `-frtti` because exceptions and runtime type info are disabled by default. `CFLAGS` include `-funwind-tables` and `-fexceptions` to ensure C++ exceptions pass through C code, if needed. Also see `docs/CPLUSPLUS—SUPPORT.html` in the NDK docs. +`CXXFLAGS` includes `-fexceptions` and `-frtti` because exceptions and runtime type info are disabled by default. `CFLAGS` include `-funwind-tables` and `-fexceptions` to ensure C++ exceptions pass through C code, if needed. Also see `docs/CPLUSPLUS-SUPPORT.html` in the NDK docs. To inspect the flags used by `ndk-build` for a platform clone ASOP's [ndk-samples](https://github.com/android/ndk-samples/tree/master/hello-jni) and build the `hello-jni` project. Use the `V=1` flag to see the full compiler output from `ndk-build`. -### Developer workstation +## iOS builds + +Travis tests iOS builds for the armv7a. armv7s and aarch64 architectures for iPhoneOS, iPhoneOS, AppleTV and WatchOS.iPhone OS is tested using both 32-bit builds (iPhones) and 64-bit builds (iPads). The builds are trickier than other builds for several reasons. The testing requires a cross-compile, and requires OpenSSL and Expat prerequisites. The iOS cross-compiles also require care to set the Autotools triplet, the OpenSSL triplet, the toolchain path, the tool variables, and the sysroot. The discussion below detail the steps of the iOS recipes. + +### iOS environment + +The first step sets the iOS cross-compile environment using the script `contrib/ios/setenv_ios.sh`. The script is `sourced` so the variables in the script are available to the calling shell. The script sets variables like `CC`, `CXX`, `AS` and `AR`; sets `CFLAGS` and `CXXFLAGS`; sets a `sysroot` so iOS headers and libraries are found; and adds the path to the toolchain to `PATH`. + +`contrib/ios/setenv_ios.sh` knows which toolchain and architecture to select by inspecting environmental variables set by Travis for the job. In particular, the variables `IOS_SDK` and `IOS_CPU` tell `contrib/ios/setenv_ios.sh` what tools and libraries to select. For example, below is part of the Aarch64 recipe. + +``` +os: osx +osx_image: xcode10 +name: Apple iPhone, OS X, Amd64 +compiler: clang +env: + - TEST_IOS=yes + - AUTOTOOLS_HOST=armv7-apple-ios + - OPENSSL_HOST=ios-cross + - IOS_SDK=iPhoneOS + - IOS_CPU=armv7s +``` + +The `contrib/ios/setenv_ios.sh` script specifies the tools in a `case` statement like the following. There is a case for each of the architectures armv7a, aarch64, x86 and x86_64. + +``` +iphone|iphoneos) + CPP="cpp" + CC="clang" + CXX="clang++" + LD="ld" + AS="as" + AR="ar" + RANLIB="ranlib" + STRIP="strip" + + # Default armv7. Also allowed armv7a, armv7s, arm64 + if [ -z "$IOS_CPU" ]; then IOS_CPU=armv7; fi + + CFLAGS="-arch $IOS_CPU -mios-version-min=6" + CXXFLAGS="-arch $IOS_CPU -stdlib=libc++ -mios-version-min=6" +``` + +### Tool installation + +The second step installs tools needed for OpenSSL, Expat and Unbound. This step is handled in by the script `contrib/ios/install_tools.sh`. The tools include autotools, curl and perl. + +If you are working from a developer machine you probably already have the necessary tools installed. + +### OpenSSL and Expat + +The third step builds OpenSSL and Expat. OpenSSL and Expat are built for iOS using the scripts `contrib/ios/install_openssl.sh` and `contrib/ios/install_expat.sh`. The scripts download, configure and install the latest release version of the libraries. The libraries are configured with `--prefix="$IOS_PREFIX"` so the headers are placed in `$IOS_PREFIX/include` directory, and the libraries are placed in the `$IOS_PREFIX/lib` directory. + +`IOS_PREFIX` is the value `$HOME/iPhoneOS-$IOS_CPU`, `$HOME/AppleTVOS` or `$HOME/WatchOS`. So the libraries will be installed in `$HOME/iPhoneOS-armv7s`, `$HOME/iPhoneOS-arm64`, etc. For Autotools projects, the appropriate `PKG_CONFIG_PATH` is exported. A typical `PKG_CONFIG_PATH` is `$HOME/iPhoneOS-armv7s/lib/pkgconfig`. + +OpenSSL also uses a custom configuration file called `15-ios.conf`. It is a copy of the OpenSSL's project file and located at `contrib/ios/15-ios.conf`. The Unbound version is copied to the OpenSSL source files after unpacking the OpenSSL distribution. The changes mean Unbound's `15-ios.conf` will only work with Unbound and a properly set environment. + +OpenSSL is configured with `no-engine`. Engines require dynamic loading so engines are disabled permanently in the script. + +### iOS build + +Finally, once OpenSSL and Expat are built, then the Travis script configures and builds Unbound. The recipe looks as follows. + +``` +elif [ "$TEST_IOS" = "yes" ]; then + export AUTOTOOLS_BUILD="$(./config.guess)" + export PKG_CONFIG_PATH="$IOS_PREFIX/lib/pkgconfig" + source ./contrib/ios/setenv_ios.sh + ./contrib/ios/install_tools.sh + ./contrib/ios/install_openssl.sh + ./contrib/ios/install_expat.sh + ./configure \ + --build="$AUTOTOOLS_BUILD" --host="$AUTOTOOLS_HOST" \ + --prefix="$IOS_PREFIX" \ + --with-ssl="$IOS_PREFIX" --disable-gost \ + --with-libexpat="$IOS_PREFIX"; + make -j 2 + make install +``` -If you are setting up a developer workstation then `--prefix="$ANDROID_SYSROOT"` trick will not work. It will not work on a workstation because a previous install gets overwritten by the next install in `$ANDROID_SYSROOT/usr/lib`. In practice OpenSSL and Expat need to be installed in an architecture specific location. The sysroot-based locations are listed below. +Travis only smoke tests an iOS build using a compile and link. The self tests are not run. TODO: figure out how to fire up an simulator, push the tests to the device and run them. -* `$ANDROID_SYSROOT/usr/lib/aarch64-linux-android/` -* `$ANDROID_SYSROOT/usr/lib/arm-linux-androideabi/` -* `$ANDROID_SYSROOT/usr/lib/i686-linux-android/` -* `$ANDROID_SYSROOT/usr/lib/x86_64-linux-android/` +### iOS flags -A second concern is the OpenSSL header files. At least two different defines are used in the OpenSSL headers based on the architecture. The first pair of defines are `RC4_CHAR` and `RC4_INT`. The second pair of defines are `SIXTY_FOUR_BIT_LONG` and `BN_LLONG`. As with libraries, a previous install gets overwritten by the next install in `$ANDROID_SYSROOT/usr/include`. To work around the problem see [Build Multiarch OpenSSL on OS X](https://stackoverflow.com/q/25530429) on Stack Overflow. Though it is a MacOS question, the same applies to Android in this situation. +`contrib/ios/setenv_ios.sh` uses specific flags for `CFLAGS` and `CXXFLAGS`. They are taken from Xcode, so we consider them the official flag set. It is important to use the same flags across projects to avoid subtle problems due to mixing and matching different flags. diff --git a/contrib/android/install_expat.sh b/contrib/android/install_expat.sh index fa6575973..ffb22322c 100755 --- a/contrib/android/install_expat.sh +++ b/contrib/android/install_expat.sh @@ -1,9 +1,5 @@ #!/usr/bin/env bash -# install android deps -sudo apt-get -qq update -sudo apt-get -qq install --no-install-recommends curl tar - echo "Downloading Expat" if ! curl -L -k -s -o expat-2.2.9.tar.gz https://github.com/libexpat/libexpat/releases/download/R_2_2_9/expat-2.2.9.tar.gz; then @@ -22,13 +18,13 @@ fi cd expat-2.2.9 || exit 1 echo "Configuring Expat" -if ! ./configure --build="$AUTOTOOLS_BUILD" --host="$AUTOTOOLS_HOST" --prefix="$ANDROID_SYSROOT"; then +if ! ./configure --build="$AUTOTOOLS_BUILD" --host="$AUTOTOOLS_HOST" --prefix="$ANDROID_PREFIX"; then echo "Error: Failed to configure Expat" exit 1 fi # Cleanup warnings, https://github.com/libexpat/libexpat/issues/383 -echo "Fixing Makefiles..." +echo "Fixing Makefiles" (IFS="" find "$PWD" -name 'Makefile' -print | while read -r file do cp -p "$file" "$file.fixed" diff --git a/contrib/android/install_ndk.sh b/contrib/android/install_ndk.sh index 5a16f78a7..6e07b5d6c 100755 --- a/contrib/android/install_ndk.sh +++ b/contrib/android/install_ndk.sh @@ -1,9 +1,5 @@ #!/usr/bin/env bash -# install android deps -sudo apt-get -qq update -sudo apt-get -qq install --no-install-recommends curl openjdk-8-jdk zip unzip - if [ -z "$ANDROID_SDK_ROOT" ]; then echo "ERROR: ANDROID_SDK_ROOT is not a valid path. Please set it." echo "SDK root is $ANDROID_SDK_ROOT" diff --git a/contrib/android/install_openssl.sh b/contrib/android/install_openssl.sh index 58a00d21a..5a6ff13e5 100755 --- a/contrib/android/install_openssl.sh +++ b/contrib/android/install_openssl.sh @@ -1,9 +1,5 @@ #!/usr/bin/env bash -# install android deps -sudo apt-get -qq update -sudo apt-get -qq install --no-install-recommends curl tar perl - echo "Downloading OpenSSL" if ! curl -L -k -s -o openssl-1.1.1d.tar.gz https://www.openssl.org/source/openssl-1.1.1d.tar.gz; then @@ -28,7 +24,7 @@ fi echo "Configuring OpenSSL" if ! ./Configure "$OPENSSL_HOST" no-comp no-asm no-hw no-engine shared \ - "$CFLAGS" --prefix="$ANDROID_SYSROOT" --openssldir="$ANDROID_SYSROOT"; then + "$CFLAGS" --prefix="$ANDROID_PREFIX" --openssldir="$ANDROID_PREFIX"; then echo "Failed to configure OpenSSL" exit 1 fi diff --git a/contrib/android/install_tools.sh b/contrib/android/install_tools.sh new file mode 100755 index 000000000..6bf2a7eba --- /dev/null +++ b/contrib/android/install_tools.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +# This step should install tools needed for all packages - OpenSSL, Expat and Unbound +echo "Updating tools" +sudo apt-get -qq update +sudo apt-get -qq install --no-install-recommends curl tar zip unzip perl openjdk-8-jdk autoconf automake libtool pkgconfig diff --git a/contrib/android/setenv_android.sh b/contrib/android/setenv_android.sh index 915753ee0..d87a8f3e3 100755 --- a/contrib/android/setenv_android.sh +++ b/contrib/android/setenv_android.sh @@ -48,14 +48,10 @@ fi ##################################################################### -if [ "$#" -lt 1 ]; then - AOSP_ARCH=armeabi-v7a -else - AOSP_ARCH=$(tr '[:upper:]' '[:upper:]' <<< "$1") -fi +AOSP_CPU=$(tr '[:upper:]' '[:lower:]' <<< "$ANDROID_CPU") # https://developer.android.com/ndk/guides/abis.html -case "$AOSP_ARCH" in +case "$AOSP_CPU" in armeabi|armv7a|armv7-a|armeabi-v7a) CC="armv7a-linux-androideabi$ANDROID_API-clang" CXX="armv7a-linux-androideabi$ANDROID_API-clang++" @@ -109,7 +105,7 @@ case "$AOSP_ARCH" in ;; *) - echo "ERROR: Unknown architecture $1" + echo "ERROR: Unknown architecture $ANDROID_CPU" [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 ;; @@ -155,14 +151,10 @@ fi ##################################################################### -# Only modify/export PATH if AOSP_TOOLCHAIN_PATH good -if [ -d "$AOSP_TOOLCHAIN_PATH" ]; then - # And only modify PATH if AOSP_TOOLCHAIN_PATH is not present - LEN=${#AOSP_TOOLCHAIN_PATH} - SUBSTR=${PATH:0:$LEN} - if [ "$SUBSTR" != "$AOSP_TOOLCHAIN_PATH" ]; then - export PATH="$AOSP_TOOLCHAIN_PATH:$PATH" - fi +LENGTH=${#AOSP_TOOLCHAIN_PATH} +SUBSTR=${PATH:0:$LENGTH} +if [ "$SUBSTR" != "$AOSP_TOOLCHAIN_PATH" ]; then + export PATH="$AOSP_TOOLCHAIN_PATH:$PATH" fi ##################################################################### @@ -176,11 +168,11 @@ export CXXFLAGS="-D__ANDROID_API__=$ANDROID_API $CXXFLAGS --sysroot=$AOSP_SYSROO echo "AOSP_TOOLCHAIN_PATH: $AOSP_TOOLCHAIN_PATH" -echo "CC: $CC" -echo "CXX: $CXX" -echo "LD: $LD" -echo "AS: $AS" -echo "AR: $AR" +echo "CC: $(command -v "$CC")" +echo "CXX: $(command -v "$CXX")" +echo "LD: $(command -v "$LD")" +echo "AS: $(command -v "$AS")" +echo "AR: $(command -v "$AR")" echo "ANDROID_SYSROOT: $ANDROID_SYSROOT" diff --git a/contrib/ios/15-ios.conf b/contrib/ios/15-ios.conf new file mode 100644 index 000000000..b611210fe --- /dev/null +++ b/contrib/ios/15-ios.conf @@ -0,0 +1,41 @@ +#### iPhoneOS/iOS +# +# It takes recent enough Xcode to use following two targets. It shouldn't +# be a problem by now, but if they don't work, original targets below +# that depend on manual definition of environment variables should still +# work... +# +my %targets = ( + "ios-common" => { + template => 1, + inherit_from => [ "darwin-common" ], + sys_id => "iOS", + disable => [ "engine", "async" ], + }, + "ios-xcrun" => { + inherit_from => [ "ios-common", asm("armv4_asm") ], + perlasm_scheme => "ios32", + }, + "ios64-xcrun" => { + inherit_from => [ "ios-common", asm("aarch64_asm") ], + #bn_ops => "SIXTY_FOUR_BIT_LONG RC4_CHAR", + perlasm_scheme => "ios64", + }, + "iossimulator-xcrun" => { + inherit_from => [ "ios-common" ], + }, + + "iphoneos-cross" => { + inherit_from => [ "ios-common" ], + cflags => add("-Wall -fno-common"), + }, + "ios-cross" => { + inherit_from => [ "ios-xcrun" ], + cflags => add("-Wall -fno-common"), + }, + "ios64-cross" => { + inherit_from => [ "ios64-xcrun" ], + cppflags => add("-DSIXTY_FOUR_BIT_LONG -DRC4_CHAR"), + cflags => add("-Wall -fno-common"), + }, +); diff --git a/contrib/ios/install_expat.sh b/contrib/ios/install_expat.sh new file mode 100755 index 000000000..9471b5aff --- /dev/null +++ b/contrib/ios/install_expat.sh @@ -0,0 +1,56 @@ +#!/usr/bin/env bash + +echo "Downloading Expat" +if ! curl -L -k -s -o expat-2.2.9.tar.gz https://github.com/libexpat/libexpat/releases/download/R_2_2_9/expat-2.2.9.tar.gz; +then + echo "Failed to download Expat" + exit 1 +fi + +echo "Unpacking Expat" +rm -rf ./expat-2.2.9 +if ! tar -xf expat-2.2.9.tar.gz; +then + echo "Failed to unpack Expat" + exit 1 +fi + +cd expat-2.2.9 || exit 1 + +export PKG_CONFIG_PATH="$IOS_PREFIX/lib/pkgconfig" + +echo "Configuring Expat" +if ! ./configure \ + --build="$AUTOTOOLS_BUILD" --host="$AUTOTOOLS_HOST" \ + --prefix="$IOS_PREFIX" ; then + echo "Error: Failed to configure Expat" + cat config.log + exit 1 +fi + +# Cleanup warnings, https://github.com/libexpat/libexpat/issues/383 +echo "Fixing Makefiles" +(IFS="" find "$PWD" -name 'Makefile' -print | while read -r file +do + cp -p "$file" "$file.fixed" + sed 's|-Wduplicated-cond ||g; s|-Wduplicated-branches ||g; s|-Wlogical-op ||g' "$file" > "$file.fixed" + mv "$file.fixed" "$file" + + cp -p "$file" "$file.fixed" + sed 's|-Wrestrict ||g; s|-Wjump-misses-init ||g; s|-Wmisleading-indentation ||g' "$file" > "$file.fixed" + mv "$file.fixed" "$file" +done) + +echo "Building Expat" +if ! make; then + echo "Failed to build Expat" + exit 1 +fi + +echo "Installing Expat" +if ! make install; then + echo "Failed to install Expat" + exit 1 +fi + +exit 0 diff --git a/contrib/ios/install_openssl.sh b/contrib/ios/install_openssl.sh new file mode 100755 index 000000000..3ca41269b --- /dev/null +++ b/contrib/ios/install_openssl.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env bash + +echo "Downloading OpenSSL" +if ! curl -L -k -s -o openssl-1.1.1d.tar.gz https://www.openssl.org/source/openssl-1.1.1d.tar.gz; +then + echo "Failed to download OpenSSL" + exit 1 +fi + +echo "Unpacking OpenSSL" +rm -rf ./openssl-1.1.1d +if ! tar -xf openssl-1.1.1d.tar.gz; +then + echo "Failed to unpack OpenSSL" + exit 1 +fi + +cd openssl-1.1.1d || exit 1 + +if ! cp ../contrib/ios/15-ios.conf Configurations/; then + echo "Failed to copy OpenSSL ios config" + exit 1 +fi + +echo "Configuring OpenSSL" +if ! ./Configure "$OPENSSL_HOST" no-comp no-asm no-hw no-engine \ + "$CFLAGS" --prefix="$IOS_PREFIX" --openssldir="$IOS_PREFIX"; then + echo "Failed to configure OpenSSL" + exit 1 +fi + +echo "Building OpenSSL" +if ! make; then + echo "Failed to build OpenSSL" + exit 1 +fi + +echo "Installing OpenSSL" +if ! make install_sw; then + echo "Failed to install OpenSSL" + exit 1 +fi + +exit 0 diff --git a/contrib/ios/install_tools.sh b/contrib/ios/install_tools.sh new file mode 100755 index 000000000..af633b758 --- /dev/null +++ b/contrib/ios/install_tools.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +# This step should install tools needed for all packages - OpenSSL, Expat and Unbound +echo "Updating tools" +brew update 1>/dev/null +echo "Installing tools" +brew install autoconf automake libtool pkgconfig curl perl 1>/dev/null diff --git a/contrib/ios/setenv_ios.sh b/contrib/ios/setenv_ios.sh new file mode 100755 index 000000000..f03c1db3a --- /dev/null +++ b/contrib/ios/setenv_ios.sh @@ -0,0 +1,221 @@ +#!/usr/bin/env bash + +##################################################################### + +# Allow a user override? I think we should be doing this. The use case is: +# move /Applications/Xcode somewhere else for a side-by-side installation. +if [ -z "${XCODE_DEVELOPER-}" ]; then + XCODE_DEVELOPER=$(xcode-select -print-path 2>/dev/null) +fi + +if [ ! -d "$XCODE_DEVELOPER" ]; then + echo "ERROR: unable to find XCODE_DEVELOPER directory." + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 +fi + +# Default toolchain location +XCODE_TOOLCHAIN="$XCODE_DEVELOPER/usr/bin" + +if [ ! -d "$XCODE_TOOLCHAIN" ]; then + echo "ERROR: unable to find XCODE_TOOLCHAIN directory." + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 +fi + +# XCODE_DEVELOPER_TOP is the top of the development tools tree +XCODE_DEVELOPER_TOP="$XCODE_DEVELOPER/Platforms/$IOS_SDK.platform/Developer" + +if [ ! -d "$XCODE_DEVELOPER_TOP" ]; then + echo "ERROR: unable to find XCODE_DEVELOPER_TOP directory." + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 +fi + +# IOS_TOOLCHAIN_PATH is the location of the actual compiler tools. +if [ -d "$XCODE_DEVELOPER/Toolchains/XcodeDefault.xctoolchain/usr/bin/" ]; then + IOS_TOOLCHAIN_PATH="$XCODE_DEVELOPER/Toolchains/XcodeDefault.xctoolchain/usr/bin/" +elif [ -d "$XCODE_DEVELOPER_TOP/usr/bin/" ]; then + IOS_TOOLCHAIN_PATH="$XCODE_DEVELOPER_TOP/usr/bin/" +fi + +if [ -z "$IOS_TOOLCHAIN_PATH" ] || [ ! -d "$IOS_TOOLCHAIN_PATH" ]; then + echo "ERROR: unable to find Xcode cross-compiler tools." + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 +fi + +##################################################################### + +# XCODE_SDK is the SDK name/version being used. Adjust the list as appropriate. +# For example, remove 4.3, 6.2, and 6.1 if they are not installed. We go back to +# the 1.0 SDKs because Apple WatchOS uses low numbers, like 2.0 and 2.1. +unset XCODE_SDK +for i in $(seq -f "%.1f" 30.0 -0.1 1.0) +do + if [ -d "$XCODE_DEVELOPER/Platforms/$IOS_SDK.platform/Developer/SDKs/$IOS_SDK$i.sdk" ]; then + XCODE_SDK="$IOS_SDK$i.sdk" + break + fi +done + +# Error checking +if [ -z "$XCODE_SDK" ]; then + echo "ERROR: unable to find a SDK." + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 +fi + +IOS_SYSROOT="$XCODE_DEVELOPER_TOP/SDKs/$XCODE_SDK" + +if [ -z "$IOS_SYSROOT" ] || [ ! -d "$IOS_SYSROOT" ]; then + echo "ERROR: unable to find IOS_SYSROOT directory." + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 +fi + +##################################################################### + +XCODE_SDK=$(tr '[:upper:]' '[:lower:]' <<< "$IOS_SDK") + +case "$XCODE_SDK" in + iphone|iphoneos) + CPP="cpp" + CC="clang" + CXX="clang++" + LD="ld" + AS="as" + AR="ar" + RANLIB="ranlib" + STRIP="strip" + + # Default armv7. Also allowed armv7a, armv7s, arm64 + if [ -z "$IOS_CPU" ]; then IOS_CPU=armv7; fi + + if [ "$IOS_CPU" = "arm64" ]; then + CFLAGS="-arch $IOS_CPU -mios-version-min=7" + CXXFLAGS="-arch $IOS_CPU -stdlib=libc++ -mios-version-min=7" + else + CFLAGS="-arch $IOS_CPU -mios-version-min=6" + CXXFLAGS="-arch $IOS_CPU -stdlib=libc++ -mios-version-min=6" + fi + ;; + + iphonesimulator) + CPP="cpp" + CC="clang" + CXX="clang++" + LD="ld" + AS="as" + AR="ar" + RANLIB="ranlib" + STRIP="strip" + + # Default i386. + if [ -z "$IOS_CPU" ]; then IOS_CPU=i386; fi + + CFLAGS="-arch $IOS_CPU -mios-version-min=5" + CXXFLAGS="-arch $IOS_CPU -stdlib=libc++ -mios-version-min=5" + ;; + + watch|watchos|applewatch) + CPP="cpp" + CC="clang" + CXX="clang++" + LD="ld" + AS="as" + AR="ar" + RANLIB="ranlib" + STRIP="strip" + + # Default armv7. Also allowed armv7a, armv7s + if [ -z "$IOS_CPU" ]; then IOS_CPU=armv7; fi + + CFLAGS="-arch $IOS_CPU -mios-version-min=7" + CXXFLAGS="-arch $IOS_CPU -stdlib=libc++ -mios-version-min=7" + ;; + + watchsimulator|watchossimulator) + CPP="cpp" + CC="clang" + CXX="clang++" + LD="ld" + AS="as" + AR="ar" + RANLIB="ranlib" + STRIP="strip" + + # Default i386. + if [ -z "$IOS_CPU" ]; then IOS_CPU=i386; fi + + CFLAGS="-arch $IOS_CPU" + CXXFLAGS="-arch $IOS_CPU -stdlib=libc++" + ;; + + appletv|appletvos) + CPP="cpp" + CC="clang" + CXX="clang++" + LD="ld" + AS="as" + AR="ar" + RANLIB="ranlib" + STRIP="strip" + + # Default arm64. + if [ -z "$IOS_CPU" ]; then IOS_CPU=arm64; fi + + CFLAGS="-arch $IOS_CPU" + CXXFLAGS="-arch $IOS_CPU -stdlib=libc++" + ;; + + appletvsimulator|appletvossimulator) + CPP="cpp" + CC="clang" + CXX="clang++" + LD="ld" + AS="as" + AR="ar" + RANLIB="ranlib" + STRIP="strip" + + # Default x86_64, + if [ -z "$IOS_CPU" ]; then IOS_CPU=x86_64; fi + + CFLAGS="-arch $IOS_CPU" + CXXFLAGS="-arch $IOS_CPU -stdlib=libc++" + ;; + + *) + echo "ERROR: Unknown architecture $IOS_SDK" + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 + ;; + +esac + +##################################################################### + +TOOLCHAIN_PATH="$IOS_TOOLCHAIN_PATH:$XCODE_TOOLCHAIN" +LENGTH=${#TOOLCHAIN_PATH} +SUBSTR=${PATH:0:$LENGTH} +if [ "$SUBSTR" != "$TOOLCHAIN_PATH" ]; then + export PATH="$TOOLCHAIN_PATH":"$PATH" +fi + +##################################################################### + +export CPP CC CXX LD AS AR RANLIB STRIP +export IOS_SYSROOT +export CFLAGS="$CFLAGS --sysroot=$IOS_SYSROOT" +export CXXFLAGS="$CXXFLAGS --sysroot=$IOS_SYSROOT" + +##################################################################### + +echo "IOS_TOOLCHAIN_PATH: $IOS_TOOLCHAIN_PATH" + +echo "CC: $(command -v "$CC")" +echo "CXX: $(command -v "$CXX")" +echo "LD: $(command -v "$LD")" +echo "AS: $(command -v "$AS")" +echo "AR: $(command -v "$AR")" + +echo "IOS_SYSROOT: $IOS_SYSROOT" + +echo "CFLAGS: $CFLAGS" +echo "CXXFLAGS: $CXXFLAGS" + +[ "$0" = "${BASH_SOURCE[0]}" ] && exit 0 || return 0 -- 2.47.2