Fix MIN_SDK in framework creation (#54)

This commit is contained in:
Davide De Rosa 2023-12-12 13:08:46 +01:00 committed by GitHub
parent 12ad7b9efc
commit 99eb3624b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 102 additions and 115 deletions

View File

@ -3,17 +3,11 @@ source scripts/get-openssl-version.sh
set -euo pipefail set -euo pipefail
if [ $# == 0 ]; then
echo "Usage: `basename $0` static|dynamic"
exit 1
fi
if [ ! -d lib ]; then if [ ! -d lib ]; then
echo "Please run build-libssl.sh first!" echo "Please run build-libssl.sh first!"
exit 1 exit 1
fi fi
FWTYPE=$1
FWNAME=openssl FWNAME=openssl
FWROOT=frameworks FWROOT=frameworks
@ -64,6 +58,27 @@ function get_min_sdk() {
set -o pipefail set -o pipefail
} }
function get_target_sdk() {
local file=$1
set +o pipefail
otool -l "$file" | awk "
/^Load command/ {
last_command = \"\"
}
\$1 == \"cmd\" {
last_command = \$2
}
((last_command ~ /LC_BUILD_VERSION/ && \$1 == \"sdk\") ||
(last_command ~ /^LC_VERSION_MIN_/ && \$1 == \"sdk\")) &&
(\$2 ~ /^[1-9]/) {
print \$2
exit
}
"
set -o pipefail
}
# Read OpenSSL version from opensslv.h file. # Read OpenSSL version from opensslv.h file.
# #
# In modern OpenSSL releases the version line looks like this: # In modern OpenSSL releases the version line looks like this:
@ -95,127 +110,99 @@ function get_openssl_version_from_file() {
echo $(get_openssl_version $std_version) echo $(get_openssl_version $std_version)
} }
if [ $FWTYPE == "dynamic" ]; then DEVELOPER=`xcode-select -print-path`
DEVELOPER=`xcode-select -print-path` FW_EXEC_NAME="${FWNAME}.framework/${FWNAME}"
FW_EXEC_NAME="${FWNAME}.framework/${FWNAME}" INSTALL_NAME="@rpath/${FW_EXEC_NAME}"
INSTALL_NAME="@rpath/${FW_EXEC_NAME}" COMPAT_VERSION="1.0.0"
COMPAT_VERSION="1.0.0" CURRENT_VERSION="1.0.0"
CURRENT_VERSION="1.0.0"
RX='([A-z]+)([0-9]+(\.[0-9]+)*)-([A-z0-9_]+)\.sdk' RX='([A-z]+)([0-9]+(\.[0-9]+)*)-([A-z0-9_]+)\.sdk'
cd bin cd bin
for TARGETDIR in `ls -d *.sdk`; do for TARGETDIR in `ls -d *.sdk`; do
if [[ $TARGETDIR =~ $RX ]]; then if [[ $TARGETDIR =~ $RX ]]; then
PLATFORM="${BASH_REMATCH[1]}" PLATFORM="${BASH_REMATCH[1]}"
SDKVERSION="${BASH_REMATCH[2]}" SDKVERSION="${BASH_REMATCH[2]}"
ARCH="${BASH_REMATCH[4]}" ARCH="${BASH_REMATCH[4]}"
fi fi
echo "Assembling .dylib for $PLATFORM $SDKVERSION ($ARCH)" echo "Assembling .dylib for $PLATFORM $SDKVERSION ($ARCH)"
MIN_SDK_VERSION=$(get_min_sdk "${TARGETDIR}/lib/libcrypto.a") MIN_SDK_VERSION=$(get_min_sdk "${TARGETDIR}/lib/libcrypto.a")
if [[ $PLATFORM == AppleTVSimulator* ]]; then TARGET_SDK_VERSION=$(get_target_sdk "${TARGETDIR}/lib/libcrypto.a")
MIN_SDK="-platform_version tvos-simulator $MIN_SDK_VERSION" if [[ $PLATFORM == AppleTVSimulator* ]]; then
elif [[ $PLATFORM == AppleTV* ]]; then MIN_SDK="-platform_version tvos-simulator $MIN_SDK_VERSION $TARGET_SDK_VERSION"
MIN_SDK="-platform_version tvos $MIN_SDK_VERSION" elif [[ $PLATFORM == AppleTV* ]]; then
elif [[ $PLATFORM == MacOSX* ]]; then MIN_SDK="-platform_version tvos $MIN_SDK_VERSION $TARGET_SDK_VERSION"
MIN_SDK="-platform_version macos $MIN_SDK_VERSION" elif [[ $PLATFORM == MacOSX* ]]; then
elif [[ $PLATFORM == Catalyst* ]]; then MIN_SDK="-platform_version macos $MIN_SDK_VERSION $TARGET_SDK_VERSION"
MIN_SDK="-platform_version mac-catalyst $MIN_SDK_VERSION $MIN_SDK_VERSION" elif [[ $PLATFORM == Catalyst* ]]; then
PLATFORM="MacOSX" MIN_SDK="-platform_version mac-catalyst $MIN_SDK_VERSION $TARGET_SDK_VERSION"
elif [[ $PLATFORM == iPhoneSimulator* ]]; then PLATFORM="MacOSX"
MIN_SDK="-platform_version ios-simulator $MIN_SDK_VERSION" elif [[ $PLATFORM == iPhoneSimulator* ]]; then
elif [[ $PLATFORM == WatchOS* ]]; then MIN_SDK="-platform_version ios-simulator $MIN_SDK_VERSION $TARGET_SDK_VERSION"
MIN_SDK="-platform_version watchos $MIN_SDK_VERSION" elif [[ $PLATFORM == WatchOS* ]]; then
elif [[ $PLATFORM == WatchSimulator* ]]; then MIN_SDK="-platform_version watchos $MIN_SDK_VERSION $TARGET_SDK_VERSION"
MIN_SDK="-platform_version watchos-simulator $MIN_SDK_VERSION" elif [[ $PLATFORM == WatchSimulator* ]]; then
else MIN_SDK="-platform_version watchos-simulator $MIN_SDK_VERSION $TARGET_SDK_VERSION"
MIN_SDK="-platform_version ios $MIN_SDK_VERSION" else
fi MIN_SDK="-platform_version ios $MIN_SDK_VERSION $TARGET_SDK_VERSION"
fi
CROSS_TOP="${DEVELOPER}/Platforms/${PLATFORM}.platform/Developer" CROSS_TOP="${DEVELOPER}/Platforms/${PLATFORM}.platform/Developer"
CROSS_SDK="${PLATFORM}${SDKVERSION}.sdk" CROSS_SDK="${PLATFORM}${SDKVERSION}.sdk"
SDK="${CROSS_TOP}/SDKs/${CROSS_SDK}" SDK="${CROSS_TOP}/SDKs/${CROSS_SDK}"
#cd $TARGETDIR #cd $TARGETDIR
#libtool -dynamic -lSystem $MIN_SDK -syslibroot $SDK -install_name $INSTALL_NAME -compatibility_version $COMPAT_VERSION -current_version $CURRENT_VERSION lib/*.a -o $FWNAME.dylib #libtool -dynamic -lSystem $MIN_SDK -syslibroot $SDK -install_name $INSTALL_NAME -compatibility_version $COMPAT_VERSION -current_version $CURRENT_VERSION lib/*.a -o $FWNAME.dylib
TARGETOBJ="${TARGETDIR}/obj" TARGETOBJ="${TARGETDIR}/obj"
rm -rf $TARGETOBJ rm -rf $TARGETOBJ
mkdir $TARGETOBJ mkdir $TARGETOBJ
cd $TARGETOBJ cd $TARGETOBJ
ar -x ../lib/libcrypto.a ar -x ../lib/libcrypto.a
ar -x ../lib/libssl.a ar -x ../lib/libssl.a
cd ..
ld obj/*.o \
-dylib \
-lSystem \
-arch $ARCH \
$MIN_SDK \
-syslibroot $SDK \
-compatibility_version $COMPAT_VERSION \
-current_version $CURRENT_VERSION \
-application_extension \
-o $FWNAME.dylib
install_name_tool -id $INSTALL_NAME $FWNAME.dylib
cd ..
done
cd .. cd ..
for SYS in ${ALL_SYSTEMS[@]}; do ld obj/*.o \
SYSDIR="$FWROOT/$SYS" -dylib \
FWDIR="$SYSDIR/$FWNAME.framework" -lSystem \
DYLIBS=(bin/${SYS}*/$FWNAME.dylib) -arch $ARCH \
$MIN_SDK \
-syslibroot $SDK \
-compatibility_version $COMPAT_VERSION \
-current_version $CURRENT_VERSION \
-application_extension \
-o $FWNAME.dylib
install_name_tool -id $INSTALL_NAME $FWNAME.dylib
if [[ ${#DYLIBS[@]} -gt 0 && -e ${DYLIBS[0]} ]]; then cd ..
echo "Creating framework for $SYS" done
mkdir -p $FWDIR/Headers cd ..
lipo -create ${DYLIBS[@]} -output $FWDIR/$FWNAME
cp -r include/$FWNAME/* $FWDIR/Headers/
cp -L assets/$SYS/Info.plist $FWDIR/Info.plist
MIN_SDK_VERSION=$(get_min_sdk "$FWDIR/$FWNAME")
OPENSSL_VERSION=$(get_openssl_version_from_file "$FWDIR/Headers/opensslv.h")
sed -e "s/\\\$(MIN_SDK_VERSION)/$MIN_SDK_VERSION/g" \
-e "s/\\\$(OPENSSL_VERSION)/$OPENSSL_VERSION/g" \
-i '' "$FWDIR/Info.plist"
echo "Created $FWDIR"
else
echo "Skipped framework for $SYS"
fi
done
rm bin/*/$FWNAME.dylib for SYS in ${ALL_SYSTEMS[@]}; do
else SYSDIR="$FWROOT/$SYS"
for SYS in ${ALL_SYSTEMS[@]}; do FWDIR="$SYSDIR/$FWNAME.framework"
SYSDIR="$FWROOT/$SYS" DYLIBS=(bin/${SYS}*/$FWNAME.dylib)
FWDIR="$SYSDIR/$FWNAME.framework"
LIBS_CRYPTO=(bin/${SYS}*/lib/libcrypto.a)
LIBS_SSL=(bin/${SYS}*/lib/libssl.a)
if [[ ${#LIBS_CRYPTO[@]} -gt 0 && -e ${LIBS_CRYPTO[0]} && ${#LIBS_SSL[@]} -gt 0 && -e ${LIBS_SSL[0]} ]]; then if [[ ${#DYLIBS[@]} -gt 0 && -e ${DYLIBS[0]} ]]; then
echo "Creating framework for $SYS" echo "Creating framework for $SYS"
mkdir -p $FWDIR/lib mkdir -p $FWDIR/Headers
lipo -create ${LIBS_CRYPTO[@]} -output $FWDIR/lib/libcrypto.a lipo -create ${DYLIBS[@]} -output $FWDIR/$FWNAME
lipo -create ${LIBS_SSL[@]} -output $FWDIR/lib/libssl.a cp -r include/$FWNAME/* $FWDIR/Headers/
libtool -static -o $FWDIR/$FWNAME $FWDIR/lib/*.a cp -L assets/$SYS/Info.plist $FWDIR/Info.plist
rm -rf $FWDIR/lib MIN_SDK_VERSION=$(get_min_sdk "$FWDIR/$FWNAME")
mkdir -p $FWDIR/Headers OPENSSL_VERSION=$(get_openssl_version_from_file "$FWDIR/Headers/opensslv.h")
cp -r include/$FWNAME/* $FWDIR/Headers/ sed -e "s/\\\$(MIN_SDK_VERSION)/$MIN_SDK_VERSION/g" \
cp -L assets/$SYS/Info.plist $FWDIR/Info.plist -e "s/\\\$(OPENSSL_VERSION)/$OPENSSL_VERSION/g" \
MIN_SDK_VERSION=$(get_min_sdk "$FWDIR/$FWNAME") -i '' "$FWDIR/Info.plist"
OPENSSL_VERSION=$(get_openssl_version_from_file "$FWDIR/Headers/opensslv.h") echo "Created $FWDIR"
sed -e "s/\\\$(MIN_SDK_VERSION)/$MIN_SDK_VERSION/g" \ else
-e "s/\\\$(OPENSSL_VERSION)/$OPENSSL_VERSION/g" \ echo "Skipped framework for $SYS"
-i '' "$FWDIR/Info.plist" fi
echo "Created $FWDIR" done
else
echo "Skipped framework for $SYS" rm bin/*/$FWNAME.dylib
fi
done
fi
# macOS and Catalyst symlinks # macOS and Catalyst symlinks
for SYS in ${ALL_SYSTEMS[@]}; do for SYS in ${ALL_SYSTEMS[@]}; do