From 78a70f645d30a7572a19804623adc747432eace7 Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Thu, 26 Sep 2019 09:39:59 +0200 Subject: [PATCH] Add WatchOS targets to build script Squash commits by ezathashim --- Gemfile | 0 Gemfile.lock | 0 LICENSE | 0 OPENSSL-LICENSE | 0 OpenSSL-Apple.podspec.template | 0 README.md | 2 +- assets/AppleTV/Info.plist | 0 assets/MacOSX/Info.plist | 0 assets/WatchOS/Info.plist | 24 +++++++++++++++++ assets/iPhone/Info.plist | 0 build-libssl.sh | 47 ++++++++++++++++++++++++++++------ config/20-all-platforms.conf | 32 ++++++++++++++++++++++- create-openssl-framework.sh | 22 +++++++++------- include/LICENSE | 0 include/opensslconf-template.h | 0 scripts/build-loop-archs.sh | 24 +++++++++++++---- scripts/build-loop-targets.sh | 7 +++++ 17 files changed, 134 insertions(+), 24 deletions(-) mode change 100644 => 100755 Gemfile mode change 100644 => 100755 Gemfile.lock mode change 100644 => 100755 LICENSE mode change 100644 => 100755 OPENSSL-LICENSE mode change 100644 => 100755 OpenSSL-Apple.podspec.template mode change 100644 => 100755 README.md mode change 100644 => 100755 assets/AppleTV/Info.plist mode change 100644 => 100755 assets/MacOSX/Info.plist create mode 100755 assets/WatchOS/Info.plist mode change 100644 => 100755 assets/iPhone/Info.plist mode change 100644 => 100755 config/20-all-platforms.conf mode change 100644 => 100755 include/LICENSE mode change 100644 => 100755 include/opensslconf-template.h mode change 100755 => 100644 scripts/build-loop-archs.sh diff --git a/Gemfile b/Gemfile old mode 100644 new mode 100755 diff --git a/Gemfile.lock b/Gemfile.lock old mode 100644 new mode 100755 diff --git a/LICENSE b/LICENSE old mode 100644 new mode 100755 diff --git a/OPENSSL-LICENSE b/OPENSSL-LICENSE old mode 100644 new mode 100755 diff --git a/OpenSSL-Apple.podspec.template b/OpenSSL-Apple.podspec.template old mode 100644 new mode 100755 diff --git a/README.md b/README.md old mode 100644 new mode 100755 index 8f00d3e..eff4c92 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ This is a fork of the popular work by [Felix Schulze](https://github.com/x2on), that is a set of scripts for using self-compiled builds of the OpenSSL library on the iPhone and the Apple TV. -However, this repository focuses more on framework-based setups and also adds macOS support. +However, this repository focuses more on framework-based setups and also adds macOS and watchOS support. # Compile library diff --git a/assets/AppleTV/Info.plist b/assets/AppleTV/Info.plist old mode 100644 new mode 100755 diff --git a/assets/MacOSX/Info.plist b/assets/MacOSX/Info.plist old mode 100644 new mode 100755 diff --git a/assets/WatchOS/Info.plist b/assets/WatchOS/Info.plist new file mode 100755 index 0000000..b5d8c76 --- /dev/null +++ b/assets/WatchOS/Info.plist @@ -0,0 +1,24 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + openssl + CFBundleIdentifier + org.openssl.OpenSSL + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + openssl + CFBundlePackageType + FMWK + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + MinimumOSVersion + 4.0 + + diff --git a/assets/iPhone/Info.plist b/assets/iPhone/Info.plist old mode 100644 new mode 100755 diff --git a/build-libssl.sh b/build-libssl.sh index 266c0a8..7bc5af8 100755 --- a/build-libssl.sh +++ b/build-libssl.sh @@ -30,13 +30,14 @@ DEFAULTVERSION="1.1.0i" # Default (=full) set of architectures (OpenSSL <= 1.0.2) or targets (OpenSSL >= 1.1.0) to build #DEFAULTARCHS="ios_x86_64 ios_arm64 ios_armv7s ios_armv7 tv_x86_64 tv_arm64 mac_x86_64" #DEFAULTTARGETS="ios-sim-cross-x86_64 ios64-cross-arm64 ios-cross-armv7s ios-cross-armv7 tvos-sim-cross-x86_64 tvos64-cross-arm64 macos64-x86_64" -DEFAULTARCHS="ios_x86_64 ios_arm64 tv_x86_64 tv_arm64 mac_x86_64" -DEFAULTTARGETS="ios-sim-cross-x86_64 ios64-cross-arm64 tvos-sim-cross-x86_64 tvos64-cross-arm64 macos64-x86_64" +DEFAULTARCHS="ios_x86_64 ios_arm64 tv_x86_64 tv_arm64 mac_x86_64 watchos_armv7k watchos_arm64_32 watchos_i386" +DEFAULTTARGETS="ios-sim-cross-x86_64 ios64-cross-arm64 tvos-sim-cross-x86_64 tvos64-cross-arm64 macos64-x86_64 watchos-cross-armv7k watchos-cross-arm64_32 watchos-sim-cross-i386" # Minimum iOS/tvOS SDK version to build for MACOS_MIN_SDK_VERSION="10.11" IOS_MIN_SDK_VERSION="11.0" TVOS_MIN_SDK_VERSION="11.0" +WATCHOS_MIN_SDK_VERSION="4.0" # Init optional env variables (use available variable or default to empty string) CURL_OPTIONS="${CURL_OPTIONS:-}" @@ -54,7 +55,7 @@ echo_help() echo " --ios-sdk=SDKVERSION Override iOS SDK version" echo " --noparallel Disable running make with parallel jobs (make -j)" echo " --tvos-sdk=SDKVERSION Override tvOS SDK version" - #echo " --disable-bitcode Disable embedding Bitcode" + echo " --disable-bitcode Disable embedding Bitcode" echo " -v, --verbose Enable verbose logging" echo " --verbose-on-error Dump last 500 lines from log file if an error occurs (for Travis builds)" echo " --version=VERSION OpenSSL version to build (defaults to ${DEFAULTVERSION})" @@ -172,6 +173,10 @@ finish_build_loop() LIBSSL_TVOS+=("${TARGETDIR}/lib/libssl.a") LIBCRYPTO_TVOS+=("${TARGETDIR}/lib/libcrypto.a") OPENSSLCONF_SUFFIX="tvos_${ARCH}" + elif [[ "${PLATFORM}" == Watch* ]]; then + LIBSSL_WATCHOS+=("${TARGETDIR}/lib/libssl.a") + LIBCRYPTO_WATCHOS+=("${TARGETDIR}/lib/libcrypto.a") + OPENSSLCONF_SUFFIX="watchos_${ARCH}" elif [[ "${PLATFORM}" == iPhone* ]]; then LIBSSL_IOS+=("${TARGETDIR}/lib/libssl.a") LIBCRYPTO_IOS+=("${TARGETDIR}/lib/libcrypto.a") @@ -202,6 +207,7 @@ CONFIG_DISABLE_BITCODE="" CONFIG_NO_DEPRECATED="" MACOS_SDKVERSION="" IOS_SDKVERSION="" +WATCHOS_SDKVERSION="" LOG_VERBOSE="" PARALLEL="" TARGETS="" @@ -229,9 +235,9 @@ case $i in --ec-nistp-64-gcc-128) CONFIG_ENABLE_EC_NISTP_64_GCC_128="true" ;; - #--disable-bitcode) - # CONFIG_DISABLE_BITCODE="true" - # ;; + --disable-bitcode) + CONFIG_DISABLE_BITCODE="true" + ;; -h|--help) echo_help exit @@ -255,6 +261,10 @@ case $i in TVOS_SDKVERSION="${i#*=}" shift ;; + --watchos-sdk=*) + WATCHOS_SDKVERSION="${i#*=}" + shift + ;; -v|--verbose) LOG_VERBOSE="verbose" ;; @@ -349,6 +359,9 @@ fi if [ ! -n "${TVOS_SDKVERSION}" ]; then TVOS_SDKVERSION=$(xcrun -sdk appletvos --show-sdk-version) fi +if [ ! -n "${WATCHOS_SDKVERSION}" ]; then + WATCHOS_SDKVERSION=$(xcrun -sdk watchos --show-sdk-version) +fi # Determine number of cores for (parallel) build BUILD_THREADS=1 @@ -399,6 +412,7 @@ fi echo " macOS SDK: ${MACOS_SDKVERSION}" echo " iOS SDK: ${IOS_SDKVERSION}" echo " tvOS SDK: ${TVOS_SDKVERSION}" +echo " watchOS SDK: ${WATCHOS_SDKVERSION}" if [ "${CONFIG_DISABLE_BITCODE}" == "true" ]; then echo " Bitcode embedding disabled" fi @@ -481,6 +495,8 @@ LIBSSL_IOS=() LIBCRYPTO_IOS=() LIBSSL_TVOS=() LIBCRYPTO_TVOS=() +LIBSSL_WATCHOS=() +LIBCRYPTO_WATCHOS=() # Run relevant build loop (archs = 1.0 style, targets = 1.1 style) if [ "${BUILD_TYPE}" == "archs" ]; then @@ -489,7 +505,7 @@ else source "${SCRIPTDIR}/scripts/build-loop-targets.sh" fi -# Build macOS library if selected for build +#Build macOS library if selected for build if [ ${#LIBSSL_MACOS[@]} -gt 0 ]; then echo "Build library for macOS..." lipo -create ${LIBSSL_MACOS[@]} -output "${CURRENTPATH}/lib/libssl-MacOSX.a" @@ -510,6 +526,13 @@ if [ ${#LIBSSL_TVOS[@]} -gt 0 ]; then lipo -create ${LIBCRYPTO_TVOS[@]} -output "${CURRENTPATH}/lib/libcrypto-AppleTV.a" fi +# Build tvOS library if selected for build +if [ ${#LIBSSL_WATCHOS[@]} -gt 0 ]; then + echo "Build library for watchOS..." + lipo -create ${LIBSSL_WATCHOS[@]} -output "${CURRENTPATH}/lib/libssl-WatchOS.a" + lipo -create ${LIBCRYPTO_WATCHOS[@]} -output "${CURRENTPATH}/lib/libcrypto-WatchOS.a" +fi + # Copy include directory cp -R "${INCLUDE_DIR}" "${CURRENTPATH}/include/" @@ -558,6 +581,15 @@ if [ ${#OPENSSLCONF_ALL[@]} -gt 1 ]; then *_tvos_arm64.h) DEFINE_CONDITION="TARGET_OS_TV && TARGET_OS_EMBEDDED && TARGET_CPU_ARM64" ;; + *_watchos_armv7k.h) + DEFINE_CONDITION="TARGET_OS_WATCHOS && TARGET_OS_EMBEDDED && TARGET_CPU_ARMV7K" + ;; + *_watchos_arm64_32.h) + DEFINE_CONDITION="TARGET_OS_WATCHOS && TARGET_OS_EMBEDDED && TARGET_CPU_ARM64_32" + ;; + *_watchos_i386.h) + DEFINE_CONDITION="TARGET_OS_SIMULATOR && TARGET_CPU_X86 || TARGET_OS_EMBEDDED" + ;; *) # Don't run into unexpected cases by setting the default condition to false DEFINE_CONDITION="0" @@ -583,4 +615,3 @@ if [ ${#OPENSSLCONF_ALL[@]} -gt 1 ]; then fi echo "Done." - diff --git a/config/20-all-platforms.conf b/config/20-all-platforms.conf old mode 100644 new mode 100755 index 81bbb09..c888c19 --- a/config/20-all-platforms.conf +++ b/config/20-all-platforms.conf @@ -12,7 +12,7 @@ ? '-fembed-bitcode' : (); }, ), }, - + ## Base settings for iOS "ios-cross-base" => { inherit_from => [ "all-base" ], @@ -36,6 +36,36 @@ cflags => add(sub { defined($ENV{'MACOS_MIN_SDK_VERSION'}) ? '-mmacosx-version-min=$(MACOS_MIN_SDK_VERSION)' : '-mmacosx-version-min=10.11'; }), }, + ## Apple WatchOS + + ## Base settings for iOS + "watchos-cross-base" => { + inherit_from => [ "all-base" ], + template => 1, + cflags => add(sub { defined($ENV{'WATCH_MIN_SDK_VERSION'}) ? '-mwatchos-version-min=$(WATCH_MIN_SDK_VERSION)' : '-mwatchos-version-min=4.0'; }), + }, + + "watchos-cross-armv7k" => { + inherit_from => [ "darwin-common", "watchos-cross-base", asm("armv7_asm") ], + cflags => add("-arch armv7k -fembed-bitcode"), + defines => [ "HAVE_FORK=0" ], + sys_id => "WatchOS", + }, + + "watchos-cross-arm64_32" => { + inherit_from => [ "darwin-common", "watchos-cross-base"], + cflags => add("-arch arm64_32 -fembed-bitcode"), + defines => [ "HAVE_FORK=0" ], + sys_id => "WatchOS", + }, + + "watchos-sim-cross-i386" => { + inherit_from => [ "darwin-common", "watchos-cross-base"], + cflags => add("-arch i386 -fembed-bitcode"), + defines => [ "HAVE_FORK=0" ], + sys_id => "WatchOS", + }, + ## Apple iOS simulator (x86_64) # Based on 10-main.conf: iphoneos-cross / darwin64-x86_64-cc "ios-sim-cross-x86_64" => { diff --git a/create-openssl-framework.sh b/create-openssl-framework.sh index 2b6f6f2..05532d8 100755 --- a/create-openssl-framework.sh +++ b/create-openssl-framework.sh @@ -21,22 +21,22 @@ if [ -d $FWROOT ]; then rm -rf $FWROOT fi -ALL_SYSTEMS=("iPhone" "AppleTV" "MacOSX") +ALL_SYSTEMS=("iPhone" "AppleTV" "MacOSX" "WatchOS") function check_bitcode() { local FWDIR=$1 if [[ $FWTYPE == "dynamic" ]]; then - BITCODE_PATTERN="__LLVM" + BITCODE_PATTERN="__LLVM" else - BITCODE_PATTERN="__bitcode" - fi + BITCODE_PATTERN="__bitcode" + fi - if otool -l "$FWDIR/$FWNAME" | grep "${BITCODE_PATTERN}" >/dev/null; then - echo "INFO: $FWDIR contains Bitcode" - else - echo "INFO: $FWDIR doesn't contain Bitcode" - fi + if otool -l "$FWDIR/$FWNAME" | grep "${BITCODE_PATTERN}" >/dev/null; then + echo "INFO: $FWDIR contains Bitcode" + else + echo "INFO: $FWDIR doesn't contain Bitcode" + fi } if [ $FWTYPE == "dynamic" ]; then @@ -70,6 +70,10 @@ if [ $FWTYPE == "dynamic" ]; then MIN_SDK="-macosx_version_min 10.11" elif [[ $PLATFORM == iPhoneSimulator* ]]; then MIN_SDK="-ios_simulator_version_min 11.0" + elif [[ $PLATFORM == WatchOS* ]]; then + MIN_SDK="-watchos_version_min 4.0" + elif [[ $PLATFORM == WatchSimulator* ]]; then + MIN_SDK="-watchos_simulator_version_min 4.0" else MIN_SDK="-ios_version_min 11.0" fi diff --git a/include/LICENSE b/include/LICENSE old mode 100644 new mode 100755 diff --git a/include/opensslconf-template.h b/include/opensslconf-template.h old mode 100644 new mode 100755 diff --git a/scripts/build-loop-archs.sh b/scripts/build-loop-archs.sh old mode 100755 new mode 100644 index 9eca676..6f93a5a --- a/scripts/build-loop-archs.sh +++ b/scripts/build-loop-archs.sh @@ -26,6 +26,8 @@ do SDKVERSION=${TVOS_SDKVERSION} elif [[ "$ARCH" == mac* ]]; then SDKVERSION=${MACOS_SDKVERSION} + elif [[ "$ARCH" == watchos* ]]; then + SDKVERSION=${WATCHOS_SDKVERSION} else SDKVERSION=${IOS_SDKVERSION} fi @@ -39,6 +41,10 @@ do PLATFORM="AppleTVOS" elif [[ "${ARCH}" == "mac_x86_64" || "${ARCH}" == "mac_i386" ]]; then PLATFORM="MacOSX" + elif [[ "${ARCH}" == "watchos_arm64_32" || "${ARCH}" == "watchos_armv7k" ]]; then + PLATFORM="WatchOS" + elif [[ "${ARCH}" == "watchos_i386" ]]; then + PLATFORM="WatchSimulator" else PLATFORM="iPhoneOS" fi @@ -65,11 +71,8 @@ do esac fi - # Embed bitcode for SDK >= 9 if [ "${CONFIG_DISABLE_BITCODE}" != "true" ]; then - if [[ "${SDKVERSION}" == 9.* || "${SDKVERSION}" == [0-9][0-9].* ]]; then LOCAL_CONFIG_OPTIONS="${LOCAL_CONFIG_OPTIONS} -fembed-bitcode" - fi fi # Add platform specific config options @@ -77,6 +80,14 @@ do LOCAL_CONFIG_OPTIONS="${LOCAL_CONFIG_OPTIONS} -DHAVE_FORK=0 -mtvos-version-min=${TVOS_MIN_SDK_VERSION}" echo " Patching Configure..." LC_ALL=C sed -i -- 's/D\_REENTRANT\:iOS/D\_REENTRANT\:tvOS/' "./Configure" + elif [[ "${PLATFORM}" == WatchOS* ]]; then + LOCAL_CONFIG_OPTIONS="${LOCAL_CONFIG_OPTIONS} -DHAVE_FORK=0 -mwatchos-version-min=${WATCHOS_MIN_SDK_VERSION}" + echo " Patching Configure..." + LC_ALL=C sed -i -- 's/D\_REENTRANT\:iOS/D\_REENTRANT\:WatchOS/' "./Configure" + elif [[ "${PLATFORM}" == WatchSimulator* ]]; then + LOCAL_CONFIG_OPTIONS="${LOCAL_CONFIG_OPTIONS} -DHAVE_FORK=0 -mwatchos-version-min=${WATCHOS_MIN_SDK_VERSION}" + echo " Patching Configure..." + LC_ALL=C sed -i -- 's/D\_REENTRANT\:iOS/D\_REENTRANT\:WatchOS/' "./Configure" elif [[ "${PLATFORM}" == MacOSX* ]]; then LOCAL_CONFIG_OPTIONS="${LOCAL_CONFIG_OPTIONS} -mmacosx-version-min=${MACOS_MIN_SDK_VERSION}" else @@ -87,8 +98,10 @@ do LOCAL_CONFIG_OPTIONS="--openssldir=${TARGETDIR} ${LOCAL_CONFIG_OPTIONS}" # Determine configure target - if [ "${ARCH}" == "x86_64" ]; then + if [[ "${ARCH}" == "x86_64" ]]; then LOCAL_CONFIG_OPTIONS="darwin64-x86_64-cc no-asm ${LOCAL_CONFIG_OPTIONS}" + elif [[ "${ARCH}" == "watchos_i386" ]]; then + LOCAL_CONFIG_OPTIONS="darwin-i386-cc no-asm ${LOCAL_CONFIG_OPTIONS}" else LOCAL_CONFIG_OPTIONS="iphoneos-cross ${LOCAL_CONFIG_OPTIONS}" fi @@ -97,7 +110,7 @@ do run_configure # Only required for Darwin64 builds (-isysroot is automatically added by iphoneos-cross target) - if [ "${ARCH}" == "x86_64" ]; then + if [[ "${ARCH}" == "x86_64" || "${ARCH}" == "watchos_i386" ]]; then echo " Patching Makefile..." sed -ie "s!^CFLAG=!CFLAG=-isysroot ${CROSS_TOP}/SDKs/${CROSS_SDK} !" "Makefile" fi @@ -129,4 +142,5 @@ do # Remove source dir, add references to library files to relevant arrays # Keep reference to first build target for include file finish_build_loop + done diff --git a/scripts/build-loop-targets.sh b/scripts/build-loop-targets.sh index 886e151..0af5a21 100755 --- a/scripts/build-loop-targets.sh +++ b/scripts/build-loop-targets.sh @@ -26,6 +26,8 @@ do SDKVERSION="${TVOS_SDKVERSION}" elif [[ "${TARGET}" == macos* ]]; then SDKVERSION="${MACOS_SDKVERSION}" + elif [[ "${TARGET}" == watchos* ]]; then + SDKVERSION="${WATCHOS_SDKVERSION}" else SDKVERSION="${IOS_SDKVERSION}" fi @@ -35,6 +37,7 @@ do export MACOS_MIN_SDK_VERSION export IOS_MIN_SDK_VERSION export TVOS_MIN_SDK_VERSION + export WATCHOS_MIN_SDK_VERSION export CONFIG_DISABLE_BITCODE # Determine platform @@ -46,6 +49,10 @@ do PLATFORM="AppleTVOS" elif [[ "${TARGET}" == "macos"* ]]; then PLATFORM="MacOSX" + elif [[ "${TARGET}" == "watchos-sim-cross"* ]]; then + PLATFORM="WatchSimulator" + elif [[ "${TARGET}" == "watchos"* ]]; then + PLATFORM="WatchOS" else PLATFORM="iPhoneOS" fi