Added the visionOS support for "Build XCFramework" script target

Move the scripts from xcproj into the actual Scripts folder
This commit is contained in:
DreamPiggy 2023-09-11 15:14:10 +08:00
parent f62ae2adf8
commit 35089a0b9b
3 changed files with 78 additions and 2 deletions

View File

@ -1140,10 +1140,12 @@
"$(SRCROOT)/build/watchos/SDWebImage.framework", "$(SRCROOT)/build/watchos/SDWebImage.framework",
"$(SRCROOT)/build/watchsimulator/SDWebImage.framework", "$(SRCROOT)/build/watchsimulator/SDWebImage.framework",
"$(SRCROOT)/build/maccatalyst/SDWebImage.framework", "$(SRCROOT)/build/maccatalyst/SDWebImage.framework",
"$(SRCROOT)/build/xros/SDWebImage.framework",
"$(SRCROOT)/build/xrsimulator/SDWebImage.framework",
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh; shellPath = /bin/sh;
shellScript = "XCODE_VERSION=$(xcodebuild -version | head -n 1| awk -F ' ' '{print $2}')\nXCODE_VERSION_MAJOR=$(echo $XCODE_VERSION | awk -F '.' '{print $1}')\n\nmkdir -p $(SRCROOT)/build\ndeclare -a PLATFORMS=(\"iphoneos\" \"iphonesimulator\" \"macosx\" \"appletvos\" \"appletvsimulator\" \"watchos\" \"watchsimulator\" \"maccatalyst\")\nfor CURRENT_PLATFORM in \"${PLATFORMS[@]}\"\ndo\n if [[ $CURRENT_PLATFORM == *\"simulator\" ]]; then\n xcodebuild build -project \"SDWebImage.xcodeproj\" -sdk \"${CURRENT_PLATFORM}\" -scheme \"SDWebImage\" -configuration \"Debug\" -derivedDataPath \"${SRCROOT}/build/DerivedData\" CONFIGURATION_BUILD_DIR=\"${SRCROOT}/build/${CURRENT_PLATFORM}/\"\n else\n # macOS Catalyst\n if [[ $CURRENT_PLATFORM == \"maccatalyst\" ]]; then\n if [[ $XCODE_VERSION_MAJOR -lt 11 ]]; then\n # Xcode 10 does not support macOS Catalyst\n continue\n else\n xcodebuild archive -project \"SDWebImage.xcodeproj\" -scheme \"SDWebImage\" -configuration \"Release\" -destination 'platform=macOS,arch=x86_64,variant=Mac Catalyst' -archivePath \"${SRCROOT}/build/${CURRENT_PLATFORM}/SDWebImage.xcarchive\" -derivedDataPath \"${SRCROOT}/build/DerivedData\" SKIP_INSTALL=NO\n fi\n else\n xcodebuild archive -project \"SDWebImage.xcodeproj\" -sdk \"${CURRENT_PLATFORM}\" -scheme \"SDWebImage\" -configuration \"Release\" -archivePath \"${SRCROOT}/build/${CURRENT_PLATFORM}/SDWebImage.xcarchive\" SKIP_INSTALL=NO\n fi\n mv \"${SRCROOT}/build/${CURRENT_PLATFORM}/SDWebImage.xcarchive/Products/Library/Frameworks/SDWebImage.framework\" \"${SRCROOT}/build/${CURRENT_PLATFORM}/\"\n mv \"${SRCROOT}/build/${CURRENT_PLATFORM}/SDWebImage.xcarchive/dSYMs/SDWebImage.framework.dSYM\" \"${SRCROOT}/build/${CURRENT_PLATFORM}/\"\n rm -rf \"${SRCROOT}/build/${CURRENT_PLATFORM}/SDWebImage.xcarchive/\"\n fi\ndone\n"; shellScript = "sh ${SRCROOT}/Scripts/build-frameworks.sh\n";
}; };
326CA51422BA25F70033A92F /* Create XCFramework */ = { 326CA51422BA25F70033A92F /* Create XCFramework */ = {
isa = PBXShellScriptBuildPhase; isa = PBXShellScriptBuildPhase;
@ -1161,6 +1163,8 @@
"$(SRCROOT)/build/watchos/SDWebImage.framework", "$(SRCROOT)/build/watchos/SDWebImage.framework",
"$(SRCROOT)/build/watchsimulator/SDWebImage.framework", "$(SRCROOT)/build/watchsimulator/SDWebImage.framework",
"$(SRCROOT)/build/maccatalyst/SDWebImage.framework", "$(SRCROOT)/build/maccatalyst/SDWebImage.framework",
"$(SRCROOT)/build/xros/SDWebImage.framework",
"$(SRCROOT)/build/xrsimulator/SDWebImage.framework",
); );
name = "Create XCFramework"; name = "Create XCFramework";
outputFileListPaths = ( outputFileListPaths = (
@ -1170,7 +1174,7 @@
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh; shellPath = /bin/sh;
shellScript = "XCODE_VERSION=$(xcodebuild -version | head -n 1| awk -F ' ' '{print $2}')\nXCODE_VERSION_MAJOR=$(echo $XCODE_VERSION | awk -F '.' '{print $1}')\n\nif [ $XCODE_VERSION_MAJOR -lt 11 ]\nthen\n echo \"Xcode 10 does not support xcframework. You can still use the individual framework for each platform.\"\n open -a Finder \"${SRCROOT}/build/\"\n exit 0\nfi\n\ndeclare -a PLATFORMS=(\"iphoneos\" \"iphonesimulator\" \"macosx\" \"appletvos\" \"appletvsimulator\" \"watchos\" \"watchsimulator\" \"maccatalyst\")\nCOMMAND_ARGS=\"\"\nfor CURRENT_PLATFORM in \"${PLATFORMS[@]}\"\ndo\n COMMAND_ARGS=\"${COMMAND_ARGS} -framework ${SRCROOT}/build/${CURRENT_PLATFORM}/SDWebImage.framework\"\ndone\n\n# Combine XCFramework\nxcodebuild -create-xcframework $COMMAND_ARGS -output \"${SRCROOT}/build/SDWebImage.xcframework\"\nopen -a Finder \"${SRCROOT}/build/SDWebImage.xcframework\"\n"; shellScript = "sh ${SRCROOT}/Scripts/create-xcframework.sh\n";
}; };
/* End PBXShellScriptBuildPhase section */ /* End PBXShellScriptBuildPhase section */

39
Scripts/build-frameworks.sh Executable file
View File

@ -0,0 +1,39 @@
#!/bin/bash
XCODE_VERSION=$(xcodebuild -version | head -n 1| awk -F ' ' '{print $2}')
XCODE_VERSION_MAJOR=$(echo $XCODE_VERSION | awk -F '.' '{print $1}')
if [ -z "$SRCROOT" ]
then
SRCROOT=$(pwd)
fi
mkdir -p "${SRCROOT}/build"
declare -a PLATFORMS=("iphoneos" "iphonesimulator" "macosx" "appletvos" "appletvsimulator" "watchos" "watchsimulator" "maccatalyst")
if [ $XCODE_VERSION_MAJOR -ge 15 ]
then
PLATFORMS+=("xros")
PLATFORMS+=("xrsimulator")
fi
for CURRENT_PLATFORM in "${PLATFORMS[@]}"
do
if [[ $CURRENT_PLATFORM == *"simulator" ]]; then
xcodebuild build -project "SDWebImage.xcodeproj" -sdk "${CURRENT_PLATFORM}" -scheme "SDWebImage" -configuration "Debug" -derivedDataPath "${SRCROOT}/build/DerivedData" CONFIGURATION_BUILD_DIR="${SRCROOT}/build/${CURRENT_PLATFORM}/"
else
# macOS Catalyst
if [[ $CURRENT_PLATFORM == "maccatalyst" ]]; then
if [[ $XCODE_VERSION_MAJOR -lt 11 ]]; then
# Xcode 10 does not support macOS Catalyst
continue
else
xcodebuild archive -project "SDWebImage.xcodeproj" -scheme "SDWebImage" -configuration "Release" -destination 'platform=macOS,arch=x86_64,variant=Mac Catalyst' -archivePath "${SRCROOT}/build/${CURRENT_PLATFORM}/SDWebImage.xcarchive" -derivedDataPath "${SRCROOT}/build/DerivedData" SKIP_INSTALL=NO
fi
else
xcodebuild archive -project "SDWebImage.xcodeproj" -sdk "${CURRENT_PLATFORM}" -scheme "SDWebImage" -configuration "Release" -archivePath "${SRCROOT}/build/${CURRENT_PLATFORM}/SDWebImage.xcarchive" SKIP_INSTALL=NO
fi
mv "${SRCROOT}/build/${CURRENT_PLATFORM}/SDWebImage.xcarchive/Products/Library/Frameworks/SDWebImage.framework" "${SRCROOT}/build/${CURRENT_PLATFORM}/"
mv "${SRCROOT}/build/${CURRENT_PLATFORM}/SDWebImage.xcarchive/dSYMs/SDWebImage.framework.dSYM" "${SRCROOT}/build/${CURRENT_PLATFORM}/"
rm -rf "${SRCROOT}/build/${CURRENT_PLATFORM}/SDWebImage.xcarchive/"
fi
done

33
Scripts/create-xcframework.sh Executable file
View File

@ -0,0 +1,33 @@
#!/bin/bash
XCODE_VERSION=$(xcodebuild -version | head -n 1| awk -F ' ' '{print $2}')
XCODE_VERSION_MAJOR=$(echo $XCODE_VERSION | awk -F '.' '{print $1}')
if [ -z "$SRCROOT" ]
then
SRCROOT=$(pwd)
fi
if [ $XCODE_VERSION_MAJOR -lt 11 ]
then
echo "Xcode 10 does not support xcframework. You can still use the individual framework for each platform."
open -a Finder "${SRCROOT}/build/"
exit 0
fi
declare -a PLATFORMS=("iphoneos" "iphonesimulator" "macosx" "appletvos" "appletvsimulator" "watchos" "watchsimulator")
if [ $XCODE_VERSION_MAJOR -ge 15 ]
then
PLATFORMS+=("xros")
PLATFORMS+=("xrsimulator")
fi
COMMAND_ARGS=""
for CURRENT_PLATFORM in "${PLATFORMS[@]}"
do
COMMAND_ARGS="${COMMAND_ARGS} -framework ${SRCROOT}/build/${CURRENT_PLATFORM}/SDWebImage.framework"
done
# Combine XCFramework
xcodebuild -create-xcframework $COMMAND_ARGS -output "${SRCROOT}/build/SDWebImage.xcframework"
open -a Finder "${SRCROOT}/build/SDWebImage.xcframework"