-
Notifications
You must be signed in to change notification settings - Fork 2
/
build-ios.sh
executable file
·146 lines (118 loc) · 5.7 KB
/
build-ios.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/bin/sh
set -e
if [ -z "${1}" ]; then
echo "Usage: ${0} <OpenSSL Version>"
exit 1
fi
VERSION=$1
shift
BUILD_ARGS="$@"
############
# DOWNLOAD #
############
ARCHIVE=openssl-${VERSION}.tar.gz
if [ ! -f ${ARCHIVE} ]; then
echo "Downloading openssl ${VERSION}..."
curl -L "https://github.com/openssl/openssl/releases/download/openssl-${VERSION}/openssl-${VERSION}.tar.gz" > "${ARCHIVE}"
if [ ! -z "${GPG_VERIFY}" ]; then
echo "Verifying signature for openssl-${VERSION}.tar.gz..."
rm -f "${ARCHIVE}.asc"
curl -L "https://github.com/openssl/openssl/releases/download/openssl-${VERSION}/openssl-${VERSION}.tar.gz.asc" > "${ARCHIVE}.asc"
gpg --verify "${ARCHIVE}.asc" "${ARCHIVE}"
echo "Verified signature for ${ARCHIVE} successfully!"
fi
fi
###########
# COMPILE #
###########
BUILDDIR=build
function build() {
ARCH=${1}
HOST=${2}
SDK=${3}
SDKDIR=$(xcrun --sdk ${SDK} --show-sdk-path)
LOG="../${ARCH}-${SDK}_build.log"
echo "Building openssl for ${ARCH}-${SDK}..."
WORKDIR=openssl_${ARCH}-${SDK}
mkdir "${WORKDIR}"
tar -xzf "../${ARCHIVE}" -C "${WORKDIR}" --strip-components 1
cd "${WORKDIR}"
for FILE in $(find ../../patches -name '*.patch'); do
patch -p1 < ${FILE}
done
export CC=$(xcrun -find -sdk ${SDK} clang)
export CFLAGS="-arch ${ARCH} -pipe -Os -gdwarf-2 -isysroot ${SDKDIR} -m${SDK}-version-min=12.0"
export LDFLAGS="-arch ${ARCH} -isysroot ${SDKDIR}"
BUILD_ARGS="-no-shared -no-ui-console -no-tests -no-stdio -no-threads -no-legacy -no-ssl2 -no-ssl3 -no-asm -no-weak-ssl-ciphers ${BUILD_ARGS}"
echo "build variables: CC=\"${CC}\" CFLAGS=\"${CFLAGS}\" LDFLAGS=\"${LDFLAGS}\"" >> "${LOG}"
echo "configure parameters: ${BUILD_ARGS}" >> "${LOG}"
./configure \
$BUILD_ARGS \
--prefix=$(pwd)/artifacts \
${HOST} >> "${LOG}" 2>&1
perl configdata.pm --dump >> ../${ARCH}-${SDK}_configuration.log
make -j $(sysctl -n hw.logicalcpu_max) >> "${LOG}" 2>&1
make install >> "${LOG}" 2>&1
# Deprecated file (openssl should just remove it)
rm artifacts/include/openssl/asn1_mac.h
cd ../
}
rm -rf ${BUILDDIR}
mkdir ${BUILDDIR}
cd ${BUILDDIR}
build arm64 ios64-xcrun iphoneos
build arm64 iossimulator-xcrun iphonesimulator
build x86_64 iossimulator-xcrun iphonesimulator
cd ../
###########
# PACKAGE #
###########
# Merge the arm64 and x86_64 binaries for the simulator together
lipo \
-arch arm64 ${BUILDDIR}/openssl_arm64-iphonesimulator/artifacts/lib/libssl.a \
-arch x86_64 ${BUILDDIR}/openssl_x86_64-iphonesimulator/artifacts/lib/libssl.a \
-create -output ${BUILDDIR}/libssl.a
lipo \
-arch arm64 ${BUILDDIR}/openssl_arm64-iphonesimulator/artifacts/lib/libcrypto.a \
-arch x86_64 ${BUILDDIR}/openssl_x86_64-iphonesimulator/artifacts/lib/libcrypto.a \
-create -output ${BUILDDIR}/libcrypto.a
rm -rf libssl.xcframework
xcodebuild -create-xcframework \
-library ${BUILDDIR}/openssl_arm64-iphoneos/artifacts/lib/libssl.a -headers ${BUILDDIR}/openssl_arm64-iphoneos/artifacts/include/openssl \
-library ${BUILDDIR}/libssl.a -headers ${BUILDDIR}/openssl_arm64-iphonesimulator/artifacts/include/openssl \
-output libssl.xcframework
plutil -insert CFBundleVersion -string ${VERSION} libssl.xcframework/Info.plist
rm -rf libcrypto.xcframework
xcodebuild -create-xcframework \
-library ${BUILDDIR}/openssl_arm64-iphoneos/artifacts/lib/libcrypto.a -headers ${BUILDDIR}/openssl_arm64-iphoneos/artifacts/include/openssl \
-library ${BUILDDIR}/libcrypto.a -headers ${BUILDDIR}/openssl_arm64-iphonesimulator/artifacts/include/openssl \
-output libcrypto.xcframework
plutil -insert CFBundleVersion -string ${VERSION} libcrypto.xcframework/Info.plist
# Create a traditional .framework that combines libssl and libcrypto for each platform
rm -rf ${BUILDDIR}/iphoneos/openssl.framework ${BUILDDIR}/iphonesimulator/openssl.framework
mkdir -p ${BUILDDIR}/iphoneos/openssl.framework/Headers ${BUILDDIR}/iphonesimulator/openssl.framework/Headers
libtool -no_warning_for_no_symbols -static -o ${BUILDDIR}/iphoneos/openssl.framework/openssl ${BUILDDIR}/openssl_arm64-iphoneos/artifacts/lib/libssl.a ${BUILDDIR}/openssl_arm64-iphoneos/artifacts/lib/libcrypto.a
cp -r ${BUILDDIR}/openssl_arm64-iphoneos/artifacts/include/openssl/*.h ${BUILDDIR}/iphoneos/openssl.framework/Headers
libtool -no_warning_for_no_symbols -static -o ${BUILDDIR}/iphonesimulator/openssl.framework/openssl ${BUILDDIR}/libssl.a ${BUILDDIR}/libcrypto.a
cp -r ${BUILDDIR}/openssl_arm64-iphonesimulator/artifacts/include/openssl/*.h ${BUILDDIR}/iphonesimulator/openssl.framework/Headers
# Inject a module map so Swift can consume this
function make_modulemap {
PLATFORM=${1}
mkdir -p ${BUILDDIR}/${PLATFORM}/openssl.framework/Modules
echo "framework module OpenSSL {" > ${BUILDDIR}/${PLATFORM}/openssl.framework/Modules/module.modulemap
for HEADER in $(ls ${BUILDDIR}/${PLATFORM}/openssl.framework/Headers); do
echo " header \"${HEADER}\"" >> ${BUILDDIR}/${PLATFORM}/openssl.framework/Modules/module.modulemap
done
echo " export *" >> ${BUILDDIR}/${PLATFORM}/openssl.framework/Modules/module.modulemap
echo "}" >> ${BUILDDIR}/${PLATFORM}/openssl.framework/Modules/module.modulemap
}
if [ ! -z "${WITH_MODULE_MAP}" ]; then
make_modulemap iphoneos
make_modulemap iphonesimulator
fi
rm -rf openssl.xcframework
xcodebuild -create-xcframework \
-framework ${BUILDDIR}/iphoneos/openssl.framework \
-framework ${BUILDDIR}/iphonesimulator/openssl.framework \
-output openssl.xcframework
plutil -insert CFBundleVersion -string ${VERSION} openssl.xcframework/Info.plist