-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
apple-xcframework.sh
executable file
·520 lines (428 loc) · 19.8 KB
/
apple-xcframework.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
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
#! /bin/sh
export PREFIX="$(pwd)/libsodium-apple"
export MACOS_ARM64_PREFIX="${PREFIX}/tmp/macos-arm64"
export MACOS_X86_64_PREFIX="${PREFIX}/tmp/macos-x86_64"
export IOS32_PREFIX="${PREFIX}/tmp/ios32"
export IOS32s_PREFIX="${PREFIX}/tmp/ios32s"
export IOS64_PREFIX="${PREFIX}/tmp/ios64"
export IOS_SIMULATOR_ARM64_PREFIX="${PREFIX}/tmp/ios-simulator-arm64"
export IOS_SIMULATOR_I386_PREFIX="${PREFIX}/tmp/ios-simulator-i386"
export IOS_SIMULATOR_X86_64_PREFIX="${PREFIX}/tmp/ios-simulator-x86_64"
export WATCHOS32_PREFIX="${PREFIX}/tmp/watchos32"
export WATCHOS64_32_PREFIX="${PREFIX}/tmp/watchos64_32"
export WATCHOS64_PREFIX="${PREFIX}/tmp/watchos64"
export WATCHOS_SIMULATOR_ARM64_PREFIX="${PREFIX}/tmp/watchos-simulator-arm64"
export WATCHOS_SIMULATOR_I386_PREFIX="${PREFIX}/tmp/watchos-simulator-i386"
export WATCHOS_SIMULATOR_X86_64_PREFIX="${PREFIX}/tmp/watchos-simulator-x86_64"
export TVOS_PREFIX="${PREFIX}/tmp/tvos"
export TVOS_SIMULATOR_ARM64_PREFIX="${PREFIX}/tmp/tvos-simulator-arm64"
export TVOS_SIMULATOR_X86_64_PREFIX="${PREFIX}/tmp/tvos-simulator-x86_64"
export VISIONOS_PREFIX="${PREFIX}/tmp/visionos"
export VISIONOS_SIMULATOR_PREFIX="${PREFIX}/tmp/visionos-simulator"
export CATALYST_ARM64_PREFIX="${PREFIX}/tmp/catalyst-arm64"
export CATALYST_X86_64_PREFIX="${PREFIX}/tmp/catalyst-x86_64"
export LOG_FILE="${PREFIX}/tmp/build_log"
export XCODEDIR="$(xcode-select -p)"
export MACOS_VERSION_MIN=${MACOS_VERSION_MIN-"10.10"}
export IOS_VERSION_MIN=${IOS_VERSION_MIN-"9.0.0"}
export IOS_SIMULATOR_VERSION_MIN=${IOS_SIMULATOR_VERSION_MIN-$IOS_VERSION_MIN}
export WATCHOS_VERSION_MIN=${WATCHOS_VERSION_MIN-"4.0.0"}
export WATCHOS_SIMULATOR_VERSION_MIN=${WATCHOS_SIMULATOR_VERSION_MIN-$WATCHOS_VERSION_MIN}
export TVOS_VERSION_MIN=${TVOS_VERSION_MIN-"9.0.0"}
export TVOS_SIMULATOR_VERSION_MIN=${TVOS_SIMULATOR_VERSION_MIN-$TVOS_VERSION_MIN}
echo
echo "Warnings related to headers being present but not usable are due to functions"
echo "that didn't exist in the specified minimum iOS version level."
echo "They can be safely ignored."
echo
echo "Define the LIBSODIUM_FULL_BUILD environment variable to build the full"
echo "library (including all deprecated/undocumented/low-level functions)."
echo
echo "Define the LIBSODIUM_SKIP_SIMULATORS environment variable to skip building"
echo "the simulators libraries (iOS, watchOS, tvOS, visionOS simulators)."
echo
if [ -z "$LIBSODIUM_FULL_BUILD" ]; then
export LIBSODIUM_ENABLE_MINIMAL_FLAG="--enable-minimal"
else
export LIBSODIUM_ENABLE_MINIMAL_FLAG=""
fi
IOS32_SUPPORTED=false
[ "$(echo "$IOS_VERSION_MIN" | cut -d'.' -f1)" -lt "11" ] && IOS32_SUPPORTED=true
I386_SIMULATOR_SUPPORTED=false
[ "$(echo "$IOS_SIMULATOR_VERSION_MIN" | cut -d'.' -f1)" -lt "11" ] && I386_SIMULATOR_SUPPORTED=true
VISIONOS_SUPPORTED=false
[ -d "${XCODEDIR}/Platforms/XROS.platform" ] && VISIONOS_SUPPORTED=true
NPROCESSORS=$(getconf NPROCESSORS_ONLN 2>/dev/null || getconf _NPROCESSORS_ONLN 2>/dev/null)
PROCESSORS=${NPROCESSORS:-3}
swift_module_map() {
echo 'module Clibsodium {'
echo ' header "sodium.h"'
echo ' export *'
echo '}'
}
build_macos() {
export BASEDIR="${XCODEDIR}/Platforms/MacOSX.platform/Developer"
export PATH="${BASEDIR}/usr/bin:$BASEDIR/usr/sbin:$PATH"
## macOS arm64
export CFLAGS="-O3 -arch arm64 -mmacosx-version-min=${MACOS_VERSION_MIN}"
export LDFLAGS="-arch arm64 -mmacosx-version-min=${MACOS_VERSION_MIN}"
make distclean >/dev/null 2>&1
./configure --host=aarch64-apple-darwin23 --prefix="$MACOS_ARM64_PREFIX" \
${LIBSODIUM_ENABLE_MINIMAL_FLAG} || exit 1
make -j${PROCESSORS} install || exit 1
## macOS x86_64
export CFLAGS="-O3 -arch x86_64 -mmacosx-version-min=${MACOS_VERSION_MIN}"
export LDFLAGS="-arch x86_64 -mmacosx-version-min=${MACOS_VERSION_MIN}"
make distclean >/dev/null 2>&1
./configure --host=x86_64-apple-darwin23 --prefix="$MACOS_X86_64_PREFIX" \
${LIBSODIUM_ENABLE_MINIMAL_FLAG} || exit 1
make -j${PROCESSORS} install || exit 1
}
build_ios() {
export BASEDIR="${XCODEDIR}/Platforms/iPhoneOS.platform/Developer"
export PATH="${BASEDIR}/usr/bin:$BASEDIR/usr/sbin:$PATH"
export SDK="${BASEDIR}/SDKs/iPhoneOS.sdk"
if [ "$IOS32_SUPPORTED" = true ]; then
## 32-bit iOS
export CFLAGS="-O3 -mthumb -arch armv7 -isysroot ${SDK} -mios-version-min=${IOS_VERSION_MIN}"
export LDFLAGS="-mthumb -arch armv7 -isysroot ${SDK} -mios-version-min=${IOS_VERSION_MIN}"
make distclean >/dev/null 2>&1
./configure --host=arm-apple-darwin23 --prefix="$IOS32_PREFIX" \
${LIBSODIUM_ENABLE_MINIMAL_FLAG} || exit 1
make -j${PROCESSORS} install || exit 1
## 32-bit armv7s iOS
export CFLAGS="-O3 -mthumb -arch armv7s -isysroot ${SDK} -mios-version-min=${IOS_VERSION_MIN}"
export LDFLAGS="-mthumb -arch armv7s -isysroot ${SDK} -mios-version-min=${IOS_VERSION_MIN}"
make distclean >/dev/null 2>&1
./configure --host=arm-apple-darwin23 --prefix="$IOS32s_PREFIX" \
${LIBSODIUM_ENABLE_MINIMAL_FLAG} || exit 1
make -j${PROCESSORS} install || exit 1
fi
## 64-bit iOS
export CFLAGS="-O3 -arch arm64 -isysroot ${SDK} -mios-version-min=${IOS_VERSION_MIN}"
export LDFLAGS="-arch arm64 -isysroot ${SDK} -mios-version-min=${IOS_VERSION_MIN}"
make distclean >/dev/null 2>&1
./configure --host=aarch64-apple-darwin23 --prefix="$IOS64_PREFIX" \
${LIBSODIUM_ENABLE_MINIMAL_FLAG} || exit 1
make -j${PROCESSORS} install || exit 1
}
build_ios_simulator() {
export BASEDIR="${XCODEDIR}/Platforms/iPhoneSimulator.platform/Developer"
export PATH="${BASEDIR}/usr/bin:$BASEDIR/usr/sbin:$PATH"
export SDK="${BASEDIR}/SDKs/iPhoneSimulator.sdk"
## arm64 simulator
export CFLAGS="-O3 -arch arm64 -isysroot ${SDK} -mios-simulator-version-min=${IOS_SIMULATOR_VERSION_MIN}"
export LDFLAGS="-arch arm64 -isysroot ${SDK} -mios-simulator-version-min=${IOS_SIMULATOR_VERSION_MIN}"
make distclean >/dev/null 2>&1
./configure --host=aarch64-apple-darwin23 --prefix="$IOS_SIMULATOR_ARM64_PREFIX" \
${LIBSODIUM_ENABLE_MINIMAL_FLAG} || exit 1
make -j${PROCESSORS} install || exit 1
if [ "$I386_SIMULATOR_SUPPORTED" = true ]; then
## i386 simulator
export CFLAGS="-O3 -arch i386 -isysroot ${SDK} -mios-simulator-version-min=${IOS_SIMULATOR_VERSION_MIN}"
export LDFLAGS="-arch i386 -isysroot ${SDK} -mios-simulator-version-min=${IOS_SIMULATOR_VERSION_MIN}"
make distclean >/dev/null 2>&1
./configure --host=i686-apple-darwin23 --prefix="$IOS_SIMULATOR_I386_PREFIX" \
${LIBSODIUM_ENABLE_MINIMAL_FLAG} || exit 1
make -j${PROCESSORS} install || exit 1
fi
## x86_64 simulator
export CFLAGS="-O3 -arch x86_64 -isysroot ${SDK} -mios-simulator-version-min=${IOS_SIMULATOR_VERSION_MIN}"
export LDFLAGS="-arch x86_64 -isysroot ${SDK} -mios-simulator-version-min=${IOS_SIMULATOR_VERSION_MIN}"
make distclean >/dev/null 2>&1
./configure --host=x86_64-apple-darwin23 --prefix="$IOS_SIMULATOR_X86_64_PREFIX" \
${LIBSODIUM_ENABLE_MINIMAL_FLAG}
make -j${PROCESSORS} install || exit 1
}
build_watchos() {
export BASEDIR="${XCODEDIR}/Platforms/WatchOS.platform/Developer"
export PATH="${BASEDIR}/usr/bin:$BASEDIR/usr/sbin:$PATH"
export SDK="${BASEDIR}/SDKs/WatchOS.sdk"
# 32-bit watchOS
export CFLAGS="-O3 -mthumb -arch armv7k -isysroot ${SDK} -mwatchos-version-min=${WATCHOS_VERSION_MIN}"
export LDFLAGS="-mthumb -arch armv7k -isysroot ${SDK} -mwatchos-version-min=${WATCHOS_VERSION_MIN}"
make distclean >/dev/null 2>&1
./configure --host=arm-apple-darwin23 --prefix="$WATCHOS32_PREFIX" \
${LIBSODIUM_ENABLE_MINIMAL_FLAG} || exit 1
make -j${PROCESSORS} install || exit 1
## 64-bit arm64_32 watchOS
export CFLAGS="-O3 -mthumb -arch arm64_32 -isysroot ${SDK} -mwatchos-version-min=${WATCHOS_VERSION_MIN}"
export LDFLAGS="-mthumb -arch arm64_32 -isysroot ${SDK} -mwatchos-version-min=${WATCHOS_VERSION_MIN}"
make distclean >/dev/null 2>&1
./configure --host=aarch64-apple-darwin23 --prefix="$WATCHOS64_32_PREFIX" \
${LIBSODIUM_ENABLE_MINIMAL_FLAG} || exit 1
make -j${PROCESSORS} install || exit 1
## 64-bit arm64 watchOS
export CFLAGS="-O3 -mthumb -arch arm64 -isysroot ${SDK} -mwatchos-version-min=${WATCHOS_VERSION_MIN}"
export LDFLAGS="-mthumb -arch arm64 -isysroot ${SDK} -mwatchos-version-min=${WATCHOS_VERSION_MIN}"
make distclean >/dev/null 2>&1
./configure --host=aarch64-apple-darwin23 --prefix="$WATCHOS64_PREFIX" \
${LIBSODIUM_ENABLE_MINIMAL_FLAG} || exit 1
make -j${PROCESSORS} install || exit 1
}
build_watchos_simulator() {
export BASEDIR="${XCODEDIR}/Platforms/WatchSimulator.platform/Developer"
export PATH="${BASEDIR}/usr/bin:$BASEDIR/usr/sbin:$PATH"
export SDK="${BASEDIR}/SDKs/WatchSimulator.sdk"
## arm64 simulator
export CFLAGS="-O3 -arch arm64 -isysroot ${SDK} -mwatchos-simulator-version-min=${WATCHOS_SIMULATOR_VERSION_MIN}"
export LDFLAGS="-arch arm64 -isysroot ${SDK} -mwatchos-simulator-version-min=${WATCHOS_SIMULATOR_VERSION_MIN}"
make distclean >/dev/null 2>&1
./configure --host=aarch64-apple-darwin23 --prefix="$WATCHOS_SIMULATOR_ARM64_PREFIX" \
${LIBSODIUM_ENABLE_MINIMAL_FLAG} || exit 1
make -j${PROCESSORS} install || exit 1
## i386 simulator
export CFLAGS="-O3 -arch i386 -isysroot ${SDK} -mwatchos-simulator-version-min=${WATCHOS_SIMULATOR_VERSION_MIN}"
export LDFLAGS="-arch i386 -isysroot ${SDK} -mwatchos-simulator-version-min=${WATCHOS_SIMULATOR_VERSION_MIN}"
make distclean >/dev/null 2>&1
./configure --host=i686-apple-darwin23 --prefix="$WATCHOS_SIMULATOR_I386_PREFIX" \
${LIBSODIUM_ENABLE_MINIMAL_FLAG} || exit 1
make -j${PROCESSORS} install || exit 1
## x86_64 simulator
export CFLAGS="-O3 -arch x86_64 -isysroot ${SDK} -mwatchos-simulator-version-min=${WATCHOS_SIMULATOR_VERSION_MIN}"
export LDFLAGS="-arch x86_64 -isysroot ${SDK} -mwatchos-simulator-version-min=${WATCHOS_SIMULATOR_VERSION_MIN}"
make distclean >/dev/null 2>&1
./configure --host=x86_64-apple-darwin23 --prefix="$WATCHOS_SIMULATOR_X86_64_PREFIX" \
${LIBSODIUM_ENABLE_MINIMAL_FLAG} || exit 1
make -j${PROCESSORS} install || exit 1
}
build_tvos() {
export BASEDIR="${XCODEDIR}/Platforms/AppleTVOS.platform/Developer"
export PATH="${BASEDIR}/usr/bin:$BASEDIR/usr/sbin:$PATH"
export SDK="${BASEDIR}/SDKs/AppleTVOS.sdk"
## 64-bit tvOS
export CFLAGS="-O3 -arch arm64 -isysroot ${SDK} -mtvos-version-min=${TVOS_VERSION_MIN}"
export LDFLAGS="-arch arm64 -isysroot ${SDK} -mtvos-version-min=${TVOS_VERSION_MIN}"
make distclean >/dev/null 2>&1
./configure --host=aarch64-apple-darwin23 --prefix="$TVOS_PREFIX" \
${LIBSODIUM_ENABLE_MINIMAL_FLAG} || exit 1
make -j${PROCESSORS} install || exit 1
}
build_tvos_simulator() {
export BASEDIR="${XCODEDIR}/Platforms/AppleTVSimulator.platform/Developer"
export PATH="${BASEDIR}/usr/bin:$BASEDIR/usr/sbin:$PATH"
export SDK="${BASEDIR}/SDKs/AppleTVSimulator.sdk"
## arm64 simulator
export CFLAGS="-O3 -arch arm64 -isysroot ${SDK} -mtvos-simulator-version-min=${TVOS_SIMULATOR_VERSION_MIN}"
export LDFLAGS="-arch arm64 -isysroot ${SDK} -mtvos-simulator-version-min=${TVOS_SIMULATOR_VERSION_MIN}"
make distclean >/dev/null 2>&1
./configure --host=aarch64-apple-darwin23 --prefix="$TVOS_SIMULATOR_ARM64_PREFIX" \
${LIBSODIUM_ENABLE_MINIMAL_FLAG} || exit 1
make -j${PROCESSORS} install || exit 1
## x86_64 simulator
export CFLAGS="-O3 -arch x86_64 -isysroot ${SDK} -mtvos-simulator-version-min=${TVOS_SIMULATOR_VERSION_MIN}"
export LDFLAGS="-arch x86_64 -isysroot ${SDK} -mtvos-simulator-version-min=${TVOS_SIMULATOR_VERSION_MIN}"
make distclean >/dev/null 2>&1
./configure --host=x86_64-apple-darwin23 --prefix="$TVOS_SIMULATOR_X86_64_PREFIX" \
${LIBSODIUM_ENABLE_MINIMAL_FLAG}
make -j${PROCESSORS} install || exit 1
}
build_visionos() {
export BASEDIR="${XCODEDIR}/Platforms/XROS.platform/Developer"
export PATH="${BASEDIR}/usr/bin:$BASEDIR/usr/sbin:$PATH"
export SDK="${BASEDIR}/SDKs/XROS.sdk"
export CFLAGS="-O3 -arch arm64 -isysroot ${SDK}"
export LDFLAGS="-arch arm64 -isysroot ${SDK}"
make distclean >/dev/null 2>&1
./configure --host=aarch64-apple-darwin23 --prefix="$VISIONOS_PREFIX" \
${LIBSODIUM_ENABLE_MINIMAL_FLAG} || exit 1
make -j${PROCESSORS} install || exit 1
}
build_visionos_simulator() {
export BASEDIR="${XCODEDIR}/Platforms/XRSimulator.platform/Developer"
export PATH="${BASEDIR}/usr/bin:$BASEDIR/usr/sbin:$PATH"
export SDK="${BASEDIR}/SDKs/XRSimulator.sdk"
export CFLAGS="-O3 -arch arm64 -isysroot ${SDK}"
export LDFLAGS="-arch arm64 -isysroot ${SDK}"
make distclean >/dev/null 2>&1
./configure --host=aarch64-apple-darwin23 --prefix="$VISIONOS_SIMULATOR_PREFIX" \
${LIBSODIUM_ENABLE_MINIMAL_FLAG} || exit 1
make -j${PROCESSORS} install || exit 1
}
build_catalyst() {
export BASEDIR="${XCODEDIR}/Platforms/MacOSX.platform/Developer"
export PATH="${BASEDIR}/usr/bin:$BASEDIR/usr/sbin:$PATH"
export SDK="${BASEDIR}/SDKs/MacOSX.sdk"
## arm64 catalyst
export CFLAGS="-O3 -arch arm64 -target arm64-apple-ios13.1-macabi -isysroot ${SDK}"
export LDFLAGS="-arch arm64 -target arm64-apple-ios13.1-macabi -isysroot ${SDK}"
make distclean >/dev/null 2>&1
./configure --host=aarch64-apple-ios --prefix="$CATALYST_ARM64_PREFIX" \
${LIBSODIUM_ENABLE_MINIMAL_FLAG} || exit 1
make -j${PROCESSORS} install || exit 1
## x86_64 catalyst
export CFLAGS="-O3 -arch x86_64 -target x86_64-apple-ios13.1-macabi -isysroot ${SDK}"
export LDFLAGS="-arch x86_64 -target x86_64-apple-ios13.1-macabi -isysroot ${SDK}"
make distclean >/dev/null 2>&1
./configure --host=x86_64-apple-ios --prefix="$CATALYST_X86_64_PREFIX" \
${LIBSODIUM_ENABLE_MINIMAL_FLAG} || exit 1
make -j${PROCESSORS} install || exit 1
}
mkdir -p "${PREFIX}/tmp"
echo "Building for macOS..."
build_macos >"$LOG_FILE" 2>&1 || exit 1
echo "Building for iOS..."
build_ios >"$LOG_FILE" 2>&1 || exit 1
echo "Building for watchOS..."
build_watchos >"$LOG_FILE" 2>&1 || exit 1
echo "Building for tvOS..."
build_tvos >"$LOG_FILE" 2>&1 || exit 1
echo "Building for Catalyst..."
build_catalyst >"$LOG_FILE" 2>&1 || exit 1
if [ "$VISIONOS_SUPPORTED" = true ]; then
echo "Building for visionOS..."
build_visionos >"$LOG_FILE" 2>&1 || exit 1
fi
if [ -z "$LIBSODIUM_SKIP_SIMULATORS" ]; then
echo "Building for the iOS simulator..."
build_ios_simulator >"$LOG_FILE" 2>&1 || exit 1
echo "Building for the watchOS simulator..."
build_watchos_simulator >"$LOG_FILE" 2>&1 || exit 1
echo "Building for the tvOS simulator..."
build_tvos_simulator >"$LOG_FILE" 2>&1 || exit 1
if [ "$VISIONOS_SUPPORTED" = true ]; then
echo "Building for the visionOS simulator..."
build_visionos_simulator >"$LOG_FILE" 2>&1 || exit 1
fi
else
echo "[Skipping the simulators]"
fi
echo "Adding the Clibsodium module map for Swift..."
find "$PREFIX" -name "include" -type d -print | while read -r f; do
swift_module_map >"${f}/module.modulemap"
done
echo "Bundling macOS targets..."
mkdir -p "${PREFIX}/macos/lib"
cp -a "${MACOS_X86_64_PREFIX}/include" "${PREFIX}/macos/"
for ext in a dylib; do
lipo -create \
"${MACOS_ARM64_PREFIX}/lib/libsodium.${ext}" \
"${MACOS_X86_64_PREFIX}/lib/libsodium.${ext}" \
-output "${PREFIX}/macos/lib/libsodium.${ext}"
done
echo "Bundling iOS targets..."
mkdir -p "${PREFIX}/ios/lib"
cp -a "${IOS64_PREFIX}/include" "${PREFIX}/ios/"
for ext in a dylib; do
LIBRARY_PATHS="$IOS64_PREFIX/lib/libsodium.${ext}"
if [ "$IOS32_SUPPORTED" = true ]; then
LIBRARY_PATHS="$LIBRARY_PATHS $IOS32_PREFIX/lib/libsodium.${ext}"
LIBRARY_PATHS="$LIBRARY_PATHS $IOS32s_PREFIX/lib/libsodium.${ext}"
fi
lipo -create \
${LIBRARY_PATHS} \
-output "$PREFIX/ios/lib/libsodium.${ext}"
done
echo "Bundling watchOS targets..."
mkdir -p "${PREFIX}/watchos/lib"
cp -a "${WATCHOS64_32_PREFIX}/include" "${PREFIX}/watchos/"
for ext in a dylib; do
lipo -create \
"${WATCHOS32_PREFIX}/lib/libsodium.${ext}" \
"${WATCHOS64_32_PREFIX}/lib/libsodium.${ext}" \
"${WATCHOS64_PREFIX}/lib/libsodium.${ext}" \
-output "${PREFIX}/watchos/lib/libsodium.${ext}"
done
echo "Bundling tvOS targets..."
mkdir -p "${PREFIX}/tvos/lib"
cp -a "${TVOS_PREFIX}/include" "${PREFIX}/tvos/"
for ext in a dylib; do
lipo -create \
"$TVOS_PREFIX/lib/libsodium.${ext}" \
-output "$PREFIX/tvos/lib/libsodium.${ext}"
done
if [ "$VISIONOS_SUPPORTED" = true ]; then
echo "Bundling visionOS targets..."
mkdir -p "${PREFIX}/visionos/lib"
cp -a "${VISIONOS_PREFIX}/include" "${PREFIX}/visionos/"
for ext in a dylib; do
lipo -create \
"$VISIONOS_PREFIX/lib/libsodium.${ext}" \
-output "$PREFIX/visionos/lib/libsodium.${ext}"
done
fi
echo "Bundling Catalyst targets..."
mkdir -p "${PREFIX}/catalyst/lib"
cp -a "${CATALYST_X86_64_PREFIX}/include" "${PREFIX}/catalyst/"
for ext in a dylib; do
if [ ! -f "${CATALYST_X86_64_PREFIX}/lib/libsodium.${ext}" ]; then
continue
fi
lipo -create \
"${CATALYST_ARM64_PREFIX}/lib/libsodium.${ext}" \
"${CATALYST_X86_64_PREFIX}/lib/libsodium.${ext}" \
-output "${PREFIX}/catalyst/lib/libsodium.${ext}"
done
if [ -z "$LIBSODIUM_SKIP_SIMULATORS" ]; then
echo "Bundling iOS simulators..."
mkdir -p "${PREFIX}/ios-simulators/lib"
cp -a "${IOS_SIMULATOR_X86_64_PREFIX}/include" "${PREFIX}/ios-simulators/"
for ext in a dylib; do
LIBRARY_PATHS="${IOS_SIMULATOR_ARM64_PREFIX}/lib/libsodium.${ext}"
LIBRARY_PATHS="$LIBRARY_PATHS ${IOS_SIMULATOR_X86_64_PREFIX}/lib/libsodium.${ext}"
if [ "$I386_SIMULATOR_SUPPORTED" = true ]; then
LIBRARY_PATHS="$LIBRARY_PATHS ${IOS_SIMULATOR_I386_PREFIX}/lib/libsodium.${ext}"
fi
lipo -create \
${LIBRARY_PATHS} \
-output "${PREFIX}/ios-simulators/lib/libsodium.${ext}" || exit 1
done
echo "Bundling watchOS simulators..."
mkdir -p "${PREFIX}/watchos-simulators/lib"
cp -a "${WATCHOS_SIMULATOR_X86_64_PREFIX}/include" "${PREFIX}/watchos-simulators/"
for ext in a dylib; do
lipo -create \
"${WATCHOS_SIMULATOR_ARM64_PREFIX}/lib/libsodium.${ext}" \
"${WATCHOS_SIMULATOR_I386_PREFIX}/lib/libsodium.${ext}" \
"${WATCHOS_SIMULATOR_X86_64_PREFIX}/lib/libsodium.${ext}" \
-output "${PREFIX}/watchos-simulators/lib/libsodium.${ext}"
done
echo "Bundling tvOS simulators..."
mkdir -p "${PREFIX}/tvos-simulators/lib"
cp -a "${TVOS_SIMULATOR_X86_64_PREFIX}/include" "${PREFIX}/tvos-simulators/"
for ext in a dylib; do
lipo -create \
"${TVOS_SIMULATOR_ARM64_PREFIX}/lib/libsodium.${ext}" \
"${TVOS_SIMULATOR_X86_64_PREFIX}/lib/libsodium.${ext}" \
-output "${PREFIX}/tvos-simulators/lib/libsodium.${ext}" || exit 1
done
if [ "$VISIONOS_SUPPORTED" = true ]; then
echo "Bundling visionOS simulators..."
mkdir -p "${PREFIX}/visionos-simulators/lib"
cp -a "${VISIONOS_SIMULATOR_PREFIX}/include" "${PREFIX}/visionos-simulators/"
for ext in a dylib; do
lipo -create \
"${VISIONOS_SIMULATOR_PREFIX}/lib/libsodium.${ext}" \
-output "${PREFIX}/visionos-simulators/lib/libsodium.${ext}" || exit 1
done
fi
fi
echo "Creating Clibsodium.xcframework..."
rm -rf "${PREFIX}/Clibsodium.xcframework"
XCFRAMEWORK_ARGS=""
for f in macos ios watchos tvos visionos catalyst; do
if [ "$VISIONOS_SUPPORTED" = false ] && [ "$f" = "visionos" ]; then
continue
fi
XCFRAMEWORK_ARGS="${XCFRAMEWORK_ARGS} -library $(readlink -f ${PREFIX}/${f}/lib/libsodium.a)"
XCFRAMEWORK_ARGS="${XCFRAMEWORK_ARGS} -headers $(readlink -f ${PREFIX}/${f}/include)"
done
if [ -z "$LIBSODIUM_SKIP_SIMULATORS" ]; then
for f in ios-simulators watchos-simulators tvos-simulators visionos-simulators; do
if [ "$VISIONOS_SUPPORTED" = false ] && [ "$f" = "visionos-simulators" ]; then
continue
fi
XCFRAMEWORK_ARGS="${XCFRAMEWORK_ARGS} -library $(readlink -f ${PREFIX}/${f}/lib/libsodium.a)"
XCFRAMEWORK_ARGS="${XCFRAMEWORK_ARGS} -headers $(readlink -f ${PREFIX}/${f}/include)"
done
fi
xcodebuild -create-xcframework \
${XCFRAMEWORK_ARGS} \
-output "${PREFIX}/Clibsodium.xcframework" >/dev/null
ls -ld -- "$PREFIX"
ls -l -- "$PREFIX"
ls -l -- "$PREFIX/Clibsodium.xcframework"
echo "Done!"
# Cleanup
rm -rf -- "$PREFIX/tmp"
make distclean >/dev/null