-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathbuild-xcframeworks.sh
executable file
·159 lines (129 loc) · 3.74 KB
/
build-xcframeworks.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#! /bin/sh
#
# Description:
# This script creates a binary framework for use with all supported platforms & architectures.
HELP="
build-xcframeworks -- build binary frameworks script.
Usage: build-xcframeworks [command]
Options (general):
-h, --help print help message.
-c, --clean clean the build directories on exit.
-o, --output xcframework output path.
"
# Release dir path
PROJECT_PATH=$PWD
BUILD_DIR=${PROJECT_PATH}/build
ARCHIVE_DIR=${BUILD_DIR}/archives
FRAMEWORKS_DIR=${BUILD_DIR}/Frameworks
FRAMEWORK_FILE=${FRAMEWORKS_DIR}/SKTiled.xcframework
# parse arguments
CLEAN_BUILD_DIRS=0
PARAMS=""
while (( "$#" )); do
case "$1" in
-h|--help)
printf '%s' "$HELP"
exit 0
shift
;;
-c|--clean)
CLEAN_BUILD_DIRS=1
shift
;;
-o|--output)
if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then
OUTPUT_PATH=$2
FRAMEWORK_FILE=${OUTPUT_PATH}/SKTiled.xcframework
shift 2
else
echo "Error: Argument for $1 is missing" >&2
exit 1
fi
;;
-*|--*=) # unsupported flags
echo "Error: Unsupported flag $1" >&2
exit 1
;;
*) # preserve positional arguments
PARAMS="$PARAMS $1"
shift
;;
esac
done
# set positional arguments in their proper place
eval set -- "$PARAMS"
# remove the build dir if it exists
if [ -d $BUILD_DIR ]
then
rm -rf $BUILD_DIR
fi
# remove the output file if it already exists
if [ -d $FRAMEWORK_FILE ]
then
rm -rf "$FRAMEWORK_FILE"
fi
mkdir $BUILD_DIR
mkdir $ARCHIVE_DIR
if [ ! -d $FRAMEWORKS_DIR ]
then
mkdir $FRAMEWORKS_DIR
fi
# archive the various platforms...
xcodebuild archive \
-project SKTiled.xcodeproj \
-scheme SKTiled-macOS \
-destination "generic/platform=macOS" \
-archivePath ${ARCHIVE_DIR}/SKTiled-macOS \
SKIP_INSTALL=NO \
BUILD_LIBRARY_FOR_DISTRIBUTION=YES | xcpretty
xcodebuild archive \
-project SKTiled.xcodeproj \
-scheme SKTiled-iOS \
-destination "generic/platform=iOS" \
-archivePath ${ARCHIVE_DIR}/SKTiled-iOS \
SKIP_INSTALL=NO \
BUILD_LIBRARY_FOR_DISTRIBUTION=YES | xcpretty
xcodebuild archive \
-project SKTiled.xcodeproj \
-scheme SKTiled-iOS \
-destination "generic/platform=iOS Simulator" \
-archivePath ${ARCHIVE_DIR}/SKTiled-iOS-Sim \
SKIP_INSTALL=NO \
BUILD_LIBRARY_FOR_DISTRIBUTION=YES | xcpretty
xcodebuild archive \
-project SKTiled.xcodeproj \
-scheme SKTiled-tvOS \
-destination "generic/platform=tvOS" \
-archivePath ${ARCHIVE_DIR}/SKTiled-tvOS \
SKIP_INSTALL=NO \
BUILD_LIBRARY_FOR_DISTRIBUTION=YES | xcpretty
xcodebuild archive \
-project SKTiled.xcodeproj \
-scheme SKTiled-tvOS \
-destination "generic/platform=tvOS Simulator" \
-archivePath ${ARCHIVE_DIR}/SKTiled-tvOS-Sim \
SKIP_INSTALL=NO \
BUILD_LIBRARY_FOR_DISTRIBUTION=YES | xcpretty
# create the xcframework
xcodebuild -create-xcframework \
-framework ${ARCHIVE_DIR}/SKTiled-macOS.xcarchive/Products/Library/Frameworks/SKTiled.framework \
-framework ${ARCHIVE_DIR}/SKTiled-iOS.xcarchive/Products/Library/Frameworks/SKTiled.framework \
-framework ${ARCHIVE_DIR}/SKTiled-iOS-Sim.xcarchive/Products/Library/Frameworks/SKTiled.framework \
-framework ${ARCHIVE_DIR}/SKTiled-tvOS.xcarchive/Products/Library/Frameworks/SKTiled.framework \
-framework ${ARCHIVE_DIR}/SKTiled-tvOS-Sim.xcarchive/Products/Library/Frameworks/SKTiled.framework \
-output ${BUILD_DIR}/SKTiled.xcframework | xcpretty
# move the resulting framework to the output directory
mv ${BUILD_DIR}/SKTiled.xcframework $FRAMEWORK_FILE
if [ -d $FRAMEWORK_FILE ]
then
echo "▶︎ writing xcframework to '${FRAMEWORK_FILE}'"
else
echo "Error creating framework file '${FRAMEWORK_FILE}'"
exit 1
fi
# cleanup build directory on exit
if [ $CLEAN_BUILD_DIRS = 1 ]
then
echo "▶︎ cleaning up archives '${BUILD_DIR}'"
rm -rf "$BUILD_DIR"
fi