Skip to content

Commit c02fdac

Browse files
Merge pull request #4062 from BOINC/mac_build_OpenSSL_arm64_x86_64
Update OpenSSL build script to build arm64 and x86_64 Universal binary
2 parents 8a08ed1 + ae1bb1a commit c02fdac

File tree

1 file changed

+41
-13
lines changed

1 file changed

+41
-13
lines changed

mac_build/buildopenssl.sh

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
# Updated 9/10/16 for openssl-1.1.0
3535
# Updated 1/25/18 for bulding openssl 1.1.0g (updated comemnts only)
3636
# Updated 1/23/19 use libc++ instead of libstdc++ for Xcode 10 compatibility
37-
# Updated 8/22/20 TO build Apple Silicon / arm64 and x86_64 Universal binary
37+
# Updated 10/20/20 To build Apple Silicon / arm64 and x86_64 Universal binary
3838
#
3939
## This script requires OS 10.8 or later
4040
#
@@ -116,6 +116,42 @@ if [ "${doclean}" != "yes" ]; then
116116
fi
117117
fi
118118

119+
## openssl 1.1.0g does not have a configure option for darwin arm64,
120+
## so we patch Configurations/10-main.conf to add it.
121+
## Derived from https://github.com/openssl/openssl/pull/12369/files
122+
## and https://cutecoder.org/programming/compile-open-ssl-apple-silicon/
123+
##
124+
## Note: setting perlasm_scheme to "ios64" tells configure to use
125+
## the correct assembler instructions for Apple Silicon. Setting
126+
## it to "macosx" causes it to use x86_64 assembler instructions.
127+
##
128+
if [ ! -f Configurations/10-main.conf.orig ]; then
129+
cat >> /tmp/0-main_conf_diff << ENDOFFILE
130+
--- 10-main.conf 2017-11-02 07:29:01.000000000 -0700
131+
+++ 10-main_patched.con2020-10-19 01:34:06.000000000 -0700
132+
@@ -1614,6 +1614,14 @@
133+
perlasm_scheme => "macosx",
134+
shared_ldflag => "-arch x86_64 -dynamiclib",
135+
},
136+
+ "darwin64-arm64-cc" => {
137+
+ inherit_from => [ "darwin-common", asm("aarch64_asm") ],
138+
+ CFLAGS => add("-Wall"),
139+
+ cflags => add("-arch arm64"),
140+
+ lib_cppflags => add("-DL_ENDIAN"),
141+
+ bn_ops => "SIXTY_FOUR_BIT_LONG",
142+
+ perlasm_scheme => "ios64",
143+
+ },
144+
145+
#### iPhoneOS/iOS
146+
#
147+
ENDOFFILE
148+
patch -bfi /tmp/0-main_conf_diff Configurations/10-main.conf
149+
rm -f /tmp/0-main_conf_diff
150+
else
151+
echo "Configurations/10-main.conf already patched"
152+
fi
153+
echo ""
154+
119155
GPPPATH=`xcrun -find g++`
120156
if [ $? -ne 0 ]; then
121157
echo "ERROR: can't find g++ compiler"
@@ -185,20 +221,13 @@ if [ $GCC_can_build_arm64 == "yes" ]; then
185221
export SDKROOT="${SDKPATH}"
186222
export MACOSX_DEPLOYMENT_TARGET=10.7
187223

188-
## TEMPORARY WORKAROUNDS because OpenSSL 1.1.0g has no configure option for
189-
## darwin arm64
190224
if [ "x${lprefix}" != "x" ]; then
191-
./configure --prefix=${lprefix} no-shared ios64-cross
225+
./configure --prefix=${lprefix} no-shared darwin64-arm64-cc
192226
if [ $? -ne 0 ]; then return 1; fi
193227
else
194-
./configure no-shared ios64-cross
228+
./configure no-shared darwin64-arm64-cc
195229
if [ $? -ne 0 ]; then return 1; fi
196230
fi
197-
## Patch the ios64-cross makefile to build for a Mac instead of iOS device
198-
sed -i "" 's:-arch arm64:-target arm64-apple-macos10.7 -stdlib=libc++:g' Makefile
199-
sed -i "" 's:-mios-version-min=7.0.0:-DMAC_OS_X_VERSION_MAX_ALLOWED=1070:g' Makefile
200-
sed -i "" 's:-isysroot $(CROSS_TOP)/SDKs/$(CROSS_SDK):-isysroot ${SDKROOT}:g' Makefile
201-
## END OF TEMPORARY WORKAROUNDS
202231

203232
# save x86_64 lib for later use
204233
mv -f libcrypto.a libcrypto_x86_64.a
@@ -232,9 +261,8 @@ if [ $GCC_can_build_arm64 == "yes" ]; then
232261
rm -f libcrypto_x86_64.a libcrypto_arm64.a
233262
rm -f libssl_x86_64.a libssl_arm64.a
234263

235-
## openssl 1.1.0g does not have a configure option for darwin arm64, so we use
236-
## the same configure as for ios64-cross with some patches and hope it works
237-
## properly.
264+
## openssl 1.1.0g does not have a configure option for darwin arm64, so we
265+
## patched Configurations/10-main.conf to add it.
238266
## NOTE: At the time of writing, I do not have an arm64 Mac to test with.
239267
# Revisit this if a newer version of openssl becomes available.
240268
#

0 commit comments

Comments
 (0)