Skip to content

Commit

Permalink
Build a multi-platform XCFramework for releases
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyarnold committed Feb 11, 2022
1 parent 3e1835c commit 5520fda
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 13 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/deploy-release-artifacts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ jobs:
uses: actions/checkout@v2

- name: Create XCFramework
uses: philprime/swift-create-xcframework@v2
run: ./Scripts/build-xcframework.sh
env:
PROJECT_FILE: Differ.xcodeproj
SCHEME_NAME: Differ
OUTPUT_DIR: ${{ runner.temp }}

- name: Release XCFramework
uses: softprops/action-gh-release@v1
with:
fail_on_unmatched_files: true
files: |
Differ-*.zip
Differ-*.sha256
files: ${{ runner.temp }}/Differ.xcframework.zip
48 changes: 48 additions & 0 deletions Scripts/build-xcframework.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env bash

set -o errexit
set -o nounset

OUTPUT_DIR=${OUTPUT_DIR?error: Please provide the build directory via the 'OUTPUT_DIR' environment variable}
PROJECT_FILE=${PROJECT_FILE?error: Please provide the Xcode project file name via the 'PROJECT_FILE' environment variable}
SCHEME_NAME=${SCHEME_NAME?error: Please provide the Xcode scheme to build via the 'SCHEME_NAME' environment variable}

# Generate iOS framework
xcodebuild -project "${PROJECT_FILE}" -configuration Release -archivePath "${OUTPUT_DIR}/${SCHEME_NAME}-iphoneos.xcarchive" -destination "generic/platform=iOS" SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES -scheme "${SCHEME_NAME}" archive

# Generate iOS Simulator framework
xcodebuild -project "${PROJECT_FILE}" -configuration Release -archivePath "${OUTPUT_DIR}/${SCHEME_NAME}-iossimulator.xcarchive" -destination "generic/platform=iOS Simulator" SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES -scheme "${SCHEME_NAME}" archive

# Generate macOS framework
xcodebuild -project "${PROJECT_FILE}" -configuration Release -archivePath "${OUTPUT_DIR}/${SCHEME_NAME}-macosx.xcarchive" -destination "generic/platform=macOS,name=Any Mac" SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES -scheme "${SCHEME_NAME}" archive

# Generate macOS Catalyst framework
xcodebuild -project "${PROJECT_FILE}" -configuration Release -archivePath "${OUTPUT_DIR}/${SCHEME_NAME}-maccatalyst.xcarchive" -destination "generic/platform=macOS,variant=Mac Catalyst" SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES SUPPORTS_MACCATALYST=YES -scheme "${SCHEME_NAME}" archive

# Generate tvOS framework
xcodebuild -project "${PROJECT_FILE}" -configuration Release -archivePath "${OUTPUT_DIR}/${SCHEME_NAME}-appletvos.xcarchive" -destination "generic/platform=tvOS" SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES -scheme "${SCHEME_NAME}" archive

# Generate tvOS Simulator framework
xcodebuild -project "${PROJECT_FILE}" -configuration Release -archivePath "${OUTPUT_DIR}/${SCHEME_NAME}-appletvsimulator.xcarchive" -destination "generic/platform=tvOS Simulator" SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES -scheme "${SCHEME_NAME}" archive

# Generate watchOS framework
xcodebuild -project "${PROJECT_FILE}" -configuration Release -archivePath "${OUTPUT_DIR}/${SCHEME_NAME}-watchos.xcarchive" -destination "generic/platform=watchOS" SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES -scheme "${SCHEME_NAME}" archive

# Generate watchOS Simulator framework
xcodebuild -project "${PROJECT_FILE}" -configuration Release -archivePath "${OUTPUT_DIR}/${SCHEME_NAME}-watchsimulator.xcarchive" -destination "generic/platform=watchOS Simulator" SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES -scheme "${SCHEME_NAME}" archive

# Generate XCFramework
xcodebuild -create-xcframework \
-archive "${OUTPUT_DIR}/${SCHEME_NAME}-appletvos.xcarchive" -framework "${SCHEME_NAME}.framework" \
-archive "${OUTPUT_DIR}/${SCHEME_NAME}-appletvsimulator.xcarchive" -framework "${SCHEME_NAME}.framework" \
-archive "${OUTPUT_DIR}/${SCHEME_NAME}-iphoneos.xcarchive" -framework "${SCHEME_NAME}.framework" \
-archive "${OUTPUT_DIR}/${SCHEME_NAME}-iossimulator.xcarchive" -framework "${SCHEME_NAME}.framework" \
-archive "${OUTPUT_DIR}/${SCHEME_NAME}-macosx.xcarchive" -framework "${SCHEME_NAME}.framework" \
-archive "${OUTPUT_DIR}/${SCHEME_NAME}-maccatalyst.xcarchive" -framework "${SCHEME_NAME}.framework" \
-archive "${OUTPUT_DIR}/${SCHEME_NAME}-watchos.xcarchive" -framework "${SCHEME_NAME}.framework" \
-archive "${OUTPUT_DIR}/${SCHEME_NAME}-watchsimulator.xcarchive" -framework "${SCHEME_NAME}.framework" \
-output "${OUTPUT_DIR}/${SCHEME_NAME}.xcframework"

# Zip it!
ditto -c -k --rsrc --keepParent "${OUTPUT_DIR}/${SCHEME_NAME}.xcframework" "${OUTPUT_DIR}/${SCHEME_NAME}.xcframework.zip"
rm -rf "${OUTPUT_DIR}/${SCHEME_NAME}.xcframework"
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "Universal-Target-Base.xcconfig"

// OSX-specific default settings
// macOS-specific default settings
FRAMEWORK_VERSION[sdk=macosx*] = A
COMBINE_HIDPI_IMAGES[sdk=macosx*] = YES

Expand Down
11 changes: 3 additions & 8 deletions Supporting Files/Configurations/Universal-Target-Base.xcconfig
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
SUPPORTED_PLATFORMS = macosx iphonesimulator iphoneos watchos watchsimulator appletvos appletvsimulator
VALID_ARCHS[sdk=macosx*] = i386 x86_64 arm64
VALID_ARCHS[sdk=iphone*] = arm64 armv7 armv7s
VALID_ARCHS[sdk=iphonesimulator*] = i386 x86_64
VALID_ARCHS[sdk=watch*] = armv7k
VALID_ARCHS[sdk=watchsimulator*] = i386 x86_64
VALID_ARCHS[sdk=appletv*] = arm64
VALID_ARCHS[sdk=appletvsimulator*] = i386 x86_64
ALLOW_TARGET_PLATFORM_SPECIALIZATION = YES
SUPPORTED_PLATFORMS = macosx iphonesimulator iphoneos watchos watchsimulator appletvos appletvsimulator
SUPPORTS_MACCATALYST = YES

// Dynamic linking uses different default copy paths
LD_RUNPATH_SEARCH_PATHS[sdk=macosx*] = $(inherited) '@executable_path/../Frameworks' '@loader_path/../Frameworks'
Expand Down

0 comments on commit 5520fda

Please sign in to comment.