From 895bd4761b6306b46334b80e2a4cbe2ec19addc1 Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Wed, 11 Mar 2020 17:05:19 -0400 Subject: [PATCH] Add iOS testing for Travis --- .travis.yml | 109 +++++++++++- configure.ac | 3 + contrib/android/bootstrap_ldns.sh | 2 +- contrib/android/install_tools.sh | 4 +- contrib/android/setenv_android.sh | 87 ++++++---- contrib/ios/15-ios.conf | 41 +++++ contrib/ios/bootstrap_ldns.sh | 55 ++++++ contrib/ios/install_openssl.sh | 52 ++++++ contrib/ios/install_tools.sh | 7 + contrib/ios/openssl.patch | 48 ++++++ contrib/ios/setenv_ios.sh | 274 ++++++++++++++++++++++++++++++ examples/ldns-testns.c | 8 + 12 files changed, 650 insertions(+), 40 deletions(-) create mode 100644 contrib/ios/15-ios.conf create mode 100755 contrib/ios/bootstrap_ldns.sh create mode 100755 contrib/ios/install_openssl.sh create mode 100755 contrib/ios/install_tools.sh create mode 100644 contrib/ios/openssl.patch create mode 100755 contrib/ios/setenv_ios.sh diff --git a/.travis.yml b/.travis.yml index e5e29a31..7e7cd418 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,10 +15,10 @@ addons: - indent homebrew: packages: - - gnu-indent - - doxygen - openssl - - indent + - doxygen + - findent + update: true jobs: include: @@ -97,6 +97,94 @@ jobs: arch: s390x dist: bionic env: VALGRIND=true ANALYSIS=true COVERAGE=true DOXYGEN=true + - os: osx + osx_image: xcode10.1 + name: iPhoneOS, armv7, iOS + arch: amd64 + env: + - IOS=yes + - AUTOTOOLS_HOST=armv7-apple-ios + - OPENSSL_HOST=ios-cross + - IOS_CPU=armv7s + - IOS_SDK=iPhoneOS + - IOS_PREFIX="$HOME/$IOS_SDK-$IOS_CPU" + - os: osx + osx_image: xcode10.1 + name: iPhoneOS, arm64, iOS + arch: amd64 + env: + - IOS=yes + - AUTOTOOLS_HOST=aarch64-apple-ios + - OPENSSL_HOST=ios64-cross + - IOS_CPU=arm64 + - IOS_SDK=iPhoneOS + - IOS_PREFIX="$HOME/$IOS_SDK-$IOS_CPU" + - os: osx + osx_image: xcode10.1 + name: AppleTVOS, arm64, iOS + arch: amd64 + env: + - IOS=yes + - AUTOTOOLS_HOST=aarch64-apple-ios + - OPENSSL_HOST=ios64-cross + - IOS_CPU=arm64 + - IOS_SDK=AppleTVOS + - IOS_PREFIX="$HOME/$IOS_SDK-$IOS_CPU" + - os: osx + osx_image: xcode10.1 + name: WatchOS, armv7, iOS + arch: amd64 + env: + - IOS=yes + - AUTOTOOLS_HOST=armv7-apple-ios + - OPENSSL_HOST=ios-cross + - IOS_CPU=armv7k + - IOS_SDK=WatchOS + - IOS_PREFIX="$HOME/$IOS_SDK-$IOS_CPU" + - os: osx + osx_image: xcode10.1 + name: iPhoneSimulator, i386, OS X + arch: amd64 + env: + - IOS=yes + - AUTOTOOLS_HOST=i386-apple-ios + - OPENSSL_HOST=iphoneos-cross + - IOS_CPU=i386 + - IOS_SDK=iPhoneSimulator + - IOS_PREFIX="$HOME/$IOS_SDK-$IOS_CPU" + - os: osx + osx_image: xcode10.1 + name: iPhoneSimulator, x86_64, OS X + arch: amd64 + env: + - IOS=yes + - AUTOTOOLS_HOST=x86_64-apple-ios + - OPENSSL_HOST=iphoneos-cross + - IOS_CPU=x86_64 + - IOS_SDK=iPhoneSimulator + - IOS_PREFIX="$HOME/$IOS_SDK-$IOS_CPU" + - os: osx + osx_image: xcode10.1 + name: AppleTVSimulator, x86_64, OS X + arch: amd64 + env: + - IOS=yes + - AUTOTOOLS_HOST=x86_64-apple-ios + - OPENSSL_HOST=iphoneos-cross + - IOS_CPU=x86_64 + - IOS_SDK=AppleTVSimulator + - IOS_PREFIX="$HOME/$IOS_SDK-$IOS_CPU" + - os: osx + osx_image: xcode10.1 + name: WatchSimulator, i386, OS X + arch: amd64 + env: + - IOS=yes + - AUTOTOOLS_HOST=i386-apple-ios + - OPENSSL_HOST=iphoneos-cross + - IOS_CPU=i386 + - IOS_SDK=WatchSimulator + - IOS_PREFIX="$HOME/$IOS_SDK-$IOS_CPU" - os: linux name: Android armv7a, Linux, Amd64 compiler: clang @@ -158,6 +246,8 @@ before_script: - | if [ "$ANDROID" = "yes" ]; then ./contrib/android/install_tools.sh + elif [ "$IOS" = "yes" ]; then + ./contrib/ios/install_tools.sh fi script: @@ -168,6 +258,19 @@ script: elif [ "$ASAN" = "true" ]; then export CFLAGS="-DNDEBUG -g2 -O3 -fsanitize=address" ./test/test_ci.sh + elif [ "$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_openssl.sh + ./contrib/ios/bootstrap_ldns.sh + ./configure \ + --build="$AUTOTOOLS_BUILD" --host="$AUTOTOOLS_HOST" \ + --prefix="$IOS_PREFIX" \ + --with-ssl="$IOS_PREFIX" --disable-gost \ + --with-drill --with-examples + make -j 2 + make install elif [ "$ANDROID" = "yes" ]; then export AUTOTOOLS_BUILD="$(./config.guess)" export PKG_CONFIG_PATH="$ANDROID_PREFIX/lib/pkgconfig" diff --git a/configure.ac b/configure.ac index ab885d2b..0af6f124 100644 --- a/configure.ac +++ b/configure.ac @@ -103,6 +103,9 @@ AC_CHECK_HEADERS([getopt.h time.h],,, [AC_INCLUDES_DEFAULT]) AC_CHECK_HEADERS([winsock2.h ws2tcpip.h],,, [AC_INCLUDES_DEFAULT]) # end mingw32 tests +# Check for Apple header. This uncovers TARGET_OS_IPHONE, TARGET_OS_TV or TARGET_OS_WATCH +AC_CHECK_HEADERS([TargetConditionals.h]) + ACX_DETERMINE_EXT_FLAGS_UNBOUND AC_C_INLINE diff --git a/contrib/android/bootstrap_ldns.sh b/contrib/android/bootstrap_ldns.sh index 086cde70..7e423030 100755 --- a/contrib/android/bootstrap_ldns.sh +++ b/contrib/android/bootstrap_ldns.sh @@ -14,7 +14,7 @@ echo "AUTOTOOLS_HOST: $AUTOTOOLS_HOST" echo "Running libtoolize" if [ -n "$(command -v glibtoolize)" ]; then rm -f config.guess config.sub - if ! glibtool -ci ; then + if ! glibtoolize -ci ; then echo "Failed to libtoolize (glibtoolize)" exit 1 fi diff --git a/contrib/android/install_tools.sh b/contrib/android/install_tools.sh index d2507b13..52470881 100755 --- a/contrib/android/install_tools.sh +++ b/contrib/android/install_tools.sh @@ -1,9 +1,9 @@ #!/usr/bin/env bash -# This step should install tools needed for all packages - OpenSSL and Unbound +# This step should install tools needed for all packages - OpenSSL and LDNS echo "Updating tools" sudo apt-get -qq update -sudo apt-get -qq install --no-install-recommends curl wget tar zip unzip perl openjdk-8-jdk autoconf automake libtool pkg-config +sudo apt-get -qq install --no-install-recommends curl wget tar zip unzip patch perl openjdk-8-jdk autoconf automake libtool pkg-config # Android builds run config.guess early to determine BUILD and HOST. We need to add config.guess # and config.sub now. Later, bootstrap_ldns.sh will handle the complete bootrap of LDNS. diff --git a/contrib/android/setenv_android.sh b/contrib/android/setenv_android.sh index 1b4a0ad3..f45acb0f 100755 --- a/contrib/android/setenv_android.sh +++ b/contrib/android/setenv_android.sh @@ -1,16 +1,43 @@ #!/usr/bin/env bash -# Error checking +# ==================================================================== +# Sets the cross compile environment for Android +# +# Based upon OpenSSL's setenv-android.sh by TH, JW, and SM. +# Heavily modified by JWW for Crypto++. +# Updated by Skycoder42 for current recommendations for Android. +# Modified by JWW for LDNS. +# ==================================================================== + +######################################### +##### Some validation ##### +######################################### + +if [ -z "$ANDROID_API" ]; then + echo "ANDROID_API is not set. Please set it" + [[ "$0" = "${BASH_SOURCE[0]}" ]] && exit 1 || return 1 +fi + +if [ -z "$ANDROID_CPU" ]; then + echo "ANDROID_CPU is not set. Please set it" + [[ "$0" = "${BASH_SOURCE[0]}" ]] && exit 1 || return 1 +fi + if [ ! -d "$ANDROID_NDK_ROOT" ]; then echo "ERROR: ANDROID_NDK_ROOT is not a valid path. Please set it." echo "NDK root is $ANDROID_NDK_ROOT" [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 fi +# cryptest-android.sh may run this script without sourcing. +if [ "$0" = "${BASH_SOURCE[0]}" ]; then + echo "setenv-android.sh is usually sourced, but not this time." +fi + ##################################################################### # Need to set THIS_HOST to darwin-x86_64, linux-x86_64, -# windows-x86_64 or windows. +# windows, or windows-x86_64 if [[ "$(uname -s | grep -i -c darwin)" -ne 0 ]]; then THIS_HOST=darwin-x86_64 @@ -21,38 +48,30 @@ else [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 fi -AOSP_TOOLCHAIN_ROOT="$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/$THIS_HOST" -AOSP_TOOLCHAIN_PATH="$AOSP_TOOLCHAIN_ROOT/bin" -AOSP_SYSROOT="$AOSP_TOOLCHAIN_ROOT/sysroot" - -# Error checking -if [ ! -d "$AOSP_TOOLCHAIN_ROOT" ]; then - echo "ERROR: AOSP_TOOLCHAIN_ROOT is not a valid path. Please set it." - echo "Root is $AOSP_TOOLCHAIN_ROOT" - [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 -fi +ANDROID_TOOLCHAIN="$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/$THIS_HOST/bin" +ANDROID_SYSROOT="$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/$THIS_HOST/sysroot" # Error checking -if [ ! -d "$AOSP_TOOLCHAIN_PATH" ]; then - echo "ERROR: AOSP_TOOLCHAIN_PATH is not a valid path. Please set it." - echo "Path is $AOSP_TOOLCHAIN_PATH" +if [ ! -d "$ANDROID_TOOLCHAIN" ]; then + echo "ERROR: ANDROID_TOOLCHAIN is not a valid path. Please set it." + echo "Path is $ANDROID_TOOLCHAIN" [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 fi # Error checking -if [ ! -d "$AOSP_SYSROOT" ]; then - echo "ERROR: AOSP_SYSROOT is not a valid path. Please set it." - echo "Path is $AOSP_SYSROOT" +if [ ! -d "$ANDROID_SYSROOT" ]; then + echo "ERROR: ANDROID_SYSROOT is not a valid path. Please set it." + echo "Path is $ANDROID_SYSROOT" [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 fi ##################################################################### -AOSP_CPU=$(tr '[:upper:]' '[:lower:]' <<< "$ANDROID_CPU") +THE_ARCH=$(tr '[:upper:]' '[:lower:]' <<< "$ANDROID_CPU") # https://developer.android.com/ndk/guides/abis.html -case "$AOSP_CPU" in - armeabi|armv7a|armv7-a|armeabi-v7a) +case "$THE_ARCH" in + armv7*|armeabi*) CC="armv7a-linux-androideabi$ANDROID_API-clang" CXX="armv7a-linux-androideabi$ANDROID_API-clang++" LD="arm-linux-androideabi-ld" @@ -65,7 +84,7 @@ case "$AOSP_CPU" in CXXFLAGS="-march=armv7-a -mthumb -mfloat-abi=softfp -funwind-tables -fexceptions -frtti" ;; - armv8|armv8a|aarch64|arm64|arm64-v8a) + armv8*|aarch64|arm64) CC="aarch64-linux-android$ANDROID_API-clang" CXX="aarch64-linux-android$ANDROID_API-clang++" LD="aarch64-linux-android-ld" @@ -108,53 +127,52 @@ case "$AOSP_CPU" in echo "ERROR: Unknown architecture $ANDROID_CPU" [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 ;; - esac ##################################################################### # Error checking -if [ ! -e "$AOSP_TOOLCHAIN_PATH/$CC" ]; then +if [ ! -e "$ANDROID_TOOLCHAIN/$CC" ]; then echo "ERROR: Failed to find Android clang. Please edit this script." [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 fi # Error checking -if [ ! -e "$AOSP_TOOLCHAIN_PATH/$CXX" ]; then +if [ ! -e "$ANDROID_TOOLCHAIN/$CXX" ]; then echo "ERROR: Failed to find Android clang++. Please edit this script." [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 fi # Error checking -if [ ! -e "$AOSP_TOOLCHAIN_PATH/$RANLIB" ]; then +if [ ! -e "$ANDROID_TOOLCHAIN/$RANLIB" ]; then echo "ERROR: Failed to find Android ranlib. Please edit this script." [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 fi # Error checking -if [ ! -e "$AOSP_TOOLCHAIN_PATH/$AR" ]; then +if [ ! -e "$ANDROID_TOOLCHAIN/$AR" ]; then echo "ERROR: Failed to find Android ar. Please edit this script." [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 fi # Error checking -if [ ! -e "$AOSP_TOOLCHAIN_PATH/$AS" ]; then +if [ ! -e "$ANDROID_TOOLCHAIN/$AS" ]; then echo "ERROR: Failed to find Android as. Please edit this script." [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 fi # Error checking -if [ ! -e "$AOSP_TOOLCHAIN_PATH/$LD" ]; then +if [ ! -e "$ANDROID_TOOLCHAIN/$LD" ]; then echo "ERROR: Failed to find Android ld. Please edit this script." [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 fi ##################################################################### -LENGTH=${#AOSP_TOOLCHAIN_PATH} +LENGTH=${#ANDROID_TOOLCHAIN} SUBSTR=${PATH:0:$LENGTH} -if [ "$SUBSTR" != "$AOSP_TOOLCHAIN_PATH" ]; then - export PATH="$AOSP_TOOLCHAIN_PATH:$PATH" +if [ "$SUBSTR" != "$ANDROID_TOOLCHAIN" ]; then + export PATH="$ANDROID_TOOLCHAIN:$PATH" fi ##################################################################### @@ -163,12 +181,13 @@ export CPP CC CXX LD AS AR RANLIB STRIP export ANDROID_SYSROOT="$AOSP_SYSROOT" export CPPFLAGS="-D__ANDROID_API__=$ANDROID_API" export CFLAGS="$CFLAGS --sysroot=$AOSP_SYSROOT" -export CXXFLAGS="$CXXFLAGS --sysroot=$AOSP_SYSROOT" +export CXXFLAGS="$CXXFLAGS -stdlib=libc++ --sysroot=$AOSP_SYSROOT" ##################################################################### -echo "AOSP_TOOLCHAIN_PATH: $AOSP_TOOLCHAIN_PATH" +echo "ANDROID_TOOLCHAIN: $ANDROID_TOOLCHAIN" +echo "CPP: $(command -v "$CPP")" echo "CC: $(command -v "$CC")" echo "CXX: $(command -v "$CXX")" echo "LD: $(command -v "$LD")" diff --git a/contrib/ios/15-ios.conf b/contrib/ios/15-ios.conf new file mode 100644 index 00000000..364ed6eb --- /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") ], + bn_ops => [ "BN_LLONG", "RC4_CHAR" ], + 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" ], + cflags => add("-Wall -fno-common"), + }, +); diff --git a/contrib/ios/bootstrap_ldns.sh b/contrib/ios/bootstrap_ldns.sh new file mode 100755 index 00000000..7e423030 --- /dev/null +++ b/contrib/ios/bootstrap_ldns.sh @@ -0,0 +1,55 @@ +#!/usr/bin/env bash + +if ! git submodule update --init; then + echo "Failed to init submodule" + exit 1 +fi + +echo "AUTOTOOLS_BUILD: $AUTOTOOLS_BUILD" +echo "AUTOTOOLS_HOST: $AUTOTOOLS_HOST" + +# libtool complains about our updated config.guess and config.sub. +# Remove them to get through bootstrap. Re-add them after libtoolize. + +echo "Running libtoolize" +if [ -n "$(command -v glibtoolize)" ]; then + rm -f config.guess config.sub + if ! glibtoolize -ci ; then + echo "Failed to libtoolize (glibtoolize)" + exit 1 + fi +elif [ -n "$(command -v libtoolize)" ]; then + rm -f config.guess config.sub + if ! libtoolize -ci ; then + echo "Failed to libtoolize (libtoolize)" + exit 1 + fi +else + echo "Failed to find a libtool" + exit 1 +fi + +echo "Updating config.guess" +if ! wget -q -O config.guess 'https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD'; then + echo "Failed to download config.guess" +fi + +echo "Updating config.sub" +if ! wget -q -O config.sub 'https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD'; then + echo "Failed to download config.sub" +fi + +echo "Fixing config permissions" +chmod a+x config.guess config.sub +if [ -n "$(command -v xattr 2>/dev/null)" ]; then + xattr -d com.apple.quarantine config.guess 2>/dev/null + xattr -d com.apple.quarantine config.sub 2>/dev/null +fi + +echo "Running autoreconf" +if ! autoreconf -fi ; then + echo "Failed to autoreconf" + exit 1 +fi + +exit 0 diff --git a/contrib/ios/install_openssl.sh b/contrib/ios/install_openssl.sh new file mode 100755 index 00000000..fc5af4d4 --- /dev/null +++ b/contrib/ios/install_openssl.sh @@ -0,0 +1,52 @@ +#!/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 + +# ocsp.c:947:23: error: 'fork' is unavailable: not available on tvOS +# ocsp.c:978:23: error: 'fork' is unavailable: not available on watchOS +# Also see https://github.com/openssl/openssl/issues/7607. +if ! patch -u -p0 < ../contrib/ios/openssl.patch; then + echo "Failed to patch OpenSSL" + exit 1 +fi + +echo "Configuring OpenSSL" +if ! ./Configure "$OPENSSL_HOST" -DNO_FORK no-comp no-asm no-hw no-engine no-tests no-unit-test \ + --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 00000000..df532e29 --- /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 and LDNS +echo "Updating tools" +brew update 1>/dev/null +echo "Installing tools" +brew install autoconf automake libtool pkg-config curl perl 1>/dev/null diff --git a/contrib/ios/openssl.patch b/contrib/ios/openssl.patch new file mode 100644 index 00000000..58cef232 --- /dev/null +++ b/contrib/ios/openssl.patch @@ -0,0 +1,48 @@ +--- apps/speed.c ++++ apps/speed.c +@@ -99,6 +99,13 @@ + #endif + #include + ++/* fork() breaks AppleTVOS, WatchOS, AppleTVSimulator and WatchSimulator */ ++/* Users should configure with -DNO_FORK */ ++#if defined(NO_FORK) ++# undef HAVE_FORK ++# define HAVE_FORK 0 ++#endif ++ + #ifndef HAVE_FORK + # if defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_VXWORKS) + # define HAVE_FORK 0 +@@ -110,6 +117,7 @@ + #if HAVE_FORK + # undef NO_FORK + #else ++# undef NO_FORK + # define NO_FORK + #endif + +--- apps/ocsp.c ++++ apps/ocsp.c +@@ -36,6 +36,13 @@ + # include + # include + ++/* fork() breaks AppleTVOS, WatchOS, AppleTVSimulator and WatchSimulator */ ++/* Users should configure with -DNO_FORK */ ++#if defined(NO_FORK) ++# undef HAVE_FORK ++# define HAVE_FORK 0 ++#endif ++ + #ifndef HAVE_FORK + # if defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_WINDOWS) + # define HAVE_FORK 0 +@@ -47,6 +54,7 @@ + #if HAVE_FORK + # undef NO_FORK + #else ++# undef NO_FORK + # define NO_FORK + #endif + diff --git a/contrib/ios/setenv_ios.sh b/contrib/ios/setenv_ios.sh new file mode 100755 index 00000000..8f49f328 --- /dev/null +++ b/contrib/ios/setenv_ios.sh @@ -0,0 +1,274 @@ +#!/usr/bin/env bash + +# ==================================================================== +# Sets the cross compile environment for Xcode/iOS +# +# Based upon OpenSSL's setenv-ios.sh by TH, JW, and SM. +# Heavily modified by JWW for Crypto++. +# Modified by JWW for LDNS. +# ==================================================================== + +######################################### +##### Some validation ##### +######################################### + +# In the past we could mostly infer arch or cpu from the SDK (and +# mostly vice-versa). Nowadays we need it set for us because Apple +# platforms can be either 32-bit or 64-bit. + +if [ -z "$IOS_SDK" ]; then + echo "IOS_SDK is not set. Please set it" + [[ "$0" = "${BASH_SOURCE[0]}" ]] && exit 1 || return 1 +fi + +if [ -z "$IOS_CPU" ]; then + echo "IOS_CPU is not set. Please set it" + [[ "$0" = "${BASH_SOURCE[0]}" ]] && exit 1 || return 1 +fi + +# cryptest-ios.sh may run this script without sourcing. +if [ "$0" = "${BASH_SOURCE[0]}" ]; then + echo "setenv-ios.sh is usually sourced, but not this time." +fi + +######################################### +##### Small Fixups, if needed ##### +######################################### + +if [[ "$IOS_SDK" == "iPhone" ]]; then + IOS_SDK=iPhoneOS +fi + +if [[ "$IOS_SDK" == "iPhoneOSSimulator" ]]; then + IOS_SDK=iPhoneSimulator +fi + +if [[ "$IOS_SDK" == "TV" || "$IOS_SDK" == "AppleTV" ]]; then + IOS_SDK=AppleTVOS +fi + +if [[ "$IOS_SDK" == "Watch" || "$IOS_SDK" == "AppleWatch" ]]; then + IOS_SDK=WatchOS +fi + +if [[ "$IOS_CPU" == "aarch64" || "$IOS_CPU" == "armv8"* ]] ; then + IOS_CPU=arm64 +fi + +######################################## +##### Environment ##### +######################################## + +# The flags below were tested with Xcode 8 on Travis. If +# you use downlevel versions of Xcode, then you can push +# xxx-version-min=n lower. For example, Xcode 6 can use +# -miphoneos-version-min=5. + +# iPhones can be either 32-bit or 64-bit +if [[ "$IOS_SDK" == "iPhoneOS" && "$IOS_CPU" == "armv7"* ]]; then + MIN_VER=-miphoneos-version-min=6 +elif [[ "$IOS_SDK" == "iPhoneOS" && "$IOS_CPU" == "arm64" ]]; then + MIN_VER=-miphoneos-version-min=6 + +# Fixups for convenience +elif [[ "$IOS_SDK" == "iPhoneOS" && "$IOS_CPU" == "i386" ]]; then + IOS_SDK=iPhoneSimulator + # MIN_VER=-miphoneos-version-min=6 + MIN_VER=-miphonesimulator-version-min=6 +elif [[ "$IOS_SDK" == "iPhoneOS" && "$IOS_CPU" == "x86_64" ]]; then + IOS_SDK=iPhoneSimulator + # MIN_VER=-miphoneos-version-min=6 + MIN_VER=-miphonesimulator-version-min=6 + +# Simulator builds +elif [[ "$IOS_SDK" == "iPhoneSimulator" && "$IOS_CPU" == "i386" ]]; then + MIN_VER=-miphonesimulator-version-min=6 +elif [[ "$IOS_SDK" == "iPhoneSimulator" && "$IOS_CPU" == "x86_64" ]]; then + MIN_VER=-miphonesimulator-version-min=6 + +# Apple TV can be 32-bit Intel (1st gen), 32-bit ARM (2nd, 3rd gen) or 64-bit ARM (4th gen) +elif [[ "$IOS_SDK" == "AppleTVOS" && "$IOS_CPU" == "i386" ]]; then + MIN_VER=-mappletvos-version-min=6 +elif [[ "$IOS_SDK" == "AppleTVOS" && "$IOS_CPU" == "armv7"* ]]; then + MIN_VER=-mappletvos-version-min=6 +elif [[ "$IOS_SDK" == "AppleTVOS" && "$IOS_CPU" == "arm64" ]]; then + MIN_VER=-mappletvos-version-min=6 + +# Simulator builds +elif [[ "$IOS_SDK" == "AppleTVSimulator" && "$IOS_CPU" == "i386" ]]; then + MIN_VER=-mappletvsimulator-version-min=6 +elif [[ "$IOS_SDK" == "AppleTVSimulator" && "$IOS_CPU" == "x86_64" ]]; then + MIN_VER=-mappletvsimulator-version-min=6 + +# Watch can be either 32-bit or 64-bit ARM. TODO: figure out which +# -mwatchos-version-min=n is needed for arm64. 9 is not enough. +elif [[ "$IOS_SDK" == "WatchOS" && "$IOS_CPU" == "armv7"* ]]; then + MIN_VER=-mwatchos-version-min=6 +elif [[ "$IOS_SDK" == "WatchOS" && "$IOS_CPU" == "arm64" ]]; then + MIN_VER=-mwatchos-version-min=10 + +# Simulator builds. TODO: figure out which -watchos-version-min=n +# is needed for arm64. 6 compiles and links, but is it correct? +elif [[ "$IOS_SDK" == "WatchSimulator" && "$IOS_CPU" == "i386" ]]; then + MIN_VER=-mwatchsimulator-version-min=6 +elif [[ "$IOS_SDK" == "WatchSimulator" && "$IOS_CPU" == "x86_64" ]]; then + MIN_VER=-mwatchsimulator-version-min=6 + +# And the final catch-all +else + echo "IOS_SDK and IOS_CPU are not valid. Please fix them" + [[ "$0" = "${BASH_SOURCE[0]}" ]] && exit 1 || return 1 +fi + +##################################################################### + +# Xcode 6 and below cannot handle -miphonesimulator-version-min +# Fix it so the simulator will compile as expected. This trick +# may work on other SDKs, but it was not tested. + +if [ -n "$(command -v xcodebuild 2>/dev/null)" ]; then + # Output of xcodebuild is similar to "Xcode 6.2". The first cut gets + # the dotted decimal value. The second cut gets the major version. + XCODE_VERSION=$(xcodebuild -version 2>/dev/null | head -n 1 | cut -f2 -d" " | cut -f1 -d".") + if [ -z "$XCODE_VERSION" ]; then XCODE_VERSION=100; fi + + if [ "$XCODE_VERSION" -le 6 ]; then + MIN_VER="${MIN_VER//iphonesimulator/iphoneos}" + fi +fi + +##################################################################### + +# 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 + +# XCODE_DEVELOPER_SDK is the SDK location. +XCODE_DEVELOPER_SDK="$XCODE_DEVELOPER/Platforms/$IOS_SDK.platform" + +if [ ! -d "$XCODE_DEVELOPER_SDK" ]; then + echo "ERROR: unable to find XCODE_DEVELOPER_SDK directory." + echo " Is the SDK supported by Xcode and installed?" + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 +fi + +# XCODE_TOOLCHAIN is the location of the actual compiler tools. +if [ -d "$XCODE_DEVELOPER/Toolchains/XcodeDefault.xctoolchain/usr/bin/" ]; then + XCODE_TOOLCHAIN="$XCODE_DEVELOPER/Toolchains/XcodeDefault.xctoolchain/usr/bin/" +elif [ -d "$XCODE_DEVELOPER_SDK/Developer/usr/bin/" ]; then + XCODE_TOOLCHAIN="$XCODE_DEVELOPER_SDK/Developer/usr/bin/" +fi + +if [ -z "$XCODE_TOOLCHAIN" ] || [ ! -d "$XCODE_TOOLCHAIN" ]; 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. +XCODE_SDK= +for i in $(seq -f "%.1f" 30.0 -0.1 1.0) +do + if [ -d "$XCODE_DEVELOPER_SDK/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_SDK/Developer/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 + +##################################################################### + +# We want to set AR=libtool and ARFLAGS="-static -o", +# but I am not sure Autotools can handle it. +CPP=cpp; CC=clang; CXX=clang++; LD=ld +AS=as; AR=ar; RANLIB=ranlib; STRIP=strip + +# Error checking +if [ ! -e "$XCODE_TOOLCHAIN/$CC" ]; then + echo "ERROR: Failed to find iOS clang. Please edit this script." + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 +fi + +# Error checking +if [ ! -e "$XCODE_TOOLCHAIN/$CXX" ]; then + echo "ERROR: Failed to find iOS clang++. Please edit this script." + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 +fi + +# Error checking +if [ ! -e "$XCODE_TOOLCHAIN/$RANLIB" ]; then + echo "ERROR: Failed to find iOS ranlib. Please edit this script." + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 +fi + +# Error checking +if [ ! -e "$XCODE_TOOLCHAIN/$AR" ]; then + echo "ERROR: Failed to find iOS ar. Please edit this script." + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 +fi + +# Error checking +if [ ! -e "$XCODE_TOOLCHAIN/$AS" ]; then + echo "ERROR: Failed to find iOS as. Please edit this script." + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 +fi + +# Error checking +if [ ! -e "$XCODE_TOOLCHAIN/$LD" ]; then + echo "ERROR: Failed to find iOS ld. Please edit this script." + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 +fi + +##################################################################### + +LENGTH=${#XCODE_TOOLCHAIN} +SUBSTR=${PATH:0:$LENGTH} +if [ "$SUBSTR" != "$XCODE_TOOLCHAIN" ]; then + export PATH="$XCODE_TOOLCHAIN":"$PATH" +fi + +##################################################################### + +export CPP CC CXX LD AS AR RANLIB STRIP +export IOS_SYSROOT +export CFLAGS="-arch $IOS_CPU $MIN_VER --sysroot=$IOS_SYSROOT" +export CXXFLAGS="-arch $IOS_CPU $MIN_VER -stdlib-libc++ --sysroot=$IOS_SYSROOT" + +##################################################################### + +echo "XCODE_TOOLCHAIN: $XCODE_TOOLCHAIN" + +echo "CPP: $(command -v "$CPP")" +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 "CPPFLAGS: $CPPFLAGS" +echo "CFLAGS: $CFLAGS" +echo "CXXFLAGS: $CXXFLAGS" + +[ "$0" = "${BASH_SOURCE[0]}" ] && exit 0 || return 0 diff --git a/examples/ldns-testns.c b/examples/ldns-testns.c index a44ad74d..57a2aac0 100644 --- a/examples/ldns-testns.c +++ b/examples/ldns-testns.c @@ -149,6 +149,14 @@ struct sockaddr_storage; #include #include +#ifdef HAVE_TARGETCONDITIONALS_H +#include +#endif + +#if defined(TARGET_OS_TV) || defined(TARGET_OS_WATCH) +#undef HAVE_FORK +#endif + #define INBUF_SIZE 4096 /* max size for incoming queries */ #define DEFAULT_PORT 53 /* default if no -p port is specified */ #define CONN_BACKLOG 256 /* connections queued up for tcp */ -- 2.47.3