Skip to content

Commit 1fe12c5

Browse files
authored
Support the platform iOS for Flutter (#1079)
1 parent a250751 commit 1fe12c5

File tree

67 files changed

+2040
-46
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+2040
-46
lines changed

.github/workflows/release-dart-package.yaml

+98-17
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,6 @@ jobs:
2424
steps:
2525
- uses: actions/checkout@v4
2626

27-
- name: Setup Flutter SDK
28-
uses: flutter-actions/setup-flutter@v3
29-
with:
30-
channel: stable
31-
version: latest
32-
33-
- uses: dart-lang/setup-dart@v1
34-
3527
- name: Fix version
3628
shell: bash
3729
run: |
@@ -104,6 +96,14 @@ jobs:
10496
10597
ls -lh /tmp/to_be_published/linux
10698
99+
- name: Setup Flutter SDK
100+
uses: flutter-actions/setup-flutter@v3
101+
with:
102+
channel: stable
103+
version: latest
104+
105+
- uses: dart-lang/setup-dart@v1
106+
107107
- name: Release
108108
shell: bash
109109
run: |
@@ -127,14 +127,6 @@ jobs:
127127
with:
128128
key: ${{ matrix.os }}-flutter-release-package
129129

130-
- name: Setup Flutter SDK
131-
uses: flutter-actions/setup-flutter@v3
132-
with:
133-
channel: stable
134-
version: latest
135-
136-
- uses: dart-lang/setup-dart@v1
137-
138130
- name: Fix version
139131
shell: bash
140132
run: |
@@ -205,6 +197,14 @@ jobs:
205197
206198
ls -lh /tmp/to_be_published/macos
207199
200+
- name: Setup Flutter SDK
201+
uses: flutter-actions/setup-flutter@v3
202+
with:
203+
channel: stable
204+
version: latest
205+
206+
- uses: dart-lang/setup-dart@v1
207+
208208
- name: Release
209209
shell: bash
210210
run: |
@@ -429,8 +429,89 @@ jobs:
429429
flutter pub publish --dry-run
430430
flutter pub publish --force
431431
432+
sherpa_onnx_ios:
433+
# if: false
434+
permissions:
435+
id-token: write # Required for authentication using OIDC
436+
name: sherpa_onnx_ios
437+
runs-on: macos-latest
438+
439+
steps:
440+
- uses: actions/checkout@v4
441+
442+
- name: ccache
443+
uses: hendrikmuhs/ccache-action@v1.2
444+
with:
445+
key: ${{ matrix.os }}-flutter-release-package-ios
446+
447+
- name: Fix version
448+
shell: bash
449+
run: |
450+
SHERPA_ONNX_VERSION=$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2)
451+
452+
src_dir=$PWD/flutter/sherpa_onnx_ios
453+
pushd $src_dir
454+
v="version: $SHERPA_ONNX_VERSION"
455+
echo "v: $v"
456+
sed -i.bak s"/^version: .*/$v/" ./pubspec.yaml
457+
rm *.bak
458+
git status
459+
git diff
460+
461+
- name: Copy extra files
462+
shell: bash
463+
run: |
464+
dst=flutter/sherpa_onnx_ios
465+
466+
mkdir $dst/example
467+
468+
cp -v flutter/sherpa_onnx/example/* $dst/example
469+
cp -v LICENSE $dst/
470+
cp -v CHANGELOG.md $dst/
471+
472+
git status
473+
474+
- name: Build ios
475+
shell: bash
476+
run: |
477+
export CMAKE_CXX_COMPILER_LAUNCHER=ccache
478+
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
479+
cmake --version
480+
./build-ios-shared.sh
481+
482+
- name: Copy pre-built libs
483+
shell: bash
484+
run: |
485+
echo "----ios-arm64----"
486+
cp -v build-ios-shared/ios-arm64/libsherpa-onnx-c-api.dylib flutter/sherpa_onnx_ios/ios/
487+
cp -v build-ios-shared/ios-onnxruntime/onnxruntime.xcframework/ios-arm64/onnxruntime.a flutter/sherpa_onnx_ios/ios/libonnxruntime.a
488+
489+
ls -lh flutter/sherpa_onnx_ios/ios/libonnxruntime.a
490+
491+
mv -v flutter/sherpa_onnx_ios /tmp/to_be_published
492+
493+
ls -lh /tmp/to_be_published
494+
495+
- name: Setup Flutter SDK
496+
uses: flutter-actions/setup-flutter@v3
497+
with:
498+
channel: stable
499+
version: latest
500+
501+
- uses: dart-lang/setup-dart@v1
502+
503+
- name: Release
504+
shell: bash
505+
run: |
506+
cd /tmp/to_be_published
507+
du -h -d1 .
508+
509+
flutter pub get
510+
flutter pub publish --dry-run
511+
flutter pub publish --force
512+
432513
sherpa_onnx:
433-
# needs: [sherpa_onnx_linux, sherpa_onnx_macos, sherpa_onnx_windows, sherpa_onnx_android]
514+
needs: [sherpa_onnx_linux, sherpa_onnx_macos, sherpa_onnx_windows, sherpa_onnx_android, sherpa_onnx_ios]
434515
# if: false
435516
permissions:
436517
id-token: write # Required for authentication using OIDC

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,4 @@ sherpa-onnx-vits-*
109109
sherpa-onnx-telespeech-ctc-*
110110
*.fst
111111
.ccache
112+
lib*.a

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.10.11
2+
3+
* Support the iOS platform for iOS.
4+
15
## 1.10.10
26

37
* Build sherpa-onnx into a single shared library.

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ project(sherpa-onnx)
1111
# ./nodejs-addon-examples
1212
# ./dart-api-examples/
1313
# ./sherpa-onnx/flutter/CHANGELOG.md
14-
set(SHERPA_ONNX_VERSION "1.10.10")
14+
set(SHERPA_ONNX_VERSION "1.10.11")
1515

1616
# Disable warning about
1717
#

build-ios-shared.sh

+144
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Note: This script is to build sherpa-onnx for flutter/dart, which requires
4+
# us to use shared libraries for sherpa-onnx.
5+
#
6+
# Note: We still use static libraries for onnxruntime.
7+
8+
set -e
9+
10+
dir=build-ios-shared
11+
mkdir -p $dir
12+
cd $dir
13+
onnxruntime_version=1.17.1
14+
onnxruntime_dir=ios-onnxruntime/$onnxruntime_version
15+
16+
SHERPA_ONNX_GITHUB=github.com
17+
18+
if [ "$SHERPA_ONNX_GITHUB_MIRROW" == true ]; then
19+
SHERPA_ONNX_GITHUB=hub.nuaa.cf
20+
fi
21+
22+
if [ ! -f $onnxruntime_dir/onnxruntime.xcframework/ios-arm64/onnxruntime.a ]; then
23+
mkdir -p $onnxruntime_dir
24+
pushd $onnxruntime_dir
25+
wget -c https://${SHERPA_ONNX_GITHUB}/csukuangfj/onnxruntime-libs/releases/download/v${onnxruntime_version}/onnxruntime.xcframework-${onnxruntime_version}.tar.bz2
26+
tar xvf onnxruntime.xcframework-${onnxruntime_version}.tar.bz2
27+
rm onnxruntime.xcframework-${onnxruntime_version}.tar.bz2
28+
cd ..
29+
ln -sf $onnxruntime_version/onnxruntime.xcframework .
30+
popd
31+
fi
32+
33+
# First, for simulator
34+
echo "Building for simulator (x86_64)"
35+
36+
export SHERPA_ONNXRUNTIME_LIB_DIR=$PWD/ios-onnxruntime/onnxruntime.xcframework/ios-arm64_x86_64-simulator
37+
export SHERPA_ONNXRUNTIME_INCLUDE_DIR=$PWD/ios-onnxruntime/onnxruntime.xcframework/Headers
38+
39+
echo "SHERPA_ONNXRUNTIME_LIB_DIR: $SHERPA_ONNXRUNTIME_LIB_DIR"
40+
echo "SHERPA_ONNXRUNTIME_INCLUDE_DIR $SHERPA_ONNXRUNTIME_INCLUDE_DIR"
41+
42+
# Note: We use -DENABLE_ARC=1 here to fix the linking error:
43+
#
44+
# The symbol _NSLog is not defined
45+
#
46+
if [[ ! -f build/simulator_x86_64/install/lib/libsherpa-onnx-c-api.dylib ]]; then
47+
cmake \
48+
-DSHERPA_ONNX_ENABLE_BINARY=OFF \
49+
-DBUILD_PIPER_PHONMIZE_EXE=OFF \
50+
-DBUILD_PIPER_PHONMIZE_TESTS=OFF \
51+
-DBUILD_ESPEAK_NG_EXE=OFF \
52+
-DBUILD_ESPEAK_NG_TESTS=OFF \
53+
-S .. \
54+
-DCMAKE_TOOLCHAIN_FILE=./toolchains/ios.toolchain.cmake \
55+
-DPLATFORM=SIMULATOR64 \
56+
-DENABLE_BITCODE=0 \
57+
-DENABLE_ARC=1 \
58+
-DENABLE_VISIBILITY=1 \
59+
-DCMAKE_BUILD_TYPE=Release \
60+
-DCMAKE_INSTALL_PREFIX=./build/simulator_x86_64/install \
61+
-DBUILD_SHARED_LIBS=ON \
62+
-DSHERPA_ONNX_ENABLE_PYTHON=OFF \
63+
-DSHERPA_ONNX_ENABLE_TESTS=OFF \
64+
-DSHERPA_ONNX_ENABLE_CHECK=OFF \
65+
-DSHERPA_ONNX_ENABLE_PORTAUDIO=OFF \
66+
-DSHERPA_ONNX_ENABLE_JNI=OFF \
67+
-DSHERPA_ONNX_ENABLE_C_API=ON \
68+
-DSHERPA_ONNX_ENABLE_WEBSOCKET=OFF \
69+
-DDEPLOYMENT_TARGET=13.0 \
70+
-B build/simulator_x86_64
71+
72+
cmake --build build/simulator_x86_64 -j 4 --target install
73+
fi
74+
75+
echo "Building for simulator (arm64)"
76+
77+
if [[ ! -f build/simulator_arm64/install/lib/libsherpa-onnx-c-api.dylib ]]; then
78+
cmake \
79+
-DSHERPA_ONNX_ENABLE_BINARY=OFF \
80+
-DBUILD_PIPER_PHONMIZE_EXE=OFF \
81+
-DBUILD_PIPER_PHONMIZE_TESTS=OFF \
82+
-DBUILD_ESPEAK_NG_EXE=OFF \
83+
-DBUILD_ESPEAK_NG_TESTS=OFF \
84+
-S .. \
85+
-DCMAKE_TOOLCHAIN_FILE=./toolchains/ios.toolchain.cmake \
86+
-DPLATFORM=SIMULATORARM64 \
87+
-DENABLE_BITCODE=0 \
88+
-DENABLE_ARC=1 \
89+
-DENABLE_VISIBILITY=1 \
90+
-DCMAKE_BUILD_TYPE=Release \
91+
-DCMAKE_INSTALL_PREFIX=./build/simulator_arm64/install \
92+
-DBUILD_SHARED_LIBS=ON \
93+
-DSHERPA_ONNX_ENABLE_PYTHON=OFF \
94+
-DSHERPA_ONNX_ENABLE_TESTS=OFF \
95+
-DSHERPA_ONNX_ENABLE_CHECK=OFF \
96+
-DSHERPA_ONNX_ENABLE_PORTAUDIO=OFF \
97+
-DSHERPA_ONNX_ENABLE_JNI=OFF \
98+
-DSHERPA_ONNX_ENABLE_C_API=ON \
99+
-DSHERPA_ONNX_ENABLE_WEBSOCKET=OFF \
100+
-DDEPLOYMENT_TARGET=13.0 \
101+
-B build/simulator_arm64
102+
103+
cmake --build build/simulator_arm64 -j 4 --target install
104+
fi
105+
106+
echo "Building for arm64"
107+
108+
if [[ ! -f build/os64/install/lib/libsherpa-onnx-c-api.dylib ]]; then
109+
export SHERPA_ONNXRUNTIME_LIB_DIR=$PWD/ios-onnxruntime/onnxruntime.xcframework/ios-arm64
110+
111+
cmake \
112+
-DSHERPA_ONNX_ENABLE_BINARY=OFF \
113+
-DBUILD_PIPER_PHONMIZE_EXE=OFF \
114+
-DBUILD_PIPER_PHONMIZE_TESTS=OFF \
115+
-DBUILD_ESPEAK_NG_EXE=OFF \
116+
-DBUILD_ESPEAK_NG_TESTS=OFF \
117+
-S .. \
118+
-DCMAKE_TOOLCHAIN_FILE=./toolchains/ios.toolchain.cmake \
119+
-DPLATFORM=OS64 \
120+
-DENABLE_BITCODE=0 \
121+
-DENABLE_ARC=1 \
122+
-DENABLE_VISIBILITY=1 \
123+
-DCMAKE_BUILD_TYPE=Release \
124+
-DCMAKE_INSTALL_PREFIX=./build/os64/install \
125+
-DBUILD_SHARED_LIBS=ON \
126+
-DSHERPA_ONNX_ENABLE_PYTHON=OFF \
127+
-DSHERPA_ONNX_ENABLE_TESTS=OFF \
128+
-DSHERPA_ONNX_ENABLE_CHECK=OFF \
129+
-DSHERPA_ONNX_ENABLE_PORTAUDIO=OFF \
130+
-DSHERPA_ONNX_ENABLE_JNI=OFF \
131+
-DSHERPA_ONNX_ENABLE_C_API=ON \
132+
-DSHERPA_ONNX_ENABLE_WEBSOCKET=OFF \
133+
-DDEPLOYMENT_TARGET=13.0 \
134+
-B build/os64
135+
136+
cmake --build build/os64 -j 4 --target install
137+
fi
138+
139+
echo "Collect dynamic libraries "
140+
mkdir -p ios-arm64 ios-arm64-simulator ios-x86_64-simulator
141+
142+
cp -v ./build/os64/install/lib/libsherpa-onnx-c-api.dylib ios-arm64/
143+
cp -v ./build/simulator_arm64/install/lib/libsherpa-onnx-c-api.dylib ios-arm64-simulator
144+
cp -v .//build/simulator_x86_64/install/lib/libsherpa-onnx-c-api.dylib ios-x86_64-simulator

dart-api-examples/non-streaming-asr/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ environment:
1010

1111
# Add regular dependencies here.
1212
dependencies:
13-
sherpa_onnx: ^1.10.10
13+
sherpa_onnx: ^1.10.11
1414
path: ^1.9.0
1515
args: ^2.5.0
1616

dart-api-examples/streaming-asr/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ environment:
1111

1212
# Add regular dependencies here.
1313
dependencies:
14-
sherpa_onnx: ^1.10.10
14+
sherpa_onnx: ^1.10.11
1515
path: ^1.9.0
1616
args: ^2.5.0
1717

dart-api-examples/tts/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ environment:
88

99
# Add regular dependencies here.
1010
dependencies:
11-
sherpa_onnx: ^1.10.10
11+
sherpa_onnx: ^1.10.11
1212
path: ^1.9.0
1313
args: ^2.5.0
1414

dart-api-examples/vad/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ environment:
99
sdk: ^3.4.0
1010

1111
dependencies:
12-
sherpa_onnx: ^1.10.10
12+
sherpa_onnx: ^1.10.11
1313
path: ^1.9.0
1414
args: ^2.5.0
1515

0 commit comments

Comments
 (0)