Skip to content

Commit da0fd57

Browse files
authored
Add iOS and Android packaging to CI and improve iOS build script (#198)
* Add iOS and Android packaging to CI and improve iOS build script - Add Android build, package, and release jobs to GitHub Actions - Add iOS packaging and release steps to MacOS job - Refactor iOS build script to build all architectures and create xcframework - Simplify build type and CMake preset selection in workflows * Update workflow to verify Android outputs and adjust tag checks * Update CI badge URL and create universal simulator lib for iOS
1 parent 442b467 commit da0fd57

File tree

3 files changed

+135
-35
lines changed

3 files changed

+135
-35
lines changed

.github/workflows/main.yml

Lines changed: 82 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ jobs:
138138
files: "${{ github.workspace }}/artifacts/libsimple-windows-${{ matrix.arch }}.zip"
139139
env:
140140
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
141-
BUILD_TYPE: ${{ github.ref_type == 'tag' && 'Release' || 'Debug' }}
142141

143142
Linux:
144143
runs-on: ${{ matrix.os }}
@@ -147,14 +146,9 @@ jobs:
147146
matrix:
148147
os: [ubuntu-22.04, ubuntu-24.04-arm, ubuntu-latest]
149148
timeout-minutes: 60
149+
env:
150+
BUILD_TYPE: ${{ startsWith(github.ref, 'refs/tags/') && 'Release' || 'Debug' }}
150151
steps:
151-
- name: "Release Build Type"
152-
if: startsWith(github.ref, 'refs/tags/')
153-
run: echo "BUILD_TYPE=Release" >> $GITHUB_ENV
154-
- name: "Debug Build Type"
155-
if: startsWith(github.ref, 'refs/tags/') != true
156-
run: echo "BUILD_TYPE=Debug" >> $GITHUB_ENV
157-
158152
- uses: actions/checkout@v6
159153
with:
160154
fetch-depth: 0
@@ -187,15 +181,8 @@ jobs:
187181
uses: lukka/run-cmake@v10
188182
continue-on-error: false
189183
with:
190-
configurePreset: 'ninja-vcpkg-coverage'
191-
buildPreset: 'ninja-vcpkg-coverage'
192-
193-
- name: 'Run CMake without coverage'
194-
if: startsWith(github.ref, 'refs/tags/')
195-
uses: lukka/run-cmake@v10
196-
with:
197-
configurePreset: 'ninja-vcpkg-release'
198-
buildPreset: 'ninja-vcpkg-release'
184+
configurePreset: ${{ startsWith(github.ref, 'refs/tags/') && 'ninja-vcpkg-release' || 'ninja-vcpkg-coverage' }}
185+
buildPreset: ${{ startsWith(github.ref, 'refs/tags/') && 'ninja-vcpkg-release' || 'ninja-vcpkg-coverage' }}
199186

200187
- name: 'Run CTest'
201188
if: ${{ startsWith(github.ref, 'refs/tags/') != true && matrix.os == 'ubuntu-latest' }}
@@ -292,14 +279,9 @@ jobs:
292279
MacOS:
293280
runs-on: macos-latest
294281
needs: Linux
282+
env:
283+
BUILD_TYPE: ${{ startsWith(github.ref, 'refs/tags/') && 'Release' || 'Debug' }}
295284
steps:
296-
- name: "Release Build Type"
297-
if: startsWith(github.ref, 'refs/tags/')
298-
run: echo "BUILD_TYPE=Release" >> $GITHUB_ENV
299-
- name: "Debug Build Type"
300-
if: startsWith(github.ref, 'refs/tags/') != true
301-
run: echo "BUILD_TYPE=Debug" >> $GITHUB_ENV
302-
303285
- uses: actions/checkout@v6
304286
with:
305287
submodules: true
@@ -380,3 +362,79 @@ jobs:
380362
- name: build-iOS
381363
if: success()
382364
run: ./build-ios.sh
365+
366+
- name: Package iOS
367+
if: startsWith(github.ref, 'refs/tags/')
368+
run: |
369+
mkdir libsimple-ios-xcframework
370+
cp -r output/libsimple.xcframework output/dict libsimple-ios-xcframework/
371+
zip -r libsimple-ios-xcframework.zip libsimple-ios-xcframework
372+
working-directory: "${{ github.workspace }}"
373+
374+
- name: Release iOS
375+
if: startsWith(github.ref, 'refs/tags/')
376+
uses: softprops/action-gh-release@v2
377+
with:
378+
draft: true
379+
files: "${{ github.workspace }}/libsimple-ios-xcframework.zip"
380+
env:
381+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
382+
383+
Android:
384+
runs-on: ubuntu-latest
385+
needs: Linux
386+
strategy:
387+
fail-fast: true
388+
matrix:
389+
abi: [arm64-v8a, x86_64]
390+
steps:
391+
- uses: actions/checkout@v6
392+
with:
393+
submodules: true
394+
395+
- name: Resolve Android NDK
396+
run: |
397+
if [ -z "${ANDROID_NDK_LATEST_HOME:-}" ]; then
398+
echo "ANDROID_NDK_LATEST_HOME is not available on this runner." >&2
399+
exit 1
400+
fi
401+
echo "ANDROID_NDK_HOME=${ANDROID_NDK_LATEST_HOME}" >> "$GITHUB_ENV"
402+
403+
- name: Configure Android
404+
run: |
405+
cmake -S "${{ github.workspace }}" -B "${{ github.workspace }}/build-android-${{ matrix.abi }}" \
406+
-DCMAKE_TOOLCHAIN_FILE="${ANDROID_NDK_HOME}/build/cmake/android.toolchain.cmake" \
407+
-DANDROID_ABI="${{ matrix.abi }}" \
408+
-DANDROID_PLATFORM=android-21 \
409+
-DCMAKE_BUILD_TYPE=Release \
410+
-DCMAKE_INSTALL_PREFIX="${{ github.workspace }}/output-android-${{ matrix.abi }}" \
411+
-DBUILD_TEST_EXAMPLE=OFF \
412+
-DBUILD_SHELL=OFF
413+
414+
- name: Build Android
415+
run: cmake --build "${{ github.workspace }}/build-android-${{ matrix.abi }}" --config Release --parallel
416+
417+
- name: Install Android
418+
run: cmake --install "${{ github.workspace }}/build-android-${{ matrix.abi }}" --config Release
419+
420+
- name: Verify Android outputs
421+
run: |
422+
test -f "output-android-${{ matrix.abi }}/bin/libsimple.so"
423+
test -f "output-android-${{ matrix.abi }}/bin/dict/jieba.dict.utf8"
424+
425+
- name: Package Android
426+
if: startsWith(github.ref, 'refs/tags/')
427+
run: |
428+
mkdir "libsimple-android-${{ matrix.abi }}"
429+
cp -r "output-android-${{ matrix.abi }}/bin/libsimple.so" "output-android-${{ matrix.abi }}/bin/dict" "libsimple-android-${{ matrix.abi }}/"
430+
zip -r "libsimple-android-${{ matrix.abi }}.zip" "libsimple-android-${{ matrix.abi }}"
431+
working-directory: "${{ github.workspace }}"
432+
433+
- name: Release Android
434+
if: startsWith(github.ref, 'refs/tags/')
435+
uses: softprops/action-gh-release@v2
436+
with:
437+
draft: true
438+
files: "${{ github.workspace }}/libsimple-android-${{ matrix.abi }}.zip"
439+
env:
440+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[![Downloads](https://img.shields.io/github/downloads/wangfenjin/simple/total)](https://img.shields.io/github/downloads/wangfenjin/simple/total)
2-
[![build](https://github.com/wangfenjin/simple/workflows/CI/badge.svg)](https://github.com/wangfenjin/simple/actions?query=workflow%3ACI)
2+
[![build](https://github.com/wangfenjin/simple/actions/workflows/main.yml/badge.svg?branch=master)](https://github.com/wangfenjin/simple/actions/workflows/main.yml)
33
[![codecov](https://codecov.io/gh/wangfenjin/simple/branch/master/graph/badge.svg?token=8SHLFZ3RB4)](https://codecov.io/gh/wangfenjin/simple)
44
[![CodeFactor](https://www.codefactor.io/repository/github/wangfenjin/simple/badge)](https://www.codefactor.io/repository/github/wangfenjin/simple)
55
[![License: MIT](https://img.shields.io/badge/Dual_License-MIT_or_GPL_v3_later-blue.svg)](https://github.com/wangfenjin/simple/blob/master/LICENSE)

build-ios.sh

Lines changed: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,57 @@
11
#!/bin/sh
22

3-
current_dir=$(pwd)/$(dirname "$0")
4-
build_dir="${current_dir}/build-ios"
5-
lib_prefix="${current_dir}/output"
3+
set -eu
64

7-
cmake "$current_dir" -G Xcode -DCMAKE_TOOLCHAIN_FILE=contrib/ios.toolchain.cmake \
8-
-DPLATFORM=OS64COMBINED -DENABLE_BITCODE=1 \
9-
-DCMAKE_INSTALL_PREFIX="" -B "$build_dir" \
10-
-DDEPLOYMENT_TARGET=8.0
5+
script_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
6+
toolchain_file="${script_dir}/contrib/ios.toolchain.cmake"
7+
ios_output_root="${script_dir}/output-ios"
8+
final_output_root="${script_dir}/output"
9+
headers_dir="${ios_output_root}/headers"
1110

12-
cd "$build_dir" || exit
11+
build_variant() {
12+
platform="$1"
13+
build_dir="${script_dir}/build-ios-${platform}"
14+
install_dir="${ios_output_root}/${platform}"
1315

14-
cmake --build "$build_dir" --config Release
15-
cmake --install "$build_dir" --config Release --prefix "${lib_prefix}"
16+
cmake -S "${script_dir}" -B "${build_dir}" -G Xcode \
17+
-DCMAKE_TOOLCHAIN_FILE="${toolchain_file}" \
18+
-DPLATFORM="${platform}" \
19+
-DENABLE_BITCODE=1 \
20+
-DDEPLOYMENT_TARGET=8.0 \
21+
-DCMAKE_INSTALL_PREFIX=""
22+
23+
cmake --build "${build_dir}" --config Release
24+
cmake --install "${build_dir}" --config Release --prefix "${install_dir}"
25+
}
26+
27+
rm -rf "${ios_output_root}" "${final_output_root}/libsimple.xcframework" "${final_output_root}/dict"
28+
mkdir -p "${headers_dir}" "${final_output_root}"
29+
cp "${script_dir}"/src/*.h "${headers_dir}/"
30+
31+
build_variant OS64
32+
build_variant SIMULATOR64
33+
build_variant SIMULATORARM64
34+
35+
sim64_lib="${ios_output_root}/SIMULATOR64/bin/libsimple.a"
36+
simarm64_lib="${ios_output_root}/SIMULATORARM64/bin/libsimple.a"
37+
sim_universal_dir="${ios_output_root}/SIMULATOR_UNIVERSAL/bin"
38+
sim_universal_lib="${sim_universal_dir}/libsimple.a"
39+
40+
mkdir -p "${sim_universal_dir}"
41+
sim64_archs="$(lipo -archs "${sim64_lib}")"
42+
simarm64_archs="$(lipo -archs "${simarm64_lib}")"
43+
44+
if printf '%s' "${sim64_archs}" | grep -q 'x86_64' && printf '%s' "${sim64_archs}" | grep -q 'arm64'; then
45+
cp "${sim64_lib}" "${sim_universal_lib}"
46+
elif printf '%s' "${simarm64_archs}" | grep -q 'x86_64' && printf '%s' "${simarm64_archs}" | grep -q 'arm64'; then
47+
cp "${simarm64_lib}" "${sim_universal_lib}"
48+
else
49+
lipo -create "${sim64_lib}" "${simarm64_lib}" -output "${sim_universal_lib}"
50+
fi
51+
52+
xcodebuild -create-xcframework \
53+
-library "${ios_output_root}/OS64/bin/libsimple.a" -headers "${headers_dir}" \
54+
-library "${sim_universal_lib}" -headers "${headers_dir}" \
55+
-output "${final_output_root}/libsimple.xcframework"
56+
57+
cp -R "${ios_output_root}/OS64/bin/dict" "${final_output_root}/dict"

0 commit comments

Comments
 (0)