Skip to content

Commit

Permalink
change: Onnxruntime型を追加し、そこからdlopen/LoadLibrary*を行う (#802)
Browse files Browse the repository at this point in the history
* change: `Onnxruntime`型を追加し、そこから`dlopen`/`LoadLibrary*`を行う

* KotlinのexampleにFIXMEを追加

* "ONNX Runtimeを表す" → "AIエンジンの"

* ドキュメントとコメントを追加

* フィーチャをリネーム

* fixup! フィーチャをリネーム

* fixup! フィーチャをリネーム

* fixup! フィーチャをリネーム

* fixup! フィーチャをリネーム

* fixup! フィーチャをリネーム

* voicevox-ortを更新

* `sed`のし損ねを修正

* ドキュメントやコメントを更新

* C APIに定数のgetterを追加

* voicevox-ortを更新

* "filename"を"ファイル名(モジュール名)もしくはファイルパス"に

* C APIのドキュメントに"Availability"のセクションを追加

* フィーチャに関するドキュメントを更新

#802 (comment)

* C APIのビルドに関するドキュメントのヘッダファイル周りを更新

* voicevox-ortを更新

* `JavaStr`を`CStr::to_str`しない

* fixup! `JavaStr`を`CStr::to_str`しない

* 不要な依存を削除

* `link-onnxruntime`で`cargo test`が通るようにする

* fixup! `link-onnxruntime`で`cargo test`が通るようにする

* fixup! `link-onnxruntime`で`cargo test`が通るようにする
  • Loading branch information
qryxip authored Jul 4, 2024
1 parent a728d7e commit 537d9b2
Show file tree
Hide file tree
Showing 84 changed files with 2,253 additions and 323 deletions.
40 changes: 35 additions & 5 deletions .github/workflows/build_and_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,14 @@ defaults:
shell: bash

jobs:
config: # 全 jobs で利用する定数の定義。実行対象の条件をフィルタリングする。
# 全 jobs で利用する定数の定義。実行対象の条件をフィルタリングする。
#
# c_release_format = plain-cdylib | ios-xcframework
#
# `plain-cdylib`の場合、動的ライブラリとその付属物をZIPに固めたものをC APIとしてリリースする。
# `ios-xcframework`の場合はiOS用のXCFrameworkをC APIとしてリリースする。また、ONNX Runtimeの
# リンク方法に関わるCargoフィーチャも`c_release_format`によって選択される。
config:
runs-on: ubuntu-latest
outputs:
includes: ${{ steps.strategy_matrix.outputs.includes }}
Expand All @@ -57,6 +64,7 @@ jobs:
"features": "",
"target": "x86_64-pc-windows-msvc",
"artifact_name": "windows-x64-cpu",
"c_release_format": "plain-cdylib",
"whl_local_version": "cpu",
"can_skip_in_simple_test": true
},
Expand All @@ -65,6 +73,7 @@ jobs:
"features": "directml",
"target": "x86_64-pc-windows-msvc",
"artifact_name": "windows-x64-directml",
"c_release_format": "plain-cdylib",
"whl_local_version": "directml",
"can_skip_in_simple_test": false
},
Expand All @@ -73,6 +82,7 @@ jobs:
"features": "cuda",
"target": "x86_64-pc-windows-msvc",
"artifact_name": "windows-x64-cuda",
"c_release_format": "plain-cdylib",
"whl_local_version": "cuda",
"can_skip_in_simple_test": true
},
Expand All @@ -81,6 +91,7 @@ jobs:
"features": "",
"target": "i686-pc-windows-msvc",
"artifact_name": "windows-x86-cpu",
"c_release_format": "plain-cdylib",
"whl_local_version": "cpu",
"can_skip_in_simple_test": true
},
Expand All @@ -89,6 +100,7 @@ jobs:
"features": "",
"target": "x86_64-unknown-linux-gnu",
"artifact_name": "linux-x64-cpu",
"c_release_format": "plain-cdylib",
"whl_local_version": "cpu",
"can_skip_in_simple_test": true
},
Expand All @@ -97,6 +109,7 @@ jobs:
"features": "cuda",
"target": "x86_64-unknown-linux-gnu",
"artifact_name": "linux-x64-gpu",
"c_release_format": "plain-cdylib",
"whl_local_version": "cuda",
"can_skip_in_simple_test": false
},
Expand All @@ -105,6 +118,7 @@ jobs:
"features": "",
"target": "aarch64-unknown-linux-gnu",
"artifact_name": "linux-arm64-cpu",
"c_release_format": "plain-cdylib",
"whl_local_version": "cpu",
"can_skip_in_simple_test": true
},
Expand All @@ -113,20 +127,23 @@ jobs:
"features": "",
"target": "aarch64-linux-android",
"artifact_name": "android-arm64-cpu",
"c_release_format": "plain-cdylib",
"can_skip_in_simple_test": true
},
{
"os": "ubuntu-20.04",
"features": "",
"target": "x86_64-linux-android",
"artifact_name": "android-x86_64-cpu",
"c_release_format": "plain-cdylib",
"can_skip_in_simple_test": true
},
{
"os": "macos-12",
"features": "",
"target": "aarch64-apple-darwin",
"artifact_name": "osx-arm64-cpu",
"c_release_format": "plain-cdylib",
"whl_local_version": "cpu",
"can_skip_in_simple_test": false
},
Expand All @@ -135,6 +152,7 @@ jobs:
"features": "",
"target": "x86_64-apple-darwin",
"artifact_name": "osx-x64-cpu",
"c_release_format": "plain-cdylib",
"whl_local_version": "cpu",
"can_skip_in_simple_test": true
},
Expand All @@ -143,20 +161,23 @@ jobs:
"features": "",
"target": "aarch64-apple-ios",
"artifact_name": "ios-arm64-cpu",
"c_release_format": "ios-xcframework",
"can_skip_in_simple_test": true
},
{
"os": "macos-12",
"features": "",
"target": "aarch64-apple-ios-sim",
"artifact_name": "ios-arm64-cpu-sim",
"c_release_format": "ios-xcframework",
"can_skip_in_simple_test": true
},
{
"os": "macos-12",
"features": "",
"target": "x86_64-apple-ios",
"artifact_name": "ios-x64-cpu",
"c_release_format": "ios-xcframework",
"can_skip_in_simple_test": true
}
]'
Expand Down Expand Up @@ -244,8 +265,12 @@ jobs:
- name: build voicevox_core_c_api
shell: bash
run: |
case ${{ matrix.c_release_format }} in
plain-cdylib) linking=load-onnxruntime ;;
ios-xcframework) linking=link-onnxruntime ;;
esac
function build() {
cargo build -p voicevox_core_c_api -vv --features ${{ matrix.features }}, --target ${{ matrix.target }} --release
cargo build -p voicevox_core_c_api -vv --features "$linking",${{ matrix.features }} --target ${{ matrix.target }} --release
}
if ${{ !inputs.is_production }}; then
build
Expand Down Expand Up @@ -285,7 +310,12 @@ jobs:
- name: Organize artifact
run: |
mkdir -p "artifact/${{ env.ASSET_NAME }}"
cp -v crates/voicevox_core_c_api/include/voicevox_core.h "artifact/${{ env.ASSET_NAME }}"
case ${{ matrix.c_release_format }} in
plain-cdylib) feature=VOICEVOX_LOAD_ONNXRUNTIME ;;
ios-xcframework) feature=VOICEVOX_LINK_ONNXRUNTIME ;;
esac
sed 's:^//\(#define '"$feature"'\)$:\1:' crates/voicevox_core_c_api/include/voicevox_core.h \
> "artifact/${{ env.ASSET_NAME }}/voicevox_core.h"
cp -v target/${{ matrix.target }}/release/*voicevox_core.{dll,so,dylib} "artifact/${{ env.ASSET_NAME }}" || true
cp -v target/${{ matrix.target }}/release/voicevox_core.dll.lib "artifact/${{ env.ASSET_NAME }}/voicevox_core.lib" || true
cp -v -n target/${{ matrix.target }}/release/{,lib}onnxruntime*.{dll,so.*,so,dylib} "artifact/${{ env.ASSET_NAME }}" || true
Expand All @@ -305,7 +335,7 @@ jobs:
ESIGNERCKA_PASSWORD: ${{ secrets.ESIGNERCKA_PASSWORD }}
ESIGNERCKA_TOTP_SECRET: ${{ secrets.ESIGNERCKA_TOTP_SECRET }}
- name: Upload artifact to build XCFramework
if: contains(matrix.target, 'ios')
if: matrix.c_release_format == 'ios-xcframework'
uses: actions/upload-artifact@v4
with:
name: voicevox_core-${{ matrix.target }}
Expand All @@ -315,7 +345,7 @@ jobs:
cd artifact
7z a "../${{ env.ASSET_NAME }}.zip" "${{ env.ASSET_NAME }}"
- name: Upload to Release
if: fromJson(needs.config.outputs.deploy) && !contains(matrix.target, 'ios')
if: fromJson(needs.config.outputs.deploy) && matrix.c_release_format == 'plain-cdylib'
uses: softprops/action-gh-release@v2
with:
prerelease: true
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/generate_document.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ jobs:
with:
working-directory: "docs/apis/c_api/doxygen"
- name: Build voicevox_core_python_api
run: |
cargo build -p voicevox_core_c_api -vv
maturin develop --manifest-path ./crates/voicevox_core_python_api/Cargo.toml --locked
run: maturin develop --manifest-path ./crates/voicevox_core_python_api/Cargo.toml --locked
# https://github.com/readthedocs/sphinx-autoapi/issues/405
- name: Workaround to make Sphinx recognize `_rust` as a module
run: touch ./crates/voicevox_core_python_api/python/voicevox_core/_rust/__init__.py
Expand Down
21 changes: 14 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,10 @@ jobs:
with:
python-version: "3.8"
- uses: Swatinem/rust-cache@v2
- run: cargo clippy -vv --all-features --tests -- -D clippy::all -D warnings --no-deps
- run: cargo clippy -vv --all-features -- -D clippy::all -D warnings --no-deps
- run: cargo clippy -vv --features directml,cuda --tests -- -D clippy::all -D warnings --no-deps
- run: cargo clippy -vv --features directml,cuda -- -D clippy::all -D warnings --no-deps
- run: cargo clippy -vv -p voicevox_core -p voicevox_core_c_api --features link-onnxruntime,directml,cuda --tests -- -D clippy::all -D warnings --no-deps
- run: cargo clippy -vv -p voicevox_core -p voicevox_core_c_api --features link-onnxruntime,directml,cuda -- -D clippy::all -D warnings --no-deps
- run: cargo fmt -- --check

rust-unit-test:
Expand Down Expand Up @@ -134,7 +136,7 @@ jobs:
- uses: Swatinem/rust-cache@v2
with:
key: "cargo-integration-test-cache-${{ matrix.features }}-${{ matrix.os }}"
- name: Run cargo integration test
- name: Run cargo integration test (load-onnxruntime)
run: RUST_BACKTRACE=full cargo test --test "*" -vv --features ,${{ matrix.features }} -- --include-ignored

c-header:
Expand Down Expand Up @@ -193,11 +195,13 @@ jobs:
- name: Install cargo-binstall
uses: taiki-e/install-action@cargo-binstall
- name: build voicevox_core_c_api
run: cargo build -p voicevox_core_c_api -vv
run: cargo build -p voicevox_core_c_api --features load-onnxruntime -vv
- name: 必要なfileをunix用exampleのディレクトリに移動させる
run: |
mkdir -p example/cpp/unix/voicevox_core/
cp -v crates/voicevox_core_c_api/include/voicevox_core.h example/cpp/unix/voicevox_core/
sed 's:^//\(#define VOICEVOX_LOAD_ONNXRUNTIME\)$:\1:' \
crates/voicevox_core_c_api/include/voicevox_core.h \
> example/cpp/unix/voicevox_core/voicevox_core.h
cp -v target/debug/libvoicevox_core.{so,dylib} example/cpp/unix/voicevox_core/ || true
cp -v target/debug/libonnxruntime.so.* example/cpp/unix/voicevox_core/ || true
cp -v target/debug/libonnxruntime.*.dylib example/cpp/unix/voicevox_core/ || true
Expand Down Expand Up @@ -235,11 +239,14 @@ jobs:
- name: Install cargo-binstall
uses: taiki-e/install-action@cargo-binstall
- name: build voicevox_core_c_api
run: cargo build -p voicevox_core_c_api -vv
run: cargo build -p voicevox_core_c_api --features load-onnxruntime -vv
- name: 必要なfileをexampleのディレクトリに移動させる
shell: bash
run: |
mkdir -p example/cpp/windows/simple_tts/lib/x64
cp -v crates/voicevox_core_c_api/include/voicevox_core.h example/cpp/windows/simple_tts/
sed 's:^//\(#define VOICEVOX_LOAD_ONNXRUNTIME\)$:\1:' \
crates/voicevox_core_c_api/include/voicevox_core.h \
> example/cpp/windows/simple_tts/voicevox_core.h
cp target/debug/voicevox_core.dll.lib example/cpp/windows/simple_tts/lib/x64/voicevox_core.lib
- name: Add MSBuild to PATH
Expand Down
Loading

0 comments on commit 537d9b2

Please sign in to comment.