-
Notifications
You must be signed in to change notification settings - Fork 414
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support the platform iOS for Flutter (#1079)
- Loading branch information
1 parent
a250751
commit 1fe12c5
Showing
67 changed files
with
2,040 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,14 +24,6 @@ jobs: | |
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Setup Flutter SDK | ||
uses: flutter-actions/setup-flutter@v3 | ||
with: | ||
channel: stable | ||
version: latest | ||
|
||
- uses: dart-lang/setup-dart@v1 | ||
|
||
- name: Fix version | ||
shell: bash | ||
run: | | ||
|
@@ -104,6 +96,14 @@ jobs: | |
ls -lh /tmp/to_be_published/linux | ||
- name: Setup Flutter SDK | ||
uses: flutter-actions/setup-flutter@v3 | ||
with: | ||
channel: stable | ||
version: latest | ||
|
||
- uses: dart-lang/setup-dart@v1 | ||
|
||
- name: Release | ||
shell: bash | ||
run: | | ||
|
@@ -127,14 +127,6 @@ jobs: | |
with: | ||
key: ${{ matrix.os }}-flutter-release-package | ||
|
||
- name: Setup Flutter SDK | ||
uses: flutter-actions/setup-flutter@v3 | ||
with: | ||
channel: stable | ||
version: latest | ||
|
||
- uses: dart-lang/setup-dart@v1 | ||
|
||
- name: Fix version | ||
shell: bash | ||
run: | | ||
|
@@ -205,6 +197,14 @@ jobs: | |
ls -lh /tmp/to_be_published/macos | ||
- name: Setup Flutter SDK | ||
uses: flutter-actions/setup-flutter@v3 | ||
with: | ||
channel: stable | ||
version: latest | ||
|
||
- uses: dart-lang/setup-dart@v1 | ||
|
||
- name: Release | ||
shell: bash | ||
run: | | ||
|
@@ -429,8 +429,89 @@ jobs: | |
flutter pub publish --dry-run | ||
flutter pub publish --force | ||
sherpa_onnx_ios: | ||
# if: false | ||
permissions: | ||
id-token: write # Required for authentication using OIDC | ||
name: sherpa_onnx_ios | ||
runs-on: macos-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: ccache | ||
uses: hendrikmuhs/[email protected] | ||
with: | ||
key: ${{ matrix.os }}-flutter-release-package-ios | ||
|
||
- name: Fix version | ||
shell: bash | ||
run: | | ||
SHERPA_ONNX_VERSION=$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2) | ||
src_dir=$PWD/flutter/sherpa_onnx_ios | ||
pushd $src_dir | ||
v="version: $SHERPA_ONNX_VERSION" | ||
echo "v: $v" | ||
sed -i.bak s"/^version: .*/$v/" ./pubspec.yaml | ||
rm *.bak | ||
git status | ||
git diff | ||
- name: Copy extra files | ||
shell: bash | ||
run: | | ||
dst=flutter/sherpa_onnx_ios | ||
mkdir $dst/example | ||
cp -v flutter/sherpa_onnx/example/* $dst/example | ||
cp -v LICENSE $dst/ | ||
cp -v CHANGELOG.md $dst/ | ||
git status | ||
- name: Build ios | ||
shell: bash | ||
run: | | ||
export CMAKE_CXX_COMPILER_LAUNCHER=ccache | ||
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" | ||
cmake --version | ||
./build-ios-shared.sh | ||
- name: Copy pre-built libs | ||
shell: bash | ||
run: | | ||
echo "----ios-arm64----" | ||
cp -v build-ios-shared/ios-arm64/libsherpa-onnx-c-api.dylib flutter/sherpa_onnx_ios/ios/ | ||
cp -v build-ios-shared/ios-onnxruntime/onnxruntime.xcframework/ios-arm64/onnxruntime.a flutter/sherpa_onnx_ios/ios/libonnxruntime.a | ||
ls -lh flutter/sherpa_onnx_ios/ios/libonnxruntime.a | ||
mv -v flutter/sherpa_onnx_ios /tmp/to_be_published | ||
ls -lh /tmp/to_be_published | ||
- name: Setup Flutter SDK | ||
uses: flutter-actions/setup-flutter@v3 | ||
with: | ||
channel: stable | ||
version: latest | ||
|
||
- uses: dart-lang/setup-dart@v1 | ||
|
||
- name: Release | ||
shell: bash | ||
run: | | ||
cd /tmp/to_be_published | ||
du -h -d1 . | ||
flutter pub get | ||
flutter pub publish --dry-run | ||
flutter pub publish --force | ||
sherpa_onnx: | ||
# needs: [sherpa_onnx_linux, sherpa_onnx_macos, sherpa_onnx_windows, sherpa_onnx_android] | ||
needs: [sherpa_onnx_linux, sherpa_onnx_macos, sherpa_onnx_windows, sherpa_onnx_android, sherpa_onnx_ios] | ||
# if: false | ||
permissions: | ||
id-token: write # Required for authentication using OIDC | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -109,3 +109,4 @@ sherpa-onnx-vits-* | |
sherpa-onnx-telespeech-ctc-* | ||
*.fst | ||
.ccache | ||
lib*.a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
## 1.10.11 | ||
|
||
* Support the iOS platform for iOS. | ||
|
||
## 1.10.10 | ||
|
||
* Build sherpa-onnx into a single shared library. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# Note: This script is to build sherpa-onnx for flutter/dart, which requires | ||
# us to use shared libraries for sherpa-onnx. | ||
# | ||
# Note: We still use static libraries for onnxruntime. | ||
|
||
set -e | ||
|
||
dir=build-ios-shared | ||
mkdir -p $dir | ||
cd $dir | ||
onnxruntime_version=1.17.1 | ||
onnxruntime_dir=ios-onnxruntime/$onnxruntime_version | ||
|
||
SHERPA_ONNX_GITHUB=github.com | ||
|
||
if [ "$SHERPA_ONNX_GITHUB_MIRROW" == true ]; then | ||
SHERPA_ONNX_GITHUB=hub.nuaa.cf | ||
fi | ||
|
||
if [ ! -f $onnxruntime_dir/onnxruntime.xcframework/ios-arm64/onnxruntime.a ]; then | ||
mkdir -p $onnxruntime_dir | ||
pushd $onnxruntime_dir | ||
wget -c https://${SHERPA_ONNX_GITHUB}/csukuangfj/onnxruntime-libs/releases/download/v${onnxruntime_version}/onnxruntime.xcframework-${onnxruntime_version}.tar.bz2 | ||
tar xvf onnxruntime.xcframework-${onnxruntime_version}.tar.bz2 | ||
rm onnxruntime.xcframework-${onnxruntime_version}.tar.bz2 | ||
cd .. | ||
ln -sf $onnxruntime_version/onnxruntime.xcframework . | ||
popd | ||
fi | ||
|
||
# First, for simulator | ||
echo "Building for simulator (x86_64)" | ||
|
||
export SHERPA_ONNXRUNTIME_LIB_DIR=$PWD/ios-onnxruntime/onnxruntime.xcframework/ios-arm64_x86_64-simulator | ||
export SHERPA_ONNXRUNTIME_INCLUDE_DIR=$PWD/ios-onnxruntime/onnxruntime.xcframework/Headers | ||
|
||
echo "SHERPA_ONNXRUNTIME_LIB_DIR: $SHERPA_ONNXRUNTIME_LIB_DIR" | ||
echo "SHERPA_ONNXRUNTIME_INCLUDE_DIR $SHERPA_ONNXRUNTIME_INCLUDE_DIR" | ||
|
||
# Note: We use -DENABLE_ARC=1 here to fix the linking error: | ||
# | ||
# The symbol _NSLog is not defined | ||
# | ||
if [[ ! -f build/simulator_x86_64/install/lib/libsherpa-onnx-c-api.dylib ]]; then | ||
cmake \ | ||
-DSHERPA_ONNX_ENABLE_BINARY=OFF \ | ||
-DBUILD_PIPER_PHONMIZE_EXE=OFF \ | ||
-DBUILD_PIPER_PHONMIZE_TESTS=OFF \ | ||
-DBUILD_ESPEAK_NG_EXE=OFF \ | ||
-DBUILD_ESPEAK_NG_TESTS=OFF \ | ||
-S .. \ | ||
-DCMAKE_TOOLCHAIN_FILE=./toolchains/ios.toolchain.cmake \ | ||
-DPLATFORM=SIMULATOR64 \ | ||
-DENABLE_BITCODE=0 \ | ||
-DENABLE_ARC=1 \ | ||
-DENABLE_VISIBILITY=1 \ | ||
-DCMAKE_BUILD_TYPE=Release \ | ||
-DCMAKE_INSTALL_PREFIX=./build/simulator_x86_64/install \ | ||
-DBUILD_SHARED_LIBS=ON \ | ||
-DSHERPA_ONNX_ENABLE_PYTHON=OFF \ | ||
-DSHERPA_ONNX_ENABLE_TESTS=OFF \ | ||
-DSHERPA_ONNX_ENABLE_CHECK=OFF \ | ||
-DSHERPA_ONNX_ENABLE_PORTAUDIO=OFF \ | ||
-DSHERPA_ONNX_ENABLE_JNI=OFF \ | ||
-DSHERPA_ONNX_ENABLE_C_API=ON \ | ||
-DSHERPA_ONNX_ENABLE_WEBSOCKET=OFF \ | ||
-DDEPLOYMENT_TARGET=13.0 \ | ||
-B build/simulator_x86_64 | ||
|
||
cmake --build build/simulator_x86_64 -j 4 --target install | ||
fi | ||
|
||
echo "Building for simulator (arm64)" | ||
|
||
if [[ ! -f build/simulator_arm64/install/lib/libsherpa-onnx-c-api.dylib ]]; then | ||
cmake \ | ||
-DSHERPA_ONNX_ENABLE_BINARY=OFF \ | ||
-DBUILD_PIPER_PHONMIZE_EXE=OFF \ | ||
-DBUILD_PIPER_PHONMIZE_TESTS=OFF \ | ||
-DBUILD_ESPEAK_NG_EXE=OFF \ | ||
-DBUILD_ESPEAK_NG_TESTS=OFF \ | ||
-S .. \ | ||
-DCMAKE_TOOLCHAIN_FILE=./toolchains/ios.toolchain.cmake \ | ||
-DPLATFORM=SIMULATORARM64 \ | ||
-DENABLE_BITCODE=0 \ | ||
-DENABLE_ARC=1 \ | ||
-DENABLE_VISIBILITY=1 \ | ||
-DCMAKE_BUILD_TYPE=Release \ | ||
-DCMAKE_INSTALL_PREFIX=./build/simulator_arm64/install \ | ||
-DBUILD_SHARED_LIBS=ON \ | ||
-DSHERPA_ONNX_ENABLE_PYTHON=OFF \ | ||
-DSHERPA_ONNX_ENABLE_TESTS=OFF \ | ||
-DSHERPA_ONNX_ENABLE_CHECK=OFF \ | ||
-DSHERPA_ONNX_ENABLE_PORTAUDIO=OFF \ | ||
-DSHERPA_ONNX_ENABLE_JNI=OFF \ | ||
-DSHERPA_ONNX_ENABLE_C_API=ON \ | ||
-DSHERPA_ONNX_ENABLE_WEBSOCKET=OFF \ | ||
-DDEPLOYMENT_TARGET=13.0 \ | ||
-B build/simulator_arm64 | ||
|
||
cmake --build build/simulator_arm64 -j 4 --target install | ||
fi | ||
|
||
echo "Building for arm64" | ||
|
||
if [[ ! -f build/os64/install/lib/libsherpa-onnx-c-api.dylib ]]; then | ||
export SHERPA_ONNXRUNTIME_LIB_DIR=$PWD/ios-onnxruntime/onnxruntime.xcframework/ios-arm64 | ||
|
||
cmake \ | ||
-DSHERPA_ONNX_ENABLE_BINARY=OFF \ | ||
-DBUILD_PIPER_PHONMIZE_EXE=OFF \ | ||
-DBUILD_PIPER_PHONMIZE_TESTS=OFF \ | ||
-DBUILD_ESPEAK_NG_EXE=OFF \ | ||
-DBUILD_ESPEAK_NG_TESTS=OFF \ | ||
-S .. \ | ||
-DCMAKE_TOOLCHAIN_FILE=./toolchains/ios.toolchain.cmake \ | ||
-DPLATFORM=OS64 \ | ||
-DENABLE_BITCODE=0 \ | ||
-DENABLE_ARC=1 \ | ||
-DENABLE_VISIBILITY=1 \ | ||
-DCMAKE_BUILD_TYPE=Release \ | ||
-DCMAKE_INSTALL_PREFIX=./build/os64/install \ | ||
-DBUILD_SHARED_LIBS=ON \ | ||
-DSHERPA_ONNX_ENABLE_PYTHON=OFF \ | ||
-DSHERPA_ONNX_ENABLE_TESTS=OFF \ | ||
-DSHERPA_ONNX_ENABLE_CHECK=OFF \ | ||
-DSHERPA_ONNX_ENABLE_PORTAUDIO=OFF \ | ||
-DSHERPA_ONNX_ENABLE_JNI=OFF \ | ||
-DSHERPA_ONNX_ENABLE_C_API=ON \ | ||
-DSHERPA_ONNX_ENABLE_WEBSOCKET=OFF \ | ||
-DDEPLOYMENT_TARGET=13.0 \ | ||
-B build/os64 | ||
|
||
cmake --build build/os64 -j 4 --target install | ||
fi | ||
|
||
echo "Collect dynamic libraries " | ||
mkdir -p ios-arm64 ios-arm64-simulator ios-x86_64-simulator | ||
|
||
cp -v ./build/os64/install/lib/libsherpa-onnx-c-api.dylib ios-arm64/ | ||
cp -v ./build/simulator_arm64/install/lib/libsherpa-onnx-c-api.dylib ios-arm64-simulator | ||
cp -v .//build/simulator_x86_64/install/lib/libsherpa-onnx-c-api.dylib ios-x86_64-simulator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.