Skip to content

Commit 1f15118

Browse files
authored
Update build_xcframework.yml
1 parent 20e49f7 commit 1f15118

File tree

1 file changed

+38
-29
lines changed

1 file changed

+38
-29
lines changed

.github/workflows/build_xcframework.yml

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ on:
1616

1717
env:
1818
OUTPUT_DIR: ${{ github.workspace }}/output
19-
LIBRARIES: '("opencore-amrnb" "opencore-amrwb")'
20-
PLATFORMS: '("macos" "iphoneos" "iphonesimulator")'
2119

2220
jobs:
2321
build:
@@ -34,12 +32,20 @@ jobs:
3432
steps:
3533
- uses: actions/checkout@v4
3634

35+
- name: Get Xcode version
36+
id: xcode-version
37+
run: echo "version=$(xcodebuild -version | grep Xcode | awk '{print $2}')" >> $GITHUB_OUTPUT
38+
39+
- name: Get macOS version
40+
id: macos-version
41+
run: echo "version=$(sw_vers -productVersion)" >> $GITHUB_OUTPUT
42+
3743
- name: Cache build results
3844
uses: actions/cache@v4
3945
id: cache
4046
with:
4147
path: ${{ env.OUTPUT_DIR }}
42-
key: ${{ runner.os }}-build-${{ matrix.config.sdk }}-${{ matrix.config.arch }}-${{ hashFiles('**/*.c', '**/*.cpp', '**/*.h', '**/*.m', '**/*.mm') }}
48+
key: ${{ runner.os }}-build-${{ matrix.config.sdk }}-${{ matrix.config.arch }}-${{ hashFiles('**/*.c', '**/*.cpp', '**/*.h', '**/*.m', '**/*.mm', '.github/actions/*.sh') }}-${{ steps.xcode-version.outputs.version }}-${{ steps.macos-version.outputs.version }}
4349

4450
- name: Set up Xcode
4551
if: steps.cache.outputs.cache-hit != 'true'
@@ -86,54 +92,57 @@ jobs:
8692
ls -R ${{ env.OUTPUT_DIR }}
8793
8894
- name: Create fat libraries using lipo
89-
shell: bash
9095
run: |
9196
mkdir -p "${OUTPUT_DIR}/fat"
92-
declare -A ARCHITECTURES=(
93-
["macos"]="arm64 x86_64"
94-
["iphoneos"]="arm64"
95-
["iphonesimulator"]="x86_64 arm64"
96-
)
97-
eval "LIBRARIES=(${LIBRARIES})"
98-
eval "PLATFORMS=(${PLATFORMS})"
99-
100-
for lib in "${LIBRARIES[@]}"; do
97+
98+
MACOS_ARCHS="arm64 x86_64"
99+
IPHONEOS_ARCHS="arm64"
100+
IPHONESIMULATOR_ARCHS="x86_64 arm64"
101+
102+
LIBRARIES="libopencore-amrnb libopencore-amrwb"
103+
104+
for lib in $LIBRARIES; do
101105
# For macOS
102-
lipo -create $(for arch in ${ARCHITECTURES["macos"]}; do echo "${OUTPUT_DIR}/build-macosx-${arch}/macosx-${arch}-MacOSX/lib/${lib}.a"; done) \
106+
lipo -create $(for arch in $MACOS_ARCHS; do echo "${OUTPUT_DIR}/build-macosx-${arch}/macosx-${arch}-MacOSX/lib/${lib}.a"; done) \
103107
-output "${OUTPUT_DIR}/fat/${lib}-macos.a"
104-
108+
105109
# For iOS device
106110
cp "${OUTPUT_DIR}/build-iphoneos-arm64/iphoneos-arm64-iPhoneOS/lib/${lib}.a" "${OUTPUT_DIR}/fat/${lib}-iphoneos.a"
107-
111+
108112
# For iOS simulator
109-
lipo -create $(for arch in ${ARCHITECTURES["iphonesimulator"]}; do echo "${OUTPUT_DIR}/build-iphonesimulator-${arch}/iphonesimulator-${arch}-iPhoneSimulator/lib/${lib}.a"; done) \
113+
lipo -create $(for arch in $IPHONESIMULATOR_ARCHS; do echo "${OUTPUT_DIR}/build-iphonesimulator-${arch}/iphonesimulator-${arch}-iPhoneSimulator/lib/${lib}.a"; done) \
110114
-output "${OUTPUT_DIR}/fat/${lib}-iphonesimulator.a"
111115
done
112116
113117
- name: Create XCFrameworks
114-
shell: bash
115118
run: |
116119
mkdir -p "${OUTPUT_DIR}/Headers/"
117-
eval "LIBRARIES=(${LIBRARIES})"
118-
eval "PLATFORMS=(${PLATFORMS})"
119-
declare -A HEADERS=(
120-
["opencore-amrnb"]="amrnb/interf_dec.h amrnb/interf_enc.h"
121-
["opencore-amrwb"]="amrwb/dec_if.h amrwb/if_rom.h"
122-
)
123-
for lib in "${!HEADERS[@]}"; do
120+
121+
LIBRARIES="opencore-amrnb opencore-amrwb"
122+
PLATFORMS="macos iphoneos iphonesimulator"
123+
124+
for lib in $LIBRARIES; do
124125
rm -rf ${OUTPUT_DIR}/Headers/*
125126
rm -rf ${OUTPUT_DIR}/${lib}.xcframework
127+
126128
# Copy headers
127-
for header in ${HEADERS[$lib]}; do
128-
cp -a $header ${OUTPUT_DIR}/Headers/
129-
done
129+
case $lib in
130+
opencore-amrnb)
131+
cp -a amrnb/interf_dec.h amrnb/interf_enc.h ${OUTPUT_DIR}/Headers/
132+
;;
133+
opencore-amrwb)
134+
cp -a amrwb/dec_if.h amrwb/if_rom.h ${OUTPUT_DIR}/Headers/
135+
;;
136+
esac
137+
130138
# Prepare xcodebuild command
131139
cmd="xcodebuild -create-xcframework"
132-
for platform in "${PLATFORMS[@]}"; do
140+
for platform in $PLATFORMS; do
133141
cmd+=" -library ${OUTPUT_DIR}/fat/lib${lib}-${platform}.a"
134142
cmd+=" -headers ${OUTPUT_DIR}/Headers"
135143
done
136144
cmd+=" -output ${OUTPUT_DIR}/${lib}.xcframework"
145+
137146
# Execute xcodebuild command
138147
eval $cmd
139148
done

0 commit comments

Comments
 (0)