|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# xcframework.sh |
| 4 | +# Usage example: ./xcframework.sh -output <some_path>/ProtocolProxy.xcframework |
| 5 | + |
| 6 | +# Parse Arguments |
| 7 | + |
| 8 | +while [[ $# -gt 0 ]]; do |
| 9 | + case "$1" in |
| 10 | + -output) |
| 11 | + OUTPUT_DIR="$2" |
| 12 | + shift # -output |
| 13 | + shift # <output_dir> |
| 14 | + ;; |
| 15 | + |
| 16 | + *) |
| 17 | + echo "Unknown argument: $1" |
| 18 | + echo "./xcframework.sh [-output <output_xcframework>]"] |
| 19 | + exit 1 |
| 20 | + esac |
| 21 | +done |
| 22 | + |
| 23 | +if [ -z ${OUTPUT_DIR+x} ]; then |
| 24 | + OUTPUT_DIR="$(dirname $(realpath $0))/build/ProtocolProxy.xcframework" |
| 25 | +fi |
| 26 | + |
| 27 | +# Create Temporary Directory |
| 28 | + |
| 29 | +TMPDIR=`mktemp -d /tmp/.protocolproxy.xcframework.build.XXXXXX` |
| 30 | +cd "$(dirname $(dirname $(realpath $0)))" |
| 31 | + |
| 32 | +check_result() { |
| 33 | + if [ $1 -ne 0 ]; then |
| 34 | + rm -rf "${TMPDIR}" |
| 35 | + exit $1 |
| 36 | + fi |
| 37 | +} |
| 38 | + |
| 39 | +# Build iOS |
| 40 | +xcodebuild -project "ProtocolProxy.xcodeproj" -scheme "ProtocolProxy" -destination "generic/platform=iOS" -archivePath "${TMPDIR}/iphoneos.xcarchive" -configuration Release SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES ONLY_ACTIVE_ARCH=NO ARCHS="armv7 armv7s arm64 arm64e" archive |
| 41 | +check_result $? |
| 42 | + |
| 43 | +# Build iOS Simulator |
| 44 | +xcodebuild -project "ProtocolProxy.xcodeproj" -scheme "ProtocolProxy" -destination "generic/platform=iOS Simulator" -archivePath "${TMPDIR}/iphonesimulator.xcarchive" -configuration Release SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES ONLY_ACTIVE_ARCH=NO ARCHS="i386 x86_64 arm64" archive |
| 45 | +check_result $? |
| 46 | + |
| 47 | +# Build Mac Catalyst |
| 48 | +xcodebuild -project "ProtocolProxy.xcodeproj" -scheme "ProtocolProxy" -destination "generic/platform=macOS,variant=Mac Catalyst" -archivePath "${TMPDIR}/maccatalyst.xcarchive" -configuration Release SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES ONLY_ACTIVE_ARCH=NO ARCHS="x86_64 arm64 arm64e" archive |
| 49 | +check_result $? |
| 50 | + |
| 51 | +# Build Mac |
| 52 | +xcodebuild -project "ProtocolProxy.xcodeproj" -scheme "ProtocolProxy macOS" -destination "generic/platform=macOS" -archivePath "${TMPDIR}/macos.xcarchive" -configuration Release SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES ONLY_ACTIVE_ARCH=NO ARCHS="x86_64 arm64 arm64e" archive |
| 53 | +check_result $? |
| 54 | + |
| 55 | +# Build tvOS |
| 56 | +xcodebuild -project "ProtocolProxy.xcodeproj" -scheme "ProtocolProxy tvOS" -destination "generic/platform=tvOS" -archivePath "${TMPDIR}/appletvos.xcarchive" -configuration Release SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES ONLY_ACTIVE_ARCH=NO ARCHS="arm64 arm64e" archive |
| 57 | +check_result $? |
| 58 | + |
| 59 | +# Build tvOS Simulator |
| 60 | +xcodebuild -project "ProtocolProxy.xcodeproj" -scheme "ProtocolProxy tvOS" -destination "generic/platform=tvOS Simulator" -archivePath "${TMPDIR}/appletvsimulator.xcarchive" -configuration Release SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES ONLY_ACTIVE_ARCH=NO ARCHS="x86_64 arm64" archive |
| 61 | +check_result $? |
| 62 | + |
| 63 | +# Build watchOS |
| 64 | +xcodebuild -project "ProtocolProxy.xcodeproj" -scheme "ProtocolProxy watchOS" -destination "generic/platform=watchOS" -archivePath "${TMPDIR}/watchos.xcarchive" -configuration Release SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES ONLY_ACTIVE_ARCH=NO ARCHS="arm64_32 armv7k" archive |
| 65 | +check_result $? |
| 66 | + |
| 67 | +# Build watchOS Simulator |
| 68 | +xcodebuild -project "ProtocolProxy.xcodeproj" -scheme "ProtocolProxy watchOS" -destination "generic/platform=watchOS Simulator" -archivePath "${TMPDIR}/watchsimulator.xcarchive" -configuration Release SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES ONLY_ACTIVE_ARCH=NO ARCHS="i386 x86_64 arm64" archive |
| 69 | +check_result $? |
| 70 | + |
| 71 | +# Make XCFramework |
| 72 | + |
| 73 | +if [[ -d "${OUTPUT_DIR}" ]]; then |
| 74 | + rm -rf "${OUTPUT_DIR}" |
| 75 | +fi |
| 76 | + |
| 77 | +xcodebuild -create-xcframework \ |
| 78 | + -framework "${TMPDIR}/iphoneos.xcarchive/Products/Library/Frameworks/ProtocolProxy.framework" \ |
| 79 | + -framework "${TMPDIR}/iphonesimulator.xcarchive/Products/Library/Frameworks/ProtocolProxy.framework" \ |
| 80 | + -framework "${TMPDIR}/maccatalyst.xcarchive/Products/Library/Frameworks/ProtocolProxy.framework" \ |
| 81 | + -framework "${TMPDIR}/macos.xcarchive/Products/Library/Frameworks/ProtocolProxy.framework" \ |
| 82 | + -framework "${TMPDIR}/appletvos.xcarchive/Products/Library/Frameworks/ProtocolProxy.framework" \ |
| 83 | + -framework "${TMPDIR}/appletvsimulator.xcarchive/Products/Library/Frameworks/ProtocolProxy.framework" \ |
| 84 | + -framework "${TMPDIR}/watchos.xcarchive/Products/Library/Frameworks/ProtocolProxy.framework" \ |
| 85 | + -framework "${TMPDIR}/watchsimulator.xcarchive/Products/Library/Frameworks/ProtocolProxy.framework" \ |
| 86 | + -output "${OUTPUT_DIR}" |
| 87 | +check_result $? |
| 88 | + |
| 89 | +# Cleanup |
| 90 | + |
| 91 | +rm -rf "${TMPDIR}" |
| 92 | +exit 0 |
0 commit comments