mirror of
https://github.com/k2-fsa/sherpa-onnx.git
synced 2026-11-10 21:11:03 +08:00
Support swift package manager (SPM) (#3816)
This commit is contained in:
1 parent
d1fedc1daa
commit
14190197d9
14 files changed
+432
-89
No files matched your search
@@ -4,13 +4,7 @@ on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
paths:
|
||||
- './build-ios.sh'
|
||||
- '.github/workflows/build-xcframework.yaml'
|
||||
- 'CMakeLists.txt'
|
||||
- 'cmake/**'
|
||||
- 'sherpa-onnx/csrc/*'
|
||||
- 'sherpa-onnx/c-api/*'
|
||||
- test-spm-2
|
||||
tags:
|
||||
- 'v[0-9]+.[0-9]+.[0-9]+*'
|
||||
|
||||
@@ -21,8 +15,8 @@ concurrency:
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
build_xcframework:
|
||||
name: tts-${{ matrix.with_tts }}
|
||||
build_ios_xcframework:
|
||||
name: ios tts-${{ matrix.with_tts }}
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
@@ -39,8 +33,14 @@ jobs:
|
||||
./new-release.sh
|
||||
git diff .
|
||||
|
||||
- name: ccache
|
||||
uses: hendrikmuhs/ccache-action@v1.2
|
||||
with:
|
||||
key: ios-tts-${{ matrix.with_tts }}
|
||||
|
||||
- name: Build iOS shared
|
||||
if: matrix.with_tts == 'ON'
|
||||
# if: matrix.with_tts == 'ON'
|
||||
if: false
|
||||
shell: bash
|
||||
run: |
|
||||
export CMAKE_VERBOSE_MAKEFILE=ON
|
||||
@@ -50,77 +50,62 @@ jobs:
|
||||
if: matrix.with_tts == 'ON'
|
||||
shell: bash
|
||||
run: |
|
||||
export CMAKE_CXX_COMPILER_LAUNCHER=ccache
|
||||
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
|
||||
./build-ios.sh
|
||||
|
||||
- name: Build iOS (No tts)
|
||||
if: matrix.with_tts == 'OFF'
|
||||
shell: bash
|
||||
run: |
|
||||
export CMAKE_CXX_COMPILER_LAUNCHER=ccache
|
||||
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
|
||||
./build-ios-no-tts.sh
|
||||
|
||||
- name: Display artifacts
|
||||
if: matrix.with_tts == 'ON'
|
||||
shell: bash
|
||||
run: |
|
||||
brew install tree
|
||||
tree -L 2 ./build-ios
|
||||
ls -lh build-ios/*.xcframework.zip
|
||||
|
||||
- name: Display artifacts
|
||||
if: matrix.with_tts == 'OFF'
|
||||
shell: bash
|
||||
run: |
|
||||
brew install tree
|
||||
tree -L 2 ./build-ios-no-tts
|
||||
ls -lh build-ios-no-tts/*.xcframework.zip
|
||||
|
||||
- name: Package artifacts
|
||||
if: matrix.with_tts == 'ON'
|
||||
shell: bash
|
||||
run: |
|
||||
SHERPA_ONNX_VERSION=v$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2)
|
||||
echo "SHERPA_ONNX_VERSION=$SHERPA_ONNX_VERSION" >> "$GITHUB_ENV"
|
||||
|
||||
rm -rf build-ios/build
|
||||
rm -rf build-ios/install
|
||||
rm -rf build-ios/ios-onnxruntime/.git
|
||||
|
||||
tree build-ios
|
||||
|
||||
filename=sherpa-onnx-${SHERPA_ONNX_VERSION}-ios.tar.bz2
|
||||
|
||||
tar cjvf $filename ./build-ios
|
||||
|
||||
ls -lh
|
||||
|
||||
- name: Package artifacts
|
||||
if: matrix.with_tts == 'OFF'
|
||||
shell: bash
|
||||
run: |
|
||||
SHERPA_ONNX_VERSION=v$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2)
|
||||
echo "SHERPA_ONNX_VERSION=$SHERPA_ONNX_VERSION" >> "$GITHUB_ENV"
|
||||
|
||||
rm -rf build-ios-no-tts/build
|
||||
rm -rf build-ios-no-tts/install
|
||||
rm -rf build-ios-no-tts/ios-onnxruntime/.git
|
||||
|
||||
tree build-ios-no-tts
|
||||
|
||||
filename=sherpa-onnx-${SHERPA_ONNX_VERSION}-ios-no-tts.tar.bz2
|
||||
|
||||
tar cjvf $filename ./build-ios-no-tts
|
||||
|
||||
ls -lh
|
||||
|
||||
- uses: actions/upload-artifact@v4
|
||||
- name: Upload xcframework.zip
|
||||
if: matrix.with_tts == 'ON'
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: sherpa-onnx-ios-libs
|
||||
path: ./build-ios
|
||||
name: sherpa-onnx-ios-xcframework
|
||||
path: ./build-ios/*.xcframework.zip
|
||||
|
||||
- uses: actions/upload-artifact@v4
|
||||
- name: Upload xcframework.zip (no tts)
|
||||
if: matrix.with_tts == 'OFF'
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: sherpa-onnx-ios-libs-no-tts
|
||||
path: ./build-ios-no-tts
|
||||
name: sherpa-onnx-ios-no-tts-xcframework
|
||||
path: ./build-ios-no-tts/*.xcframework.zip
|
||||
|
||||
- name: Release xcframework
|
||||
if: github.repository_owner == 'k2-fsa' && github.event_name == 'push' && contains(github.ref, 'refs/tags/')
|
||||
uses: svenstaro/upload-release-action@v2
|
||||
with:
|
||||
file_glob: true
|
||||
overwrite: true
|
||||
file: ./build-ios*/*.xcframework.zip
|
||||
|
||||
- name: Release xcframework
|
||||
if: github.repository_owner == 'csukuangfj' && github.event_name == 'push' && contains(github.ref, 'refs/tags/')
|
||||
uses: svenstaro/upload-release-action@v2
|
||||
with:
|
||||
file_glob: true
|
||||
overwrite: true
|
||||
file: ./build-ios*/*.xcframework.zip
|
||||
# repo_name: k2-fsa/sherpa-onnx
|
||||
# repo_token: ${{ secrets.UPLOAD_GH_SHERPA_ONNX_TOKEN }}
|
||||
# tag: v1.13.4
|
||||
|
||||
# https://huggingface.co/docs/hub/spaces-github-actions
|
||||
- name: Publish to huggingface
|
||||
@@ -142,21 +127,102 @@ jobs:
|
||||
|
||||
cd huggingface
|
||||
|
||||
cp -v ../sherpa-onnx-*.tar.bz2 ./
|
||||
cp -v ../build-ios*/*.xcframework.zip ./
|
||||
|
||||
git status
|
||||
git lfs track "*.bz2"
|
||||
git lfs track "*.zip"
|
||||
|
||||
git add .
|
||||
|
||||
git commit -m "upload sherpa-onnx-${SHERPA_ONNX_VERSION}-ios.tar.bz2"
|
||||
SHERPA_ONNX_VERSION=v$(grep "SHERPA_ONNX_VERSION" ../CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2)
|
||||
git commit -m "upload sherpa-onnx-${SHERPA_ONNX_VERSION} xcframework"
|
||||
|
||||
git push https://csukuangfj2:$HF_TOKEN@huggingface.co/csukuangfj2/sherpa-onnx-libs main
|
||||
|
||||
|
||||
build_macos_xcframework:
|
||||
name: macos
|
||||
runs-on: macos-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Update version
|
||||
shell: bash
|
||||
run: |
|
||||
./new-release.sh
|
||||
git diff .
|
||||
|
||||
- name: ccache
|
||||
uses: hendrikmuhs/ccache-action@v1.2
|
||||
with:
|
||||
key: macos
|
||||
|
||||
- name: Build macOS
|
||||
shell: bash
|
||||
run: |
|
||||
export CMAKE_CXX_COMPILER_LAUNCHER=ccache
|
||||
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
|
||||
./build-swift-macos.sh
|
||||
|
||||
- name: Display artifacts
|
||||
shell: bash
|
||||
run: |
|
||||
ls -lh build-swift-macos/*.xcframework.zip
|
||||
|
||||
- name: Upload xcframework.zip
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: sherpa-onnx-macos-xcframework
|
||||
path: ./build-swift-macos/*.xcframework.zip
|
||||
|
||||
- name: Release xcframework
|
||||
if: (github.repository_owner == 'csukuangfj' || github.repository_owner == 'k2-fsa') && github.event_name == 'push' && contains(github.ref, 'refs/tags/')
|
||||
if: github.repository_owner == 'k2-fsa' && github.event_name == 'push' && contains(github.ref, 'refs/tags/')
|
||||
uses: svenstaro/upload-release-action@v2
|
||||
with:
|
||||
file_glob: true
|
||||
overwrite: true
|
||||
file: sherpa-onnx-*.tar.bz2
|
||||
file: ./build-swift-macos/*.xcframework.zip
|
||||
|
||||
- name: Release xcframework
|
||||
if: github.repository_owner == 'csukuangfj' && github.event_name == 'push' && contains(github.ref, 'refs/tags/')
|
||||
uses: svenstaro/upload-release-action@v2
|
||||
with:
|
||||
file_glob: true
|
||||
overwrite: true
|
||||
file: ./build-swift-macos/*.xcframework.zip
|
||||
# repo_name: k2-fsa/sherpa-onnx
|
||||
# repo_token: ${{ secrets.UPLOAD_GH_SHERPA_ONNX_TOKEN }}
|
||||
# tag: v1.13.4
|
||||
|
||||
# https://huggingface.co/docs/hub/spaces-github-actions
|
||||
- name: Publish to huggingface
|
||||
if: (github.repository_owner == 'csukuangfj' || github.repository_owner == 'k2-fsa') && (github.event_name == 'push' || github.event_name == 'workflow_dispatch')
|
||||
env:
|
||||
HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
||||
uses: nick-fields/retry@v3
|
||||
with:
|
||||
max_attempts: 20
|
||||
timeout_seconds: 200
|
||||
shell: bash
|
||||
command: |
|
||||
git config --global user.email "csukuangfj@gmail.com"
|
||||
git config --global user.name "Fangjun Kuang"
|
||||
|
||||
rm -rf huggingface
|
||||
export GIT_CLONE_PROTECTION_ACTIVE=false
|
||||
GIT_LFS_SKIP_SMUDGE=1 git clone https://csukuangfj2:$HF_TOKEN@huggingface.co/csukuangfj2/sherpa-onnx-libs huggingface
|
||||
|
||||
cd huggingface
|
||||
|
||||
cp -v ../build-swift-macos/*.xcframework.zip ./
|
||||
|
||||
git status
|
||||
git lfs track "*.zip"
|
||||
|
||||
git add .
|
||||
|
||||
SHERPA_ONNX_VERSION=v$(grep "SHERPA_ONNX_VERSION" ../CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2)
|
||||
git commit -m "upload sherpa-onnx-${SHERPA_ONNX_VERSION} macos xcframework"
|
||||
|
||||
git push https://csukuangfj2:$HF_TOKEN@huggingface.co/csukuangfj2/sherpa-onnx-libs main
|
||||
@@ -3,14 +3,7 @@ name: export-vits-ljspeech-to-onnx
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
paths:
|
||||
- 'scripts/vits/**'
|
||||
- '.github/workflows/export-vits-ljspeech-to-onnx.yaml'
|
||||
pull_request:
|
||||
paths:
|
||||
- 'scripts/vits/**'
|
||||
- '.github/workflows/export-vits-ljspeech-to-onnx.yaml'
|
||||
- export-vits
|
||||
|
||||
workflow_dispatch:
|
||||
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
name: test-spm
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- test-spm
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
test-spm-macos:
|
||||
name: Test SPM (macOS)
|
||||
runs-on: macos-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Build and run (macOS)
|
||||
shell: bash
|
||||
run: |
|
||||
cd spm-examples/macOS
|
||||
rm -rf .build
|
||||
swift package resolve
|
||||
swift package show-dependencies
|
||||
swift build --verbose
|
||||
swift run SherpaOnnxExample
|
||||
|
||||
test-spm-ios:
|
||||
name: Test SPM (iOS)
|
||||
runs-on: macos-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Build and run for iOS Simulator
|
||||
shell: bash
|
||||
run: |
|
||||
set -euo pipefail
|
||||
cd spm-examples/iOS
|
||||
|
||||
echo "=== Resolving ==="
|
||||
swift package resolve
|
||||
|
||||
echo "=== Building for iOS Simulator ==="
|
||||
xcodebuild -scheme SherpaOnnxExample \
|
||||
-destination "generic/platform=iOS Simulator" \
|
||||
-skipPackagePluginValidation \
|
||||
-verbose \
|
||||
build 2>&1
|
||||
|
||||
echo "=== Finding built executable ==="
|
||||
BINARY=$(find ~/Library/Developer/Xcode/DerivedData -path "*/Build/Products/*-iphonesimulator/SherpaOnnxExample" -type f | head -1)
|
||||
echo "Binary: $BINARY"
|
||||
|
||||
echo "=== Booting iOS Simulator ==="
|
||||
DEVICE=$(xcrun simctl list devices available -j | python3 -c "
|
||||
import json, sys
|
||||
devices = json.load(sys.stdin)['devices']
|
||||
for key in devices:
|
||||
for d in devices[key]:
|
||||
if d['isAvailable'] and 'iPhone' in d['name']:
|
||||
print(d['udid'])
|
||||
sys.exit(0)
|
||||
")
|
||||
echo "Device: $DEVICE"
|
||||
xcrun simctl boot "$DEVICE" 2>/dev/null || true
|
||||
|
||||
echo "=== Running on iOS Simulator ==="
|
||||
xcrun simctl spawn "$DEVICE" "$BINARY"
|
||||
+127
@@ -0,0 +1,127 @@
|
||||
// swift-tools-version: 5.9
|
||||
import PackageDescription
|
||||
|
||||
let package = Package(
|
||||
name: "sherpa-onnx",
|
||||
platforms: [
|
||||
.iOS(.v15),
|
||||
.macOS(.v10_15),
|
||||
],
|
||||
products: [
|
||||
.library(
|
||||
name: "sherpa-onnx",
|
||||
targets: ["SherpaOnnx"]
|
||||
),
|
||||
],
|
||||
dependencies: [
|
||||
.package(url: "https://github.com/csukuangfj/onnxruntime-libs", branch: "master"),
|
||||
],
|
||||
targets: [
|
||||
.binaryTarget(
|
||||
name: "SherpaOnnxMacOS",
|
||||
url: "https://github.com/k2-fsa/sherpa-onnx/releases/download/v1.13.4/sherpa-onnx-v1.13.4-macos.xcframework.zip",
|
||||
checksum: "4325d8aed99b94be58969005b19f9626f3f3afc4ebd42378b0aad2b84e233552"
|
||||
),
|
||||
.binaryTarget(
|
||||
name: "SherpaOnnxIOS",
|
||||
url: "https://github.com/k2-fsa/sherpa-onnx/releases/download/v1.13.4/sherpa-onnx-v1.13.4-ios.xcframework.zip",
|
||||
checksum: "c5a62904bba73edc4bac89bbf51b4c3db1dd6c1b397a16ee95b2ff94701e9846"
|
||||
),
|
||||
.target(
|
||||
name: "SherpaOnnx",
|
||||
dependencies: [
|
||||
.product(name: "onnxruntime-macos", package: "onnxruntime-libs", condition: .when(platforms: [.macOS])),
|
||||
.product(name: "onnxruntime-ios", package: "onnxruntime-libs", condition: .when(platforms: [.iOS])),
|
||||
.target(name: "SherpaOnnxMacOS", condition: .when(platforms: [.macOS])),
|
||||
.target(name: "SherpaOnnxIOS", condition: .when(platforms: [.iOS])),
|
||||
],
|
||||
path: "swift-api-examples",
|
||||
exclude: [
|
||||
"SherpaOnnx-Bridging-Header.h",
|
||||
"add-punctuation-online.swift",
|
||||
"add-punctuations.swift",
|
||||
"cohere-transcribe.swift",
|
||||
"compute-speaker-embeddings.swift",
|
||||
"decode-file-non-streaming.swift",
|
||||
"decode-file-sense-voice-with-hr.swift",
|
||||
"decode-file-t-one-streaming.swift",
|
||||
"decode-file.swift",
|
||||
"dolphin-ctc-asr.swift",
|
||||
"fire-red-asr-ctc.swift",
|
||||
"fire-red-asr.swift",
|
||||
"funasr-nano.swift",
|
||||
"generate-subtitles.swift",
|
||||
"keyword-spotting-from-file.swift",
|
||||
"medasr-ctc.swift",
|
||||
"moonshine-v2-asr.swift",
|
||||
"omnilingual-asr-ctc.swift",
|
||||
"online-speech-enhancement-dpdfnet.swift",
|
||||
"online-speech-enhancement-gtcrn.swift",
|
||||
"qwen3-asr.swift",
|
||||
"source-separation-spleeter.swift",
|
||||
"source-separation-uvr.swift",
|
||||
"speaker-diarization.swift",
|
||||
"speech-enhancement-dpdfnet.swift",
|
||||
"speech-enhancement-gtcrn.swift",
|
||||
"spoken-language-identification.swift",
|
||||
"streaming-hlg-decode-file.swift",
|
||||
"test-version.swift",
|
||||
"tts-kitten-en.swift",
|
||||
"tts-kokoro-en.swift",
|
||||
"tts-kokoro-zh-en.swift",
|
||||
"tts-matcha-en.swift",
|
||||
"tts-matcha-zh.swift",
|
||||
"tts-pocket-en.swift",
|
||||
"tts-supertonic-en.swift",
|
||||
"tts-vits.swift",
|
||||
"tts-zipvoice.swift",
|
||||
"wenet-ctc-asr.swift",
|
||||
"zipformer-ctc-asr.swift",
|
||||
"run-add-punctuations-online.sh",
|
||||
"run-add-punctuations.sh",
|
||||
"run-cohere-transcribe.sh",
|
||||
"run-compute-speaker-embeddings.sh",
|
||||
"run-decode-file-non-streaming.sh",
|
||||
"run-decode-file-sense-voice-with-hr.sh",
|
||||
"run-decode-file-t-one-streaming.sh",
|
||||
"run-decode-file.sh",
|
||||
"run-dolphin-ctc-asr.sh",
|
||||
"run-fire-red-asr-ctc.sh",
|
||||
"run-fire-red-asr.sh",
|
||||
"run-funasr-nano-asr.sh",
|
||||
"run-generate-subtitles-ten-vad.sh",
|
||||
"run-generate-subtitles.sh",
|
||||
"run-keyword-spotting-from-file.sh",
|
||||
"run-medasr-ctc-asr.sh",
|
||||
"run-moonshine-v2-asr.sh",
|
||||
"run-omnilingual-asr-ctc-asr.sh",
|
||||
"run-online-speech-enhancement-dpdfnet.sh",
|
||||
"run-online-speech-enhancement-gtcrn.sh",
|
||||
"run-qwen3-asr.sh",
|
||||
"run-source-separation-spleeter.sh",
|
||||
"run-source-separation-uvr.sh",
|
||||
"run-speaker-diarization.sh",
|
||||
"run-speech-enhancement-dpdfnet.sh",
|
||||
"run-speech-enhancement-gtcrn.sh",
|
||||
"run-spoken-language-identification.sh",
|
||||
"run-streaming-hlg-decode-file.sh",
|
||||
"run-test-version.sh",
|
||||
"run-tts-kitten-en.sh",
|
||||
"run-tts-kokoro-en.sh",
|
||||
"run-tts-kokoro-zh-en.sh",
|
||||
"run-tts-matcha-en.sh",
|
||||
"run-tts-matcha-zh.sh",
|
||||
"run-tts-pocket-en.sh",
|
||||
"run-tts-supertonic-en.sh",
|
||||
"run-tts-vits.sh",
|
||||
"run-tts-zipvoice.sh",
|
||||
"run-wenet-ctc-asr.sh",
|
||||
"run-zipformer-ctc-asr.sh",
|
||||
],
|
||||
sources: ["SherpaOnnx.swift"],
|
||||
linkerSettings: [
|
||||
.linkedLibrary("c++"),
|
||||
]
|
||||
),
|
||||
]
|
||||
)
|
||||
+11
-10
@@ -50,6 +50,7 @@ cmake \
|
||||
-DCMAKE_BUILD_TYPE=Release \
|
||||
-DBUILD_SHARED_LIBS=OFF \
|
||||
-DSHERPA_ONNX_ENABLE_PYTHON=OFF \
|
||||
-DSHERPA_ONNX_ENABLE_BINARY=OFF \
|
||||
-DSHERPA_ONNX_ENABLE_TESTS=OFF \
|
||||
-DSHERPA_ONNX_ENABLE_CHECK=OFF \
|
||||
-DSHERPA_ONNX_ENABLE_PORTAUDIO=OFF \
|
||||
@@ -79,6 +80,7 @@ cmake \
|
||||
-DCMAKE_INSTALL_PREFIX=./install \
|
||||
-DBUILD_SHARED_LIBS=OFF \
|
||||
-DSHERPA_ONNX_ENABLE_PYTHON=OFF \
|
||||
-DSHERPA_ONNX_ENABLE_BINARY=OFF \
|
||||
-DSHERPA_ONNX_ENABLE_TESTS=OFF \
|
||||
-DSHERPA_ONNX_ENABLE_CHECK=OFF \
|
||||
-DSHERPA_ONNX_ENABLE_PORTAUDIO=OFF \
|
||||
@@ -112,6 +114,7 @@ cmake \
|
||||
-DCMAKE_BUILD_TYPE=Release \
|
||||
-DBUILD_SHARED_LIBS=OFF \
|
||||
-DSHERPA_ONNX_ENABLE_PYTHON=OFF \
|
||||
-DSHERPA_ONNX_ENABLE_BINARY=OFF \
|
||||
-DSHERPA_ONNX_ENABLE_TESTS=OFF \
|
||||
-DSHERPA_ONNX_ENABLE_CHECK=OFF \
|
||||
-DSHERPA_ONNX_ENABLE_PORTAUDIO=OFF \
|
||||
@@ -124,6 +127,7 @@ cmake \
|
||||
cmake --build build/os64 -j 4
|
||||
# Generate headers for sherpa-onnx.xcframework
|
||||
cmake --build build/os64 --target install
|
||||
cp -v ../sherpa-onnx/c-api/module.modulemap ./install/include/sherpa-onnx/c-api/
|
||||
|
||||
echo "Generate xcframework"
|
||||
|
||||
@@ -162,17 +166,14 @@ libtool -static -o build/os64/sherpa-onnx.a \
|
||||
rm -rf sherpa-onnx.xcframework
|
||||
|
||||
xcodebuild -create-xcframework \
|
||||
-library "build/os64/sherpa-onnx.a" \
|
||||
-library "build/simulator/sherpa-onnx.a" \
|
||||
-library "build/os64/sherpa-onnx.a" -headers install/include/sherpa-onnx/c-api \
|
||||
-library "build/simulator/sherpa-onnx.a" -headers install/include/sherpa-onnx/c-api \
|
||||
-output sherpa-onnx.xcframework
|
||||
|
||||
# Copy Headers
|
||||
mkdir -p sherpa-onnx.xcframework/Headers
|
||||
cp -av install/include/* sherpa-onnx.xcframework/Headers
|
||||
SHERPA_ONNX_VERSION=v$(grep "SHERPA_ONNX_VERSION" ../CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2)
|
||||
|
||||
pushd sherpa-onnx.xcframework/ios-arm64_x86_64-simulator
|
||||
ln -s sherpa-onnx.a libsherpa-onnx.a
|
||||
popd
|
||||
rm -f sherpa-onnx-${SHERPA_ONNX_VERSION}-ios-no-tts.xcframework.zip
|
||||
zip -r -y sherpa-onnx-${SHERPA_ONNX_VERSION}-ios-no-tts.xcframework.zip sherpa-onnx.xcframework
|
||||
|
||||
pushd sherpa-onnx.xcframework/ios-arm64
|
||||
ln -s sherpa-onnx.a libsherpa-onnx.a
|
||||
echo "Checksum:"
|
||||
swift package compute-checksum sherpa-onnx-${SHERPA_ONNX_VERSION}-ios-no-tts.xcframework.zip | tee checksum.txt
|
||||
+11
-2
@@ -123,6 +123,7 @@ cmake \
|
||||
cmake --build build/os64 -j 4
|
||||
# Generate headers for sherpa-onnx.xcframework
|
||||
cmake --build build/os64 --target install
|
||||
cp -v ../sherpa-onnx/c-api/module.modulemap ./install/include/sherpa-onnx/c-api/
|
||||
|
||||
echo "Generate xcframework"
|
||||
|
||||
@@ -169,6 +170,14 @@ libtool -static -o build/os64/libsherpa-onnx.a \
|
||||
rm -rf sherpa-onnx.xcframework
|
||||
|
||||
xcodebuild -create-xcframework \
|
||||
-library "build/os64/libsherpa-onnx.a" -headers install/include \
|
||||
-library "build/simulator/libsherpa-onnx.a" -headers install/include \
|
||||
-library "build/os64/libsherpa-onnx.a" -headers install/include/sherpa-onnx/c-api \
|
||||
-library "build/simulator/libsherpa-onnx.a" -headers install/include/sherpa-onnx/c-api \
|
||||
-output sherpa-onnx.xcframework
|
||||
|
||||
SHERPA_ONNX_VERSION=v$(grep "SHERPA_ONNX_VERSION" ../CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2)
|
||||
|
||||
rm -f sherpa-onnx-${SHERPA_ONNX_VERSION}-ios.xcframework.zip
|
||||
zip -r -y sherpa-onnx-${SHERPA_ONNX_VERSION}-ios.xcframework.zip sherpa-onnx.xcframework
|
||||
|
||||
echo "Checksum:"
|
||||
swift package compute-checksum sherpa-onnx-${SHERPA_ONNX_VERSION}-ios.xcframework.zip | tee checksum.txt
|
||||
+10
-1
@@ -25,6 +25,7 @@ cmake \
|
||||
make -j4
|
||||
make install
|
||||
rm -fv ./install/include/cargs.h
|
||||
cp -v ../sherpa-onnx/c-api/module.modulemap ./install/include/sherpa-onnx/c-api/
|
||||
|
||||
libtool -static -o ./install/lib/libsherpa-onnx.a \
|
||||
./install/lib/libsherpa-onnx-c-api.a \
|
||||
@@ -42,5 +43,13 @@ libtool -static -o ./install/lib/libsherpa-onnx.a \
|
||||
|
||||
xcodebuild -create-xcframework \
|
||||
-library install/lib/libsherpa-onnx.a \
|
||||
-headers install/include \
|
||||
-headers install/include/sherpa-onnx/c-api \
|
||||
-output sherpa-onnx.xcframework
|
||||
|
||||
SHERPA_ONNX_VERSION=v$(grep "SHERPA_ONNX_VERSION" ../CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2)
|
||||
|
||||
rm -f sherpa-onnx-${SHERPA_ONNX_VERSION}-macos.xcframework.zip
|
||||
zip -r -y sherpa-onnx-${SHERPA_ONNX_VERSION}-macos.xcframework.zip sherpa-onnx.xcframework
|
||||
|
||||
echo "Checksum:"
|
||||
swift package compute-checksum sherpa-onnx-${SHERPA_ONNX_VERSION}-macos.xcframework.zip | tee checksum.txt
|
||||
@@ -7,13 +7,14 @@
|
||||
#include "sherpa-onnx/c-api/cxx-api.h"
|
||||
|
||||
auto main() -> int {
|
||||
using namespace sherpa_onnx::cxx; // NOLINT
|
||||
std::cout << "sherpa-onnx version : " << GetVersionStr()
|
||||
std::cout << "sherpa-onnx version : " << sherpa_onnx::cxx::GetVersionStr()
|
||||
<< "\n";
|
||||
std::cout << "sherpa-onnx Git SHA1: " << GetGitSha1() << "\n";
|
||||
std::cout << "sherpa-onnx Git date: " << GetGitDate() << "\n";
|
||||
std::cout << "onnxruntime version : " << GetOnnxruntimeVersionStr()
|
||||
std::cout << "sherpa-onnx Git SHA1: " << sherpa_onnx::cxx::GetGitSha1()
|
||||
<< "\n";
|
||||
std::cout << "sherpa-onnx Git date: " << sherpa_onnx::cxx::GetGitDate()
|
||||
<< "\n";
|
||||
std::cout << "onnxruntime version : "
|
||||
<< sherpa_onnx::cxx::GetOnnxruntimeVersionStr() << "\n";
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
module SherpaOnnxC {
|
||||
header "c-api.h"
|
||||
export *
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
// swift-tools-version: 5.9
|
||||
import PackageDescription
|
||||
|
||||
let package = Package(
|
||||
name: "SherpaOnnxExample",
|
||||
platforms: [.iOS(.v15)],
|
||||
dependencies: [
|
||||
.package(url: "https://github.com/k2-fsa/sherpa-onnx", branch: "master"),
|
||||
],
|
||||
targets: [
|
||||
.executableTarget(
|
||||
name: "SherpaOnnxExample",
|
||||
dependencies: [
|
||||
.product(name: "sherpa-onnx", package: "sherpa-onnx"),
|
||||
],
|
||||
linkerSettings: [
|
||||
.linkedLibrary("c++"),
|
||||
]
|
||||
)
|
||||
]
|
||||
)
|
||||
@@ -0,0 +1,11 @@
|
||||
import SherpaOnnxC
|
||||
|
||||
let version = String(cString: SherpaOnnxGetVersionStr())
|
||||
let gitSha1 = String(cString: SherpaOnnxGetGitSha1())
|
||||
let gitDate = String(cString: SherpaOnnxGetGitDate())
|
||||
let ortVersion = String(cString: SherpaOnnxGetOnnxruntimeVersionStr())
|
||||
|
||||
print("sherpa-onnx version : \(version)")
|
||||
print("sherpa-onnx Git SHA1: \(gitSha1)")
|
||||
print("sherpa-onnx Git date: \(gitDate)")
|
||||
print("onnxruntime version : \(ortVersion)")
|
||||
@@ -0,0 +1,18 @@
|
||||
// swift-tools-version: 5.9
|
||||
import PackageDescription
|
||||
|
||||
let package = Package(
|
||||
name: "SherpaOnnxExample",
|
||||
platforms: [.macOS(.v10_15)],
|
||||
dependencies: [
|
||||
.package(url: "https://github.com/k2-fsa/sherpa-onnx", branch: "master"),
|
||||
],
|
||||
targets: [
|
||||
.executableTarget(
|
||||
name: "SherpaOnnxExample",
|
||||
dependencies: [
|
||||
.product(name: "sherpa-onnx", package: "sherpa-onnx"),
|
||||
]
|
||||
)
|
||||
]
|
||||
)
|
||||
@@ -0,0 +1,11 @@
|
||||
import SherpaOnnxC
|
||||
|
||||
let version = String(cString: SherpaOnnxGetVersionStr())
|
||||
let gitSha1 = String(cString: SherpaOnnxGetGitSha1())
|
||||
let gitDate = String(cString: SherpaOnnxGetGitDate())
|
||||
let ortVersion = String(cString: SherpaOnnxGetOnnxruntimeVersionStr())
|
||||
|
||||
print("sherpa-onnx version : \(version)")
|
||||
print("sherpa-onnx Git SHA1: \(gitSha1)")
|
||||
print("sherpa-onnx Git date: \(gitDate)")
|
||||
print("onnxruntime version : \(ortVersion)")
|
||||
@@ -2,6 +2,9 @@
|
||||
/// Copyright (c) 2023 Xiaomi Corporation
|
||||
|
||||
import Foundation // For NSString
|
||||
#if SWIFT_PACKAGE
|
||||
import SherpaOnnxC
|
||||
#endif
|
||||
|
||||
/// Convert a String from swift to a `const char*` so that we can pass it to
|
||||
/// the C language.
|
||||
|
||||
Reference in new issue
Block a user