Skip to content

Improve XCFramework build process & usage. #238

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/swift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
- uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.SOVRAN_SSH_KEY }}
- run: xcodebuild -scheme Segment-Package test -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 13'
- run: xcodebuild -scheme Segment test -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 13'


build_and_test_tvos:
Expand All @@ -71,7 +71,7 @@ jobs:
- uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.SOVRAN_SSH_KEY }}
- run: xcodebuild -scheme Segment-Package test -sdk appletvsimulator -destination 'platform=tvOS Simulator,name=Apple TV'
- run: xcodebuild -scheme Segment test -sdk appletvsimulator -destination 'platform=tvOS Simulator,name=Apple TV'

build_and_test_watchos:
needs: cancel_previous
Expand All @@ -84,7 +84,7 @@ jobs:
- uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.SOVRAN_SSH_KEY }}
- run: xcodebuild -scheme Segment-Package test -sdk watchsimulator -destination 'platform=watchOS Simulator,name=Apple Watch Series 8 (45mm)'
- run: xcodebuild -scheme Segment test -sdk watchsimulator -destination 'platform=watchOS Simulator,name=Apple Watch Series 8 (45mm)'

build_and_test_examples:
needs: cancel_previous
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,4 @@ Segment-Package_XCFramework
Segment.xcframework.zip
Segment.xcframework
XCFrameworkOutput

*.sha256
26 changes: 0 additions & 26 deletions Segment.xcodeproj/Segment_Info.plist

This file was deleted.

25 changes: 0 additions & 25 deletions Segment.xcodeproj/Segment_Tests_Info.plist

This file was deleted.

986 changes: 0 additions & 986 deletions Segment.xcodeproj/project.pbxproj

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

69 changes: 0 additions & 69 deletions Segment.xcodeproj/xcshareddata/xcschemes/Segment-Package.xcscheme

This file was deleted.

137 changes: 24 additions & 113 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,115 +1,26 @@
#!/bin/zsh

# Set Project name
# These are the only variables that need to be set per-project, the rest
# is very generic and should work for most things.
PROJECT_NAME="Segment"
SCHEME_NAME="Segment-Package"

# Your PROJECT_NAME.xcodeproj should include schemes for
# iOS
# tvOS
# watchOS
# macOS
# Mac Catalyst

XCFRAMEWORK_OUTPUT_PATH="./XCFrameworkOutput"

# clean up old releases
echo "Removing previous ${PROJECT_NAME}.xcframework.zip"
rm -rf ${PROJECT_NAME}.xcframework.zip
rm -rf ${PROJECT_NAME}.xcframework
rm -rf ${XCFRAMEWORK_OUTPUT_PATH}

mkdir "${XCFRAMEWORK_OUTPUT_PATH}"
echo "Created ${XCFRAMEWORK_OUTPUT_PATH}"

# iOS Related Slices
echo "Building iOS Slices ..."
xcodebuild archive \
-scheme "${SCHEME_NAME}" \
-destination "generic/platform=iOS" \
-archivePath "${XCFRAMEWORK_OUTPUT_PATH}/iOS" \
SKIP_INSTALL=NO \
BUILD_LIBRARY_FOR_DISTRIBUTION=YES

xcodebuild archive \
ONLY_ACTIVE_ARCH=NO \
-scheme "${SCHEME_NAME}" \
-destination "generic/platform=iOS Simulator" \
-archivePath "${XCFRAMEWORK_OUTPUT_PATH}/iOSSimulator" \
SKIP_INSTALL=NO \
BUILD_LIBRARY_FOR_DISTRIBUTION=YES

# tvOS Related Slices
echo "Building tvOS Slices ..."
xcodebuild archive \
-scheme "${SCHEME_NAME}" \
-destination "generic/platform=tvOS" \
-archivePath "${XCFRAMEWORK_OUTPUT_PATH}/tvOS" \
SKIP_INSTALL=NO \
BUILD_LIBRARY_FOR_DISTRIBUTION=YES

xcodebuild archive \
ONLY_ACTIVE_ARCH=NO \
-scheme "${SCHEME_NAME}" \
-destination "generic/platform=tvOS Simulator" \
-archivePath "${XCFRAMEWORK_OUTPUT_PATH}/tvOSSimulator" \
SKIP_INSTALL=NO \
BUILD_LIBRARY_FOR_DISTRIBUTION=YES

# watchOS Related Slices
echo "Building watchOS Slices ..."
xcodebuild archive \
-scheme "${SCHEME_NAME}" \
-destination "generic/platform=watchOS" \
-archivePath "${XCFRAMEWORK_OUTPUT_PATH}/watchOS" \
SKIP_INSTALL=NO \
BUILD_LIBRARY_FOR_DISTRIBUTION=YES

xcodebuild archive \
ONLY_ACTIVE_ARCH=NO \
-scheme "${SCHEME_NAME}" \
-destination "generic/platform=watchOS Simulator" \
-archivePath "${XCFRAMEWORK_OUTPUT_PATH}/watchOSSimulator" \
SKIP_INSTALL=NO \
BUILD_LIBRARY_FOR_DISTRIBUTION=YES

# macOS Related Slices
echo "Building macOS Slices ..."

xcodebuild archive \
ONLY_ACTIVE_ARCH=NO \
-scheme "${SCHEME_NAME}" \
-destination "generic/platform=macOS" \
-archivePath "${XCFRAMEWORK_OUTPUT_PATH}/macOS" \
SKIP_INSTALL=NO \
BUILD_LIBRARY_FOR_DISTRIBUTION=YES

xcodebuild archive \
ONLY_ACTIVE_ARCH=NO \
-scheme "${SCHEME_NAME}" \
-destination "generic/platform=macOS,variant=Mac Catalyst,name=Any Mac" \
-archivePath "${XCFRAMEWORK_OUTPUT_PATH}/macOSCatalyst" \
SKIP_INSTALL=NO \
BUILD_LIBRARY_FOR_DISTRIBUTION=YES

# Combine all the slices into XCFramework
echo "Combining Slices into XCFramework ..."
xcodebuild -create-xcframework \
-framework ./${XCFRAMEWORK_OUTPUT_PATH}/iOS.xcarchive/Products/Library/Frameworks/${PROJECT_NAME}.framework \
-framework ./${XCFRAMEWORK_OUTPUT_PATH}/iOSSimulator.xcarchive/Products/Library/Frameworks/${PROJECT_NAME}.framework \
-framework ./${XCFRAMEWORK_OUTPUT_PATH}/tvOS.xcarchive/Products/Library/Frameworks/${PROJECT_NAME}.framework \
-framework ./${XCFRAMEWORK_OUTPUT_PATH}/tvOSSimulator.xcarchive/Products/Library/Frameworks/${PROJECT_NAME}.framework \
-framework ./${XCFRAMEWORK_OUTPUT_PATH}/watchOS.xcarchive/Products/Library/Frameworks/${PROJECT_NAME}.framework \
-framework ./${XCFRAMEWORK_OUTPUT_PATH}/watchOSSimulator.xcarchive/Products/Library/Frameworks/${PROJECT_NAME}.framework \
-framework ./${XCFRAMEWORK_OUTPUT_PATH}/macOS.xcarchive/Products/Library/Frameworks/${PROJECT_NAME}.framework \
-framework ./${XCFRAMEWORK_OUTPUT_PATH}/macOSCatalyst.xcarchive/Products/Library/Frameworks/${PROJECT_NAME}.framework \
-output "./${XCFRAMEWORK_OUTPUT_PATH}/${PROJECT_NAME}.xcframework"

# Zip it up!

echo "Zipping up ${PROJECT_NAME}.xcframework ..."
zip -r ${PROJECT_NAME}.xcframework.zip "./${XCFRAMEWORK_OUTPUT_PATH}/${PROJECT_NAME}.xcframework"

echo "Done."
# check if `swift-create-xcframework` tool is installed.
# command will return non-zero if not.
if ! command -v swift-create-xcframework &> /dev/null
then
echo "Swift's create-xcframework tool is required, but could not be found."
echo "Install it via:"
echo " $ brew install mint"
echo " $ mint install unsignedapps/swift-create-xcframework"
echo ""
exit 1
fi

echo "Removing old files ..."

rm Segment.zip
rm Sovran.zip
rm Segment.sha256
rm Sovran.sha256

echo "Building XCFrameworks ..."

swift create-xcframework --clean --platform ios --platform macos --platform maccatalyst --platform tvos --platform watchos --stack-evolution --zip Segment Sovran

echo "Done."
19 changes: 18 additions & 1 deletion release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ then
exit 1
fi

# check if `swift-create-xcframework` tool is installed.
# command will return non-zero if not.
if ! command -v swift-create-xcframework &> /dev/null
then
echo "Swift's create-xcframework tool is required, but could not be found."
echo "Install it via:"
echo " $ brew install mint"
echo " $ mint install unsignedapps/swift-create-xcframework"
echo ""
exit 1
fi

# check if `gh` tool has auth access.
# command will return non-zero if not auth'd.
authd=$(gh auth status -t)
Expand Down Expand Up @@ -132,4 +144,9 @@ rm $tempFile
./build.sh

# upload the release
gh release upload $newVersion ${PRODUCT_NAME}.xcframework.zip
gh release upload $newVersion ${PRODUCT_NAME}.zip
gh release upload $newVersion ${PRODUCT_NAME}.sha256

# SPECIAL CASE: We need to upload Sovran to save them time.
gh release upload $newVersion Sovran.zip
gh release upload $newVersion Sovran.sha256