-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild
executable file
·213 lines (184 loc) · 5.36 KB
/
build
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#!/bin/zsh
# build
# A build script to generate universal xcframework for iOS and macOS platforms.
#
# Created by Jaseem V V on 14.04.2024.
#
# Clean build:
# ./build
# Build with individual steps
# ./build clean # deletes all archives and frameworks
# ./build archive
# ./build framework
# ./build sign
# Build xcframework for iOS only
# ./build ios
# Build xcframework for macOS only
# ./build macos
framework_name=""
project_name=""
scheme=""
# The directory where the xcarchive will be created
archive_dir="Archives"
# The directory where the xcframework will be generated
framework_dir="Frameworks"
configuration="Release"
ios_framework_name="$framework_name-iOS"
ios_simulator_framework_name="$framework_name-iOS-Simulator"
macos_framework_name="$framework_name-macOS"
macos_catalyst_framework_name="$framework_name-macOS-Catalyst"
# Apple Development certificate name as found in Keychain
code_sign_identity=""
# Platforms. Additional platforms can be added as needed.
declare -A ios_props=(
["destination"]="generic/platform=iOS"
["archive_path"]="$archive_dir/$ios_framework_name"
["sdk"]="iphoneos"
)
declare -A ios_simulator_props=(
["destination"]="generic/platform=iOS Simulator"
["archive_path"]="$archive_dir/$ios_simulator_framework_name"
["sdk"]="iphonesimulator"
)
declare -A macos_props=(
["destination"]="generic/platform=macOS"
["archive_path"]="$archive_dir/$macos_framework_name"
["sdk"]="macosx"
)
declare -A macos_catalyst_props=(
["destination"]="generic/platform=macOS,variant=Mac Catalyst"
["archive_path"]="$archive_dir/$macos_catalyst_framework_name"
["sdk"]="macosx"
)
declare -a destinations=(
ios_props
ios_simulator_props
macos_props
macos_catalyst_props
)
declare -a destinations_ios=(
ios_props
ios_simulator_props
)
declare -a destinations_macos=(
macos_props
)
function create_directory() {
dir_name=$1
if [ ! -d "$dir_name" ]; then
mkdir -p "$dir_name"
fi
}
function create_archive() {
destination=$1
archive_path=$2
sdk=$3
echo "Archiving for $destination"
xcodebuild archive \
-project "$project_name".xcodeproj \
-scheme "$scheme" \
-configuration "$configuration" \
-destination "$destination" \
-archivePath "$archive_path" \
-sdk "$sdk" \
SKIP_INSTALL=NO \
BUILD_LIBRARIES_FOR_DISTRIBUTION=YES \
SWIFT_SERIALIZE_DEBUGGING_OPTIONS=NO
}
function create_archives() {
local dest_list=("$@")
for dest_map in $dest_list; do
local -A dest=("${(Pkv@)dest_map}")
create_archive $dest[destination] $dest[archive_path] $dest[sdk]
echo
done
}
function create_xcframework_all() {
echo "Creating xcframework for iOS and macOS"
xcodebuild -create-xcframework \
-archive "$archive_dir/$ios_framework_name".xcarchive -framework "$framework_name".framework \
-archive "$archive_dir/$ios_simulator_framework_name".xcarchive -framework "$framework_name".framework \
-archive "$archive_dir/$macos_framework_name".xcarchive -framework "$framework_name".framework \
-archive "$archive_dir/$macos_catalyst_framework_name".xcarchive -framework "$framework_name".framework \
-output "$framework_dir/$framework_name".xcframework
}
function create_xcframework_ios() {
echo "Creating xcframework for iOS"
xcodebuild -create-xcframework \
-archive "$archive_dir/$ios_framework_name".xcarchive -framework "$framework_name".framework \
-archive "$archive_dir/$ios_simulator_framework_name".xcarchive -framework "$framework_name".framework \
-output "$framework_dir/$framework_name".xcframework
}
function create_xcframework_macos() {
echo "Creating xcframework for macOS"
xcodebuild -create-xcframework \
-archive "$archive_dir/$macos_framework_name".xcarchive -framework "$framework_name".framework \
-output "$framework_dir/$framework_name".xcframework
}
function archive_all() {
create_archives "$destinations[@]"
echo "Archive complete"
}
function archive_ios() {
create_archives "$destinations_ios[@]"
echo "Archive complete"
}
function archive_macos() {
create_archives "$destinations_macos[@]"
echo "Archive complete"
}
function code_sign() {
echo "Code signing"
codesign --timestamp -v -s "$code_sign_identity" "$framework_dir/$framework_name".xcframework
}
function clean_xcframework() {
rm -rf "$framework_dir"/*
}
function clean() {
echo "Cleanup"
rm -rf "$archive_dir"/*
clean_xcframework
}
opt=$1
# No arg, run all steps
if [ -z "$opt" ]; then
create_directory $archive_dir
create_directory $framework_dir
clean
archive_all
create_xcframework_all
code_sign
else
case $opt in
"archive")
archive_all
;;
"framework")
create_xcframework_all
;;
"sign")
code_sign
;;
"clean")
clean
;;
"clean-framework")
clean_xcframework
;;
"ios")
archive_ios
create_xcframework_ios
code_sign
;;
"macos")
archive_macos
create_xcframework_macos
code_sign
;;
*)
echo "Unknown argument"
exit 1
;;
esac
fi
exit 0