From 35089a0b9b4788855d9eab073756deae76729c50 Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Mon, 11 Sep 2023 15:14:10 +0800 Subject: [PATCH 1/4] Added the visionOS support for "Build XCFramework" script target Move the scripts from xcproj into the actual Scripts folder --- SDWebImage.xcodeproj/project.pbxproj | 8 ++++-- Scripts/build-frameworks.sh | 39 ++++++++++++++++++++++++++++ Scripts/create-xcframework.sh | 33 +++++++++++++++++++++++ 3 files changed, 78 insertions(+), 2 deletions(-) create mode 100755 Scripts/build-frameworks.sh create mode 100755 Scripts/create-xcframework.sh diff --git a/SDWebImage.xcodeproj/project.pbxproj b/SDWebImage.xcodeproj/project.pbxproj index 78ec954c..5a4af183 100644 --- a/SDWebImage.xcodeproj/project.pbxproj +++ b/SDWebImage.xcodeproj/project.pbxproj @@ -1140,10 +1140,12 @@ "$(SRCROOT)/build/watchos/SDWebImage.framework", "$(SRCROOT)/build/watchsimulator/SDWebImage.framework", "$(SRCROOT)/build/maccatalyst/SDWebImage.framework", + "$(SRCROOT)/build/xros/SDWebImage.framework", + "$(SRCROOT)/build/xrsimulator/SDWebImage.framework", ); runOnlyForDeploymentPostprocessing = 0; 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 */ = { isa = PBXShellScriptBuildPhase; @@ -1161,6 +1163,8 @@ "$(SRCROOT)/build/watchos/SDWebImage.framework", "$(SRCROOT)/build/watchsimulator/SDWebImage.framework", "$(SRCROOT)/build/maccatalyst/SDWebImage.framework", + "$(SRCROOT)/build/xros/SDWebImage.framework", + "$(SRCROOT)/build/xrsimulator/SDWebImage.framework", ); name = "Create XCFramework"; outputFileListPaths = ( @@ -1170,7 +1174,7 @@ ); runOnlyForDeploymentPostprocessing = 0; 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 */ diff --git a/Scripts/build-frameworks.sh b/Scripts/build-frameworks.sh new file mode 100755 index 00000000..60744f49 --- /dev/null +++ b/Scripts/build-frameworks.sh @@ -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 diff --git a/Scripts/create-xcframework.sh b/Scripts/create-xcframework.sh new file mode 100755 index 00000000..c6905ea0 --- /dev/null +++ b/Scripts/create-xcframework.sh @@ -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" From b231b2c55e67c04abab2043a8b76d7c73c557a5d Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Mon, 11 Sep 2023 15:21:28 +0800 Subject: [PATCH 2/4] Update the README.md about the installation guide --- README.md | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index bf76153c..a9a971df 100644 --- a/README.md +++ b/README.md @@ -41,9 +41,11 @@ Note: `SD` is the prefix for **Simple Design** (which is the team name in Daily From 5.18.0, SDWebImage can be compiled for visionOS platform. However, it's still in beta and may contains issues unlike the stable iOS UIKit support. Welcome to have a try and [report issue](https://github.com/SDWebImage/SDWebImage/issues). -To build on visionOS, currently we only support the standard Xcode integration. Which means, open that `SDWebImage.xcodeproj` (Xcode 15+), then choose the target to build as library, framework or XCFramework (supports static and dynamic), and integrate to your visionOS App. +To build on visionOS, currently we only support the standard Xcode integration. -Once the visionOS toolchain is stable, we will add the package manager support later (include CocoaPods and SwiftPM). +See `Installation with Swift Package Manager` and `Manual Installation Guide` below. + +Once the visionOS toolchain is stable, we will add the other package manager support later (include CocoaPods). ## Supported Image Formats @@ -287,7 +289,31 @@ let package = Package( ### Manual Installation Guide -See more on [Manual install Guide](https://github.com/SDWebImage/SDWebImage/wiki/Installation-Guide#manual-installation-guide) ++ Check your command line Xcode version + +``` +sudo xcode-select -s /path/to/Xcode.app +``` + +or + +``` +export DEVELOPER_DIR=/path/to/Xcode.app/Contents/Developer +``` + ++ Run the script to build frameworks + +``` +./Scripts/build-frameworks.sh +``` + ++ Run the script to merge XCFramework + +``` +./Scripts/create-xcframework.sh +``` + +See more on wiki: [Manual install Guide](https://github.com/SDWebImage/SDWebImage/wiki/Installation-Guide#manual-installation-guide) ### Import headers in your source files From 99770368b5b301533f40675a5ff4d19a01db5f5b Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Mon, 11 Sep 2023 16:33:50 +0800 Subject: [PATCH 3/4] Update the build scripts with destination-based instead of sdk-based Which fix the issue on M1 Mac for x86_64 cross-build --- Scripts/build-frameworks.sh | 40 +++++++++++++++++++---------------- Scripts/create-xcframework.sh | 15 ++++++++++--- 2 files changed, 34 insertions(+), 21 deletions(-) diff --git a/Scripts/build-frameworks.sh b/Scripts/build-frameworks.sh index 60744f49..82a7dd32 100755 --- a/Scripts/build-frameworks.sh +++ b/Scripts/build-frameworks.sh @@ -1,5 +1,8 @@ #!/bin/bash +set -e +set -o pipefail + XCODE_VERSION=$(xcodebuild -version | head -n 1| awk -F ' ' '{print $2}') XCODE_VERSION_MAJOR=$(echo $XCODE_VERSION | awk -F '.' '{print $1}') if [ -z "$SRCROOT" ] @@ -8,32 +11,33 @@ then fi mkdir -p "${SRCROOT}/build" -declare -a PLATFORMS=("iphoneos" "iphonesimulator" "macosx" "appletvos" "appletvsimulator" "watchos" "watchsimulator" "maccatalyst") +PLATFORMS=("iOS" "iOSSimulator" "macOS" "tvOS" "tvOSSimulator" "watchOS" "watchOSSimulator") + +if [ $XCODE_VERSION_MAJOR -ge 11 ] +then + PLATFORMS+=("macCatalyst") +fi if [ $XCODE_VERSION_MAJOR -ge 15 ] then - PLATFORMS+=("xros") - PLATFORMS+=("xrsimulator") + PLATFORMS+=("visionOS") + PLATFORMS+=("visionOSSimulator") 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 + DESTINATION="generic/platform=${CURRENT_PLATFORM}" + # 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 + if [[ $CURRENT_PLATFORM == "macCatalyst" ]]; then + DESTINATION="generic/platform=macOS,variant=Mac Catalyst" 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/" + + # Simulator + if [[ $CURRENT_PLATFORM == *Simulator ]]; then + CURRENT_PLATFORM_OS=${CURRENT_PLATFORM%Simulator} + DESTINATION="generic/platform=${CURRENT_PLATFORM_OS} Simulator" fi + + xcodebuild build -project "SDWebImage.xcodeproj" -destination "${DESTINATION}" -scheme "SDWebImage" -configuration "Release" -derivedDataPath "${SRCROOT}/build/DerivedData" CONFIGURATION_BUILD_DIR="${SRCROOT}/build/${CURRENT_PLATFORM}/" done diff --git a/Scripts/create-xcframework.sh b/Scripts/create-xcframework.sh index c6905ea0..660b6d64 100755 --- a/Scripts/create-xcframework.sh +++ b/Scripts/create-xcframework.sh @@ -1,5 +1,8 @@ #!/bin/bash +set -e +set -o pipefail + XCODE_VERSION=$(xcodebuild -version | head -n 1| awk -F ' ' '{print $2}') XCODE_VERSION_MAJOR=$(echo $XCODE_VERSION | awk -F '.' '{print $1}') if [ -z "$SRCROOT" ] @@ -14,12 +17,18 @@ then exit 0 fi -declare -a PLATFORMS=("iphoneos" "iphonesimulator" "macosx" "appletvos" "appletvsimulator" "watchos" "watchsimulator") +mkdir -p "${SRCROOT}/build" +PLATFORMS=("iOS" "iOSSimulator" "macOS" "tvOS" "tvOSSimulator" "watchOS" "watchOSSimulator") + +if [ $XCODE_VERSION_MAJOR -ge 11 ] +then + PLATFORMS+=("macCatalyst") +fi if [ $XCODE_VERSION_MAJOR -ge 15 ] then - PLATFORMS+=("xros") - PLATFORMS+=("xrsimulator") + PLATFORMS+=("visionOS") + PLATFORMS+=("visionOSSimulator") fi COMMAND_ARGS="" From 50c8acefd72b944fab51e6ef0f5608f466b94b14 Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Mon, 11 Sep 2023 17:37:51 +0800 Subject: [PATCH 4/4] Remove the script target output file, since it's dynamic based --- SDWebImage.xcodeproj/project.pbxproj | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/SDWebImage.xcodeproj/project.pbxproj b/SDWebImage.xcodeproj/project.pbxproj index 5a4af183..1ed93492 100644 --- a/SDWebImage.xcodeproj/project.pbxproj +++ b/SDWebImage.xcodeproj/project.pbxproj @@ -1132,16 +1132,6 @@ outputFileListPaths = ( ); outputPaths = ( - "$(SRCROOT)/build/iphoneos/SDWebImage.framework", - "$(SRCROOT)/build/iphonesimulator/SDWebImage.framework", - "$(SRCROOT)/build/macosx/SDWebImage.framework", - "$(SRCROOT)/build/appletvos/SDWebImage.framework", - "$(SRCROOT)/build/appletvsimulator/SDWebImage.framework", - "$(SRCROOT)/build/watchos/SDWebImage.framework", - "$(SRCROOT)/build/watchsimulator/SDWebImage.framework", - "$(SRCROOT)/build/maccatalyst/SDWebImage.framework", - "$(SRCROOT)/build/xros/SDWebImage.framework", - "$(SRCROOT)/build/xrsimulator/SDWebImage.framework", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; @@ -1155,22 +1145,11 @@ inputFileListPaths = ( ); inputPaths = ( - "$(SRCROOT)/build/iphoneos/SDWebImage.framework", - "$(SRCROOT)/build/iphonesimulator/SDWebImage.framework", - "$(SRCROOT)/build/macosx/SDWebImage.framework", - "$(SRCROOT)/build/appletvos/SDWebImage.framework", - "$(SRCROOT)/build/appletvsimulator/SDWebImage.framework", - "$(SRCROOT)/build/watchos/SDWebImage.framework", - "$(SRCROOT)/build/watchsimulator/SDWebImage.framework", - "$(SRCROOT)/build/maccatalyst/SDWebImage.framework", - "$(SRCROOT)/build/xros/SDWebImage.framework", - "$(SRCROOT)/build/xrsimulator/SDWebImage.framework", ); name = "Create XCFramework"; outputFileListPaths = ( ); outputPaths = ( - "$(SRCROOT)/build/SDWebImage.xcframework", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh;