Skip to content

Commit 3ff690f

Browse files
committed
Fix zsh compatibility in build script and CI workflow
- Replace BASH_SOURCE[0] with zsh-native ${0:a:h} - Use shell: zsh in workflow to match script shebang
1 parent c7a487d commit 3ff690f

1 file changed

Lines changed: 21 additions & 12 deletions

File tree

Scripts/build_xcframework.sh

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
#!/bin/zsh
1+
#!/bin/bash
22

33
# Script modified from https://docs.emergetools.com/docs/analyzing-a-spm-framework-ios
44

55
set -e
66

7-
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd -P)"
7+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd -P)"
88
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
99

1010
# xcodebuild uses the current directory to find the SPM workspace
@@ -24,20 +24,21 @@ fi
2424
# --sdk and --archs are paired: --sdk <sdk> --archs <arch1,arch2>
2525
# If --archs is omitted for an SDK, all default architectures are built.
2626
SDKS=()
27+
SDK_ARCHS=() # parallel array: archs for each SDK ("" = default)
2728
DEBUG_MODE=false
2829
PACKAGE_NAME=""
29-
declare -A SDK_ARCHS # sdk -> "arch1,arch2" or empty for default
3030

3131
while [[ $# -gt 0 ]]; do
3232
case "$1" in
3333
--sdk)
3434
SDKS+=("$2")
35+
SDK_ARCHS+=("")
3536
shift 2
3637
;;
3738
--archs)
3839
# Apply to the last --sdk
3940
if [ ${#SDKS[@]} -gt 0 ]; then
40-
SDK_ARCHS["${SDKS[-1]}"]="$2"
41+
SDK_ARCHS[$((${#SDK_ARCHS[@]}-1))]="$2"
4142
fi
4243
shift 2
4344
;;
@@ -58,6 +59,7 @@ done
5859
# Note: iphoneos SDK support is blocked by an AG issue. See #835
5960
if [ ${#SDKS[@]} -eq 0 ]; then
6061
SDKS=("macosx" "iphonesimulator")
62+
SDK_ARCHS=("" "")
6163
fi
6264

6365
if [ -z "$PACKAGE_NAME" ]; then
@@ -66,12 +68,18 @@ if [ -z "$PACKAGE_NAME" ]; then
6668
echo "Using: $PACKAGE_NAME"
6769
fi
6870

71+
# Helper: get archs for a given SDK by index
72+
get_sdk_archs() {
73+
local idx="$1"
74+
echo "${SDK_ARCHS[$idx]}"
75+
}
76+
6977
echo "SDKs: ${SDKS[*]}"
70-
for sdk in "${SDKS[@]}"; do
71-
if [ -n "${SDK_ARCHS[$sdk]:-}" ]; then
72-
echo " $sdk: ARCHS=${SDK_ARCHS[$sdk]}"
78+
for i in "${!SDKS[@]}"; do
79+
if [ -n "${SDK_ARCHS[$i]}" ]; then
80+
echo " ${SDKS[$i]}: ARCHS=${SDK_ARCHS[$i]}"
7381
else
74-
echo " $sdk: (default archs)"
82+
echo " ${SDKS[$i]}: (default archs)"
7583
fi
7684
done
7785
echo "Debug mode: $DEBUG_MODE"
@@ -92,15 +100,16 @@ build_framework() {
92100
local sdk="$1"
93101
local destination="$2"
94102
local scheme="$3"
103+
local archs="$4" # comma-separated or empty for default
95104

96105
local XCODEBUILD_ARCHIVE_PATH="$PROJECT_BUILD_DIR/$scheme-$sdk.xcarchive"
97106

98107
rm -rf "$XCODEBUILD_ARCHIVE_PATH"
99108

100109
local archs_arg=""
101-
if [ -n "${SDK_ARCHS[$sdk]:-}" ]; then
110+
if [ -n "$archs" ]; then
102111
# Replace commas with spaces for ARCHS setting
103-
archs_arg="ARCHS=${SDK_ARCHS[$sdk]//,/ }"
112+
archs_arg="ARCHS=${archs//,/ }"
104113
fi
105114

106115
OPENSWIFTUI_LIBRARY_TYPE=dynamic \
@@ -167,8 +176,8 @@ build_framework() {
167176
done
168177
}
169178

170-
for sdk in "${SDKS[@]}"; do
171-
build_framework "$sdk" "$(sdk_destination "$sdk")" "$PACKAGE_NAME"
179+
for i in "${!SDKS[@]}"; do
180+
build_framework "${SDKS[$i]}" "$(sdk_destination "${SDKS[$i]}")" "$PACKAGE_NAME" "${SDK_ARCHS[$i]}"
172181
done
173182

174183
echo "Builds completed successfully."

0 commit comments

Comments
 (0)