Skip to content

Commit

Permalink
Add WatchOS targets to build script
Browse files Browse the repository at this point in the history
Squash commits by ezathashim <[email protected]>
  • Loading branch information
keeshux committed Sep 26, 2019
1 parent 9639db6 commit 78a70f6
Show file tree
Hide file tree
Showing 17 changed files with 135 additions and 25 deletions.
Empty file modified Gemfile
100644 → 100755
Empty file.
Empty file modified Gemfile.lock
100644 → 100755
Empty file.
Empty file modified LICENSE
100644 → 100755
Empty file.
Empty file modified OPENSSL-LICENSE
100644 → 100755
Empty file.
Empty file modified OpenSSL-Apple.podspec.template
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion README.md
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Empty file modified assets/AppleTV/Info.plist
100644 → 100755
Empty file.
Empty file modified assets/MacOSX/Info.plist
100644 → 100755
Empty file.
24 changes: 24 additions & 0 deletions assets/WatchOS/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>openssl</string>
<key>CFBundleIdentifier</key>
<string>org.openssl.OpenSSL</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>openssl</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>MinimumOSVersion</key>
<string>4.0</string>
</dict>
</plist>
Empty file modified assets/iPhone/Info.plist
100644 → 100755
Empty file.
47 changes: 39 additions & 8 deletions build-libssl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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:-}"
Expand All @@ -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})"
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -202,6 +207,7 @@ CONFIG_DISABLE_BITCODE=""
CONFIG_NO_DEPRECATED=""
MACOS_SDKVERSION=""
IOS_SDKVERSION=""
WATCHOS_SDKVERSION=""
LOG_VERBOSE=""
PARALLEL=""
TARGETS=""
Expand Down Expand Up @@ -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
Expand All @@ -255,6 +261,10 @@ case $i in
TVOS_SDKVERSION="${i#*=}"
shift
;;
--watchos-sdk=*)
WATCHOS_SDKVERSION="${i#*=}"
shift
;;
-v|--verbose)
LOG_VERBOSE="verbose"
;;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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"
Expand All @@ -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/"

Expand Down Expand Up @@ -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"
Expand All @@ -583,4 +615,3 @@ if [ ${#OPENSSLCONF_ALL[@]} -gt 1 ]; then
fi

echo "Done."

32 changes: 31 additions & 1 deletion config/20-all-platforms.conf
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
? '-fembed-bitcode' : (); },
),
},

## Base settings for iOS
"ios-cross-base" => {
inherit_from => [ "all-base" ],
Expand All @@ -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" => {
Expand Down
24 changes: 14 additions & 10 deletions create-openssl-framework.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

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
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 [ $FWTYPE == "dynamic" ]; then
Expand Down Expand Up @@ -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
Expand Down
Empty file modified include/LICENSE
100644 → 100755
Empty file.
Empty file modified include/opensslconf-template.h
100644 → 100755
Empty file.
24 changes: 19 additions & 5 deletions scripts/build-loop-archs.sh
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -65,18 +71,23 @@ 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
if [[ "${PLATFORM}" == AppleTV* ]]; then
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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
7 changes: 7 additions & 0 deletions scripts/build-loop-targets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 78a70f6

Please sign in to comment.