Skip to content

Instantly share code, notes, and snippets.

@mbernson
Last active April 8, 2024 12:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbernson/8e09fa53de0fa1c942b0a26f6f0e8c7c to your computer and use it in GitHub Desktop.
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)
#!/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).
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