Skip to content

Commit

Permalink
Fix OpenSSL 3 build issues (#52)
Browse files Browse the repository at this point in the history
* OpenSSL 1.1.1x is EOL, this should make it work for 3.x.x versions.
See https://www.openssl.org/blog/blog/2023/03/28/1.1.1-EOL/

* Removed asm inheritance from config

* Make 3.x the standard parsing logic

* Drop all references to Bitcode

* Use newer -platform_version

* Default to 3.2.0

---------

Co-authored-by: Davide De Rosa <[email protected]>
  • Loading branch information
hoppjan and keeshux authored Dec 12, 2023
1 parent 2d1df58 commit 12ad7b9
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 58 deletions.
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.1q-0
3.2.0-0
2 changes: 1 addition & 1 deletion build-libssl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ set -u
# SCRIPT DEFAULTS

# Default version in case no version is specified
DEFAULTVERSION="1.1.1q"
DEFAULTVERSION="3.2.0"

# Default (=full) set of targets (OpenSSL >= 1.1.1) to build
DEFAULTTARGETS=`cat <<TARGETS
Expand Down
28 changes: 12 additions & 16 deletions config/20-all-platforms.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,9 @@ my %targets = ();
## Base settings for cross-compile
# Based on 10-main.conf: iphoneos-cross
# Add generic compiler flags
# Add embed-bitcode option if SDK version is 9 or higher
"all-base" => {
template => 1,
cflags => combine('-isysroot $(CROSS_TOP)/SDKs/$(CROSS_SDK) -fno-common',
sub { ((!defined($ENV{'CONFIG_DISABLE_BITCODE'}) || $ENV{'CONFIG_DISABLE_BITCODE'} ne 'true') && defined($ENV{'SDKVERSION'}) && $ENV{'SDKVERSION'} =~ /^(9|[1-9][0-9]+)\./ && $disabled{shared})
? '-fembed-bitcode' : (); },
),
cflags => combine('-isysroot $(CROSS_TOP)/SDKs/$(CROSS_SDK) -fno-common')
},

## Base settings
Expand Down Expand Up @@ -47,14 +43,14 @@ my %targets = ();

# Device
"ios64-cross-arm64" => {
inherit_from => [ "darwin-common", "ios-cross-base", asm("aarch64_asm") ],
inherit_from => [ "darwin-common", "ios-cross-base" ],
cflags => add("-arch arm64"),
bn_ops => "SIXTY_FOUR_BIT_LONG RC4_CHAR",
perlasm_scheme => "ios64",
sys_id => "iOS",
},
"ios64-cross-arm64e" => {
inherit_from => [ "darwin-common", "ios-cross-base", asm("aarch64_asm") ],
inherit_from => [ "darwin-common", "ios-cross-base" ],
cflags => add("-arch arm64e"),
bn_ops => "SIXTY_FOUR_BIT_LONG RC4_CHAR",
perlasm_scheme => "ios64",
Expand Down Expand Up @@ -96,20 +92,20 @@ my %targets = ();

# Device
"watchos-cross-armv7k" => {
inherit_from => [ "darwin-common", "watchos-cross-base", asm("armv7_asm") ],
cflags => add("-arch armv7k -fembed-bitcode"),
inherit_from => [ "darwin-common", "watchos-cross-base" ],
cflags => add("-arch armv7k"),
defines => [ "HAVE_FORK=0" ],
sys_id => "WatchOS",
},
"watchos-cross-arm64_32" => {
inherit_from => [ "darwin-common", "watchos-cross-base"],
cflags => add("-arch arm64_32 -fembed-bitcode"),
cflags => add("-arch arm64_32"),
defines => [ "HAVE_FORK=0" ],
sys_id => "WatchOS",
},
"watchos-cross-arm64" => {
inherit_from => [ "darwin-common", "watchos-cross-base", asm("aarch64_asm") ],
cflags => add("-arch arm64 -fembed-bitcode"),
inherit_from => [ "darwin-common", "watchos-cross-base" ],
cflags => add("-arch arm64"),
bn_ops => "SIXTY_FOUR_BIT_LONG RC4_CHAR",
perlasm_scheme => "ios64",
defines => [ "HAVE_FORK=0" ],
Expand All @@ -118,19 +114,19 @@ my %targets = ();
# Simulator
"watchos-sim-cross-x86_64" => {
inherit_from => [ "darwin64-x86_64-cc", "watchos-cross-base"],
cflags => add("-fembed-bitcode"),
cflags => add(""),
defines => [ "HAVE_FORK=0" ],
sys_id => "WatchOS",
},
"watchos-sim-cross-arm64" => {
inherit_from => [ "darwin64-arm64-cc", "watchos-cross-base"],
cflags => add("-target arm64-apple-watchos7.2-simulator -mwatchos-version-min=7.2 -fembed-bitcode"),
cflags => add("-target arm64-apple-watchos7.2-simulator -mwatchos-version-min=7.2"),
defines => [ "HAVE_FORK=0" ],
sys_id => "WatchOS",
},
"watchos-sim-cross-i386" => {
inherit_from => [ "darwin-common", "watchos-cross-base"],
cflags => add("-arch i386 -fembed-bitcode"),
cflags => add("-arch i386"),
defines => [ "HAVE_FORK=0" ],
sys_id => "WatchOS",
},
Expand All @@ -139,7 +135,7 @@ my %targets = ();

# Device
"tvos64-cross-arm64" => {
inherit_from => [ "darwin-common", "tvos-cross-base", asm("aarch64_asm") ],
inherit_from => [ "darwin-common", "tvos-cross-base" ],
cflags => add("-arch arm64"),
bn_ops => "SIXTY_FOUR_BIT_LONG RC4_CHAR",
perlasm_scheme => "ios64",
Expand Down
46 changes: 7 additions & 39 deletions create-openssl-framework.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,6 @@ fi
#ALL_SYSTEMS=("iPhone" "AppleTV" "MacOSX" "Catalyst" "Watch")
ALL_SYSTEMS=("iPhoneOS" "iPhoneSimulator" "AppleTVOS" "AppleTVSimulator" "MacOSX" "Catalyst" "WatchOS" "WatchSimulator")

function check_bitcode() {
local BITCODE_PATH=$1
local IS_VERBOSE=$2

if [[ $FWTYPE == "dynamic" ]]; then
BITCODE_PATTERN="__LLVM"
else
BITCODE_PATTERN="__bitcode"
fi

if otool -l "$BITCODE_PATH" | grep "${BITCODE_PATTERN}" >/dev/null; then
if $IS_VERBOSE; then
echo "INFO: $BITCODE_PATH contains Bitcode"
fi
BITCODE_ENABLED=1
else
if $IS_VERBOSE; then
echo "INFO: $BITCODE_PATH doesn't contain Bitcode"
fi
BITCODE_ENABLED=0
fi
}

# Inspect Mach-O load commands to get minimum SDK version.
#
# Depending on the actual minimum SDK version it may look like this
Expand Down Expand Up @@ -139,22 +116,22 @@ if [ $FWTYPE == "dynamic" ]; then

MIN_SDK_VERSION=$(get_min_sdk "${TARGETDIR}/lib/libcrypto.a")
if [[ $PLATFORM == AppleTVSimulator* ]]; then
MIN_SDK="-tvos_simulator_version_min $MIN_SDK_VERSION"
MIN_SDK="-platform_version tvos-simulator $MIN_SDK_VERSION"
elif [[ $PLATFORM == AppleTV* ]]; then
MIN_SDK="-tvos_version_min $MIN_SDK_VERSION"
MIN_SDK="-platform_version tvos $MIN_SDK_VERSION"
elif [[ $PLATFORM == MacOSX* ]]; then
MIN_SDK="-macosx_version_min $MIN_SDK_VERSION"
MIN_SDK="-platform_version macos $MIN_SDK_VERSION"
elif [[ $PLATFORM == Catalyst* ]]; then
MIN_SDK="-platform_version mac-catalyst $MIN_SDK_VERSION $MIN_SDK_VERSION"
PLATFORM="MacOSX"
elif [[ $PLATFORM == iPhoneSimulator* ]]; then
MIN_SDK="-ios_simulator_version_min $MIN_SDK_VERSION"
MIN_SDK="-platform_version ios-simulator $MIN_SDK_VERSION"
elif [[ $PLATFORM == WatchOS* ]]; then
MIN_SDK="-watchos_version_min $MIN_SDK_VERSION"
MIN_SDK="-platform_version watchos $MIN_SDK_VERSION"
elif [[ $PLATFORM == WatchSimulator* ]]; then
MIN_SDK="-watchos_simulator_version_min $MIN_SDK_VERSION"
MIN_SDK="-platform_version watchos-simulator $MIN_SDK_VERSION"
else
MIN_SDK="-ios_version_min $MIN_SDK_VERSION"
MIN_SDK="-platform_version ios $MIN_SDK_VERSION"
fi

CROSS_TOP="${DEVELOPER}/Platforms/${PLATFORM}.platform/Developer"
Expand All @@ -172,15 +149,8 @@ if [ $FWTYPE == "dynamic" ]; then
ar -x ../lib/libssl.a
cd ..

BUNDLE_BITCODE=""
check_bitcode "lib/libssl.a" false
if [[ $BITCODE_ENABLED == 1 ]]; then
BUNDLE_BITCODE="-bitcode_bundle"
fi

ld obj/*.o \
-dylib \
$BUNDLE_BITCODE \
-lSystem \
-arch $ARCH \
$MIN_SDK \
Expand Down Expand Up @@ -212,7 +182,6 @@ if [ $FWTYPE == "dynamic" ]; then
-e "s/\\\$(OPENSSL_VERSION)/$OPENSSL_VERSION/g" \
-i '' "$FWDIR/Info.plist"
echo "Created $FWDIR"
check_bitcode "$FWDIR/$FWNAME" true
else
echo "Skipped framework for $SYS"
fi
Expand Down Expand Up @@ -242,7 +211,6 @@ else
-e "s/\\\$(OPENSSL_VERSION)/$OPENSSL_VERSION/g" \
-i '' "$FWDIR/Info.plist"
echo "Created $FWDIR"
check_bitcode "$FWDIR/$FWNAME" true
else
echo "Skipped framework for $SYS"
fi
Expand Down
6 changes: 5 additions & 1 deletion scripts/get-openssl-version.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/bash
function get_openssl_version() {
local std_version=$1
local std_version=$1
if [[ ! "$std_version" =~ 3.*.* ]]; then
local script_version=${2:-}
local generic_version=${std_version%?}
local subpatch=${std_version: -1}
Expand All @@ -9,4 +10,7 @@ function get_openssl_version() {
script_version="$(printf '%02d' $script_version)"
local normalized_version="${generic_version}${subpatch_number}${script_version}"
echo $normalized_version
return
fi
echo $std_version
}

0 comments on commit 12ad7b9

Please sign in to comment.