Last active
May 15, 2024 07:21
-
-
Save mbernson/8e09fa53de0fa1c942b0a26f6f0e8c7c to your computer and use it in GitHub Desktop.
Compile OpenSSL from source for macOS, creating a universal xcframework that works for Intel (x86_64) and Apple Silicon (arm64)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env zsh | |
set -e | |
# This script compiles OpenSSL from source for macOS, creating a universal xcframework that works for Intel (x86_64) and Apple Silicon (arm64). | |
# How to use it: download or clone OpenSSL. Put this script in the root of the repository and run it. | |
CROSS_COMPILE=`xcode-select --print-path`/Toolchains/XcodeDefault.xctoolchain/usr/bin/ | |
CROSS_TOP=`xcode-select --print-path`/Platforms/MacOSX.platform/Developer | |
CROSS_SDK=MacOSX.sdk | |
ARCH="x86_64" # The x86_64 architecture preset also includes the ARM64 architecture. | |
# Set up a build directory | |
BUILD_ROOT="/private/tmp/openssl-macos"; | |
rm -rf $BUILD_ROOT; | |
mkdir -p $BUILD_ROOT; | |
# Compile OpenSSL | |
perl "./Configure" no-asm no-apps no-docs no-shared no-dso no-quic darwin64-$ARCH --prefix="$BUILD_ROOT" | |
make -j8 | |
make install | |
# Merge libssl and libcrypto into a single static library | |
libtool -static -o "$BUILD_ROOT/lib/openssl.a" "$BUILD_ROOT/lib/libssl.a" "$BUILD_ROOT/lib/libcrypto.a" | |
# Create the xcframework | |
OUTPUT_FRAMEWORK="$BUILD_ROOT/openssl.xcframework" | |
rm -rf $OUTPUT_FRAMEWORK | |
xcodebuild -create-xcframework \ | |
-library $BUILD_ROOT/lib/openssl.a \ | |
-headers $BUILD_ROOT/include \ | |
-output $OUTPUT_FRAMEWORK | |
echo "Success! The OpenSSL xcframework is located at $OUTPUT_FRAMEWORK" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment