Skip to content

Commit

Permalink
version 3.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
apotocki committed Feb 3, 2024
1 parent d062624 commit b02e5ed
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 13 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
## OpenSSL for iOS and Mac OS X (Intel & Apple Silicon M1) & Catalyst - arm64 / x86_64
## OpenSSL for iOS, visionOS, macOS (Intel & Apple Silicon M1) & Catalyst - arm64 / x86_64

Supported version: 3.2.1

This repository provides a universal script for building static OpenSSL libraries for use in iOS and macOS applications.
This repository provides a universal script for building static OpenSSL libraries for use in iOS, visionOS, and macOS & Catalyst applications.
The actual library version is taken from https://github.com/openssl/openssl with tag 'openssl-3.2.1'

## Prerequisites
1) Xcode must be installed because xcodebuild is used to create xcframeworks
2) ```xcode-select -p``` must point to Xcode app developer directory (by default e.g. /Applications/Xcode.app/Contents/Developer). If it points to CommandLineTools directory you should execute:
```sudo xcode-select --reset``` or ```sudo xcode-select -s /Applications/Xcode.app/Contents/Developer```
3) For the creation of visionOS related artifacts and their integration into the resulting xcframeworks, XROS.platform and XRSimulator.platform should be available in the folder: /Applications/Xcode.app/Contents/Developer/Platforms

## How to build?
- Manually
Expand All @@ -27,7 +28,7 @@ The actual library version is taken from https://github.com/openssl/openssl with
use_frameworks!
pod 'openssl-iosx', '~> 3.2.1'
# or optionally more precisely
# pod 'openssl-iosx', :git => 'https://github.com/apotocki/openssl-iosx', :tag => '3.2.1.0'
# pod 'openssl-iosx', :git => 'https://github.com/apotocki/openssl-iosx', :tag => '3.2.1.1'
```
install new dependency:
```
Expand Down
6 changes: 4 additions & 2 deletions openssl-iosx.podspec
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
Pod::Spec.new do |s|
s.name = "openssl-iosx"
s.version = "3.2.1.0"
s.summary = "OpenSSL"
s.version = "3.2.1.1"
s.summary = "OpenSSL libraries for macOS, iOS, and visionOS, including both arm64 and x86_64 builds for macOS, Mac Catalyst, iOS Simulator, and visionOS Simulator."
s.homepage = "https://github.com/apotocki/openssl-iosx"
s.license = "Apache"
s.author = { "Alexander Pototskiy" => "[email protected]" }
s.social_media_url = "https://www.linkedin.com/in/alexander-pototskiy"
s.osx.deployment_target = "11.0"
s.ios.deployment_target = "13.4"
s.visionos.deployment_target = "1.0"
s.osx.pod_target_xcconfig = { 'ONLY_ACTIVE_ARCH' => 'YES' }
s.ios.pod_target_xcconfig = { 'ONLY_ACTIVE_ARCH' => 'YES' }
s.visionos.pod_target_xcconfig = { 'ONLY_ACTIVE_ARCH' => 'YES' }
s.static_framework = true
s.prepare_command = "sh scripts/build.sh"
s.source = { :git => "https://github.com/apotocki/openssl-iosx.git", :tag => "#{s.version}" }
Expand Down
25 changes: 25 additions & 0 deletions scripts/15-ios.conf.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
@@ -34,6 +34,24 @@
inherit_from => [ "ios-common" ],
CC => "xcrun -sdk iphonesimulator cc",
},
+ "xros-common" => {
+ template => 1,
+ inherit_from => [ "darwin-common" ],
+ sys_id => "visionOS",
+ disable => [ "shared", "async" ],
+ },
+ "xros-xcrun" => {
+ inherit_from => [ "xros-common" ],
+ CC => "xcrun -sdk xros cc",
+ cflags => add("-arch arm64 -fno-common"),
+ bn_ops => "SIXTY_FOUR_BIT_LONG RC4_CHAR",
+ asm_arch => 'aarch64',
+ perlasm_scheme => "ios64",
+ },
+ "xrossimulator-xcrun" => {
+ inherit_from => [ "xros-common" ],
+ CC => "xcrun -sdk xrsimulator cc",
+ },
# It takes three prior-set environment variables to make it work:
#
# CROSS_COMPILE=/where/toolchain/is/usr/bin/ [note ending slash]
90 changes: 82 additions & 8 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,28 @@ THREAD_COUNT=$(sysctl hw.ncpu | awk '{print $2}')
HOST_ARC=$( uname -m )
XCODE_ROOT=$( xcode-select -print-path )
OPENSSL_VER=openssl-3.2.1
#MACOSX_VERSION_ARM=12.3
#MACOSX_VERSION_X86_64=10.13
################## SETUP END
#DEVSYSROOT=$XCODE_ROOT/Platforms/iPhoneOS.platform/Developer
#SIMSYSROOT=$XCODE_ROOT/Platforms/iPhoneSimulator.platform/Developer
#IOSSYSROOT=$XCODE_ROOT/Platforms/iPhoneOS.platform/Developer
#IOSSIMSYSROOT=$XCODE_ROOT/Platforms/iPhoneSimulator.platform/Developer
MACSYSROOT=$XCODE_ROOT/Platforms/MacOSX.platform/Developer
XROSSYSROOT=$XCODE_ROOT/Platforms/XROS.platform/Developer
XROSSIMSYSROOT=$XCODE_ROOT/Platforms/XRSimulator.platform/Developer

BUILD_DIR="$( cd "$( dirname "./" )" >/dev/null 2>&1 && pwd )"
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

if [ "$HOST_ARC" = "arm64" ]; then
FOREIGN_ARC=x86_64
FOREIGN_BUILD_FLAGS="" && [ ! -z "${MACOSX_VERSION_X86_64}" ] && FOREIGN_BUILD_FLAGS="-mmacosx-version-min=$MACOSX_VERSION_X86_64"
NATIVE_BUILD_FLAGS="" && [ ! -z "${MACOSX_VERSION_ARM}" ] && NATIVE_BUILD_FLAGS="-mmacosx-version-min=$MACOSX_VERSION_ARM"
else
FOREIGN_ARC=arm64
FOREIGN_BUILD_FLAGS="" && [ ! -z "${MACOSX_VERSION_ARM}" ] && FOREIGN_BUILD_FLAGS="-mmacosx-version-min=$MACOSX_VERSION_ARM"
NATIVE_BUILD_FLAGS="" && [ ! -z "${MACOSX_VERSION_X86_64}" ] && NATIVE_BUILD_FLAGS="-mmacosx-version-min=$MACOSX_VERSION_X86_64"
fi

FOREIGN_BUILD_FLAGS="-arch $FOREIGN_ARC $FOREIGN_BUILD_FLAGS"

if [[ ! -d $BUILD_DIR/frameworks ]]; then

Expand All @@ -28,6 +38,14 @@ fi

pushd $OPENSSL_VER

echo patching openssl...
if [ ! -f Configurations/15-ios.conf.orig ]; then
cp -f Configurations/15-ios.conf Configurations/15-ios.conf.orig
else
cp -f Configurations/15-ios.conf.orig Configurations/15-ios.conf
fi
patch Configurations/15-ios.conf $SCRIPT_DIR/15-ios.conf.patch

function arc()
{
if [[ $1 == arm* ]]; then
Expand All @@ -43,7 +61,6 @@ build_catalyst_libs()
{
if [[ ! -d $BUILD_DIR/build/lib.catalyst-$1 ]]; then
./Configure --openssldir="$BUILD_DIR/build/ssl" no-shared darwin64-$1-cc --target=$(arc $1)-apple-ios13.4-macabi -isysroot $MACSYSROOT/SDKs/MacOSX.sdk
# -I$MACSYSROOT/SDKs/MacOSX.sdk/System/iOSSupport/usr/include/ -isystem $MACSYSROOT/SDKs/MacOSX.sdk/System/iOSSupport/usr/include -iframework $MACSYSROOT/SDKs/MacOSX.sdk/System/iOSSupport/System/Library/Frameworks
make clean
make -j$THREAD_COUNT

Expand All @@ -68,6 +85,20 @@ build_sim_libs()
fi
}

build_xrossim_libs()
{
if [[ ! -d $BUILD_DIR/build/lib.xrossim-$1 ]]; then
./Configure --openssldir="$BUILD_DIR/build/ssl" no-shared xrossimulator-xcrun CFLAGS="-arch $1"
make clean
make -j$THREAD_COUNT

mkdir $BUILD_DIR/build/lib.xrossim-$1
cp libssl.a $BUILD_DIR/build/lib.xrossim-$1/
cp libcrypto.a $BUILD_DIR/build/lib.xrossim-$1/
make clean
fi
}

build_ios_libs()
{
if [[ ! -d $BUILD_DIR/build/lib.ios ]]; then
Expand All @@ -82,15 +113,29 @@ build_ios_libs()
fi
}

build_xros_libs()
{
if [[ ! -d $BUILD_DIR/build/lib.xros ]]; then
./Configure --openssldir="$BUILD_DIR/build/ssl" no-shared no-dso no-hw no-engine xros-xcrun -fembed-bitcode
make clean
make -j$THREAD_COUNT

mkdir $BUILD_DIR/build/lib.xros
cp libssl.a $BUILD_DIR/build/lib.xros/
cp libcrypto.a $BUILD_DIR/build/lib.xros/
make clean
fi
}

if [[ ! -d $BUILD_DIR/build/lib ]]; then
./Configure --prefix="$BUILD_DIR/build" --openssldir="$BUILD_DIR/build/ssl" no-shared darwin64-$HOST_ARC-cc
./Configure --prefix="$BUILD_DIR/build" --openssldir="$BUILD_DIR/build/ssl" no-shared darwin64-$HOST_ARC-cc CFLAGS="$NATIVE_BUILD_FLAGS"
make clean
make -j$THREAD_COUNT
make install
make clean
fi
if [[ ! -d $BUILD_DIR/build/lib.macos ]]; then
./Configure --openssldir="$BUILD_DIR/build/ssl" no-shared darwin64-$FOREIGN_ARC-cc CFLAGS="-arch $FOREIGN_ARC"
./Configure --openssldir="$BUILD_DIR/build/ssl" no-shared darwin64-$FOREIGN_ARC-cc CFLAGS="$FOREIGN_BUILD_FLAGS"
make clean
make -j$THREAD_COUNT

Expand All @@ -117,14 +162,43 @@ if [[ ! -d $BUILD_DIR/build/lib.iossim ]]; then
lipo -create $BUILD_DIR/build/lib.iossim-x86_64/libcrypto.a $BUILD_DIR/build/lib.iossim-arm64/libcrypto.a -output $BUILD_DIR/build/lib.iossim/libcrypto.a
fi

if [ -d $XROSSIMSYSROOT/SDKs/XRSimulator.sdk ]; then
if [[ ! -d $BUILD_DIR/build/lib.xrossim ]]; then
build_xrossim_libs arm64
build_xrossim_libs x86_64
mkdir $BUILD_DIR/build/lib.xrossim
lipo -create $BUILD_DIR/build/lib.xrossim-x86_64/libssl.a $BUILD_DIR/build/lib.xrossim-arm64/libssl.a -output $BUILD_DIR/build/lib.xrossim/libssl.a
lipo -create $BUILD_DIR/build/lib.xrossim-x86_64/libcrypto.a $BUILD_DIR/build/lib.xrossim-arm64/libcrypto.a -output $BUILD_DIR/build/lib.xrossim/libcrypto.a
fi
fi

build_ios_libs
if [ -d $XROSSYSROOT ]; then
build_xros_libs
fi

mkdir $BUILD_DIR/frameworks

cp -R $BUILD_DIR/build/include $BUILD_DIR/frameworks/Headers

xcodebuild -create-xcframework -library $BUILD_DIR/build/lib.macos/libssl.a -library $BUILD_DIR/build/lib.catalyst/libssl.a -library $BUILD_DIR/build/lib.iossim/libssl.a -library $BUILD_DIR/build/lib.ios/libssl.a -output $BUILD_DIR/frameworks/ssl.xcframework
xcodebuild -create-xcframework -library $BUILD_DIR/build/lib.macos/libcrypto.a -library $BUILD_DIR/build/lib.catalyst/libcrypto.a -library $BUILD_DIR/build/lib.iossim/libcrypto.a -library $BUILD_DIR/build/lib.ios/libcrypto.a -output $BUILD_DIR/frameworks/crypto.xcframework
create_xcframework()
{
LIBARGS="-library $BUILD_DIR/build/lib.macos/lib$1.a \
-library $BUILD_DIR/build/lib.catalyst/lib$1.a \
-library $BUILD_DIR/build/lib.iossim/lib$1.a \
-library $BUILD_DIR/build/lib.ios/lib$1.a"

if [ -d $XROSSIMSYSROOT/SDKs/XRSimulator.sdk ]; then
LIBARGS="$LIBARGS -library $BUILD_DIR/build/lib.xrossim/lib$1.a"
fi
if [ -d $XROSSYSROOT/SDKs/XROS.sdk ]; then
LIBARGS="$LIBARGS -library $BUILD_DIR/build/lib.xros/lib$1.a"
fi
xcodebuild -create-xcframework $LIBARGS -output "$BUILD_DIR/frameworks/$1.xcframework"
}

create_xcframework ssl
create_xcframework crypto

popd

Expand Down

0 comments on commit b02e5ed

Please sign in to comment.