Skip to content

Commit

Permalink
フィーチャをリネーム
Browse files Browse the repository at this point in the history
  • Loading branch information
qryxip committed Jun 29, 2024
1 parent 379cc44 commit b1dca9c
Show file tree
Hide file tree
Showing 18 changed files with 93 additions and 95 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ model フォルダにある onnx モデルはダミーのため、ノイズの

```bash
# DLLをビルド
cargo build --release -p voicevox_core_c_api --features onnxruntime-libloading
cargo build --release -p voicevox_core_c_api --features load-onnxruntime
```

DLL 用のヘッダファイルは [crates/voicevox_core_c_api/include/voicevox_core.h](https://github.com/VOICEVOX/voicevox_core/tree/main/crates/voicevox_core_c_api/include/voicevox_core.h) にあります。
Expand Down
4 changes: 2 additions & 2 deletions crates/test_util/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@ fn generate_c_api_rs_bindings(out_dir: &Utf8Path) -> anyhow::Result<()> {
bindgen::Builder::default()
.header(C_BINDINGS_PATH)
.header(ADDITIONAL_C_BINDINGS_PATH)
// we test for `--feature onnxruntime-libloading`
.clang_arg("-DVOICEVOX_ONNXRUNTIME_LIBLOADING=")
// we test for `--feature load-onnxruntime`
.clang_arg("-DVOICEVOX_LINK_ONNXRUNTIME=")
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
.dynamic_library_name("CApi")
.generate()?
Expand Down
10 changes: 5 additions & 5 deletions crates/voicevox_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition.workspace = true
publish.workspace = true

[package.metadata.docs.rs]
features = ["onnxruntime-libloading", "onnxruntime-link-dylib"]
features = ["load-onnxruntime", "link-onnxruntime"]
rustdoc-args = ["--cfg", "docsrs"]

[features]
Expand All @@ -14,11 +14,11 @@ default = []
# ONNX Runtimeのリンク方法を決めるフィーチャ。どちらか片方を有効化しなければならず、両方の有効化は
# 許容されない。
#
# `onnxruntime-libloading`の場合、ONNX Runtimeを`dlopen`/`LoadLibraryExW`で開く。
# `onnxruntime-link-dylib`の場合はONNX Runtimeをロード時動的リンクする。またそれに伴い、
# `load-onnxruntime`の場合、ONNX Runtimeを`dlopen`/`LoadLibraryExW`で開く。
# `link-onnxruntime`の場合はONNX Runtimeをロード時動的リンクする。またそれに伴い、
# `struct Onnxruntime`の初期化方法も異なる。
onnxruntime-libloading = ["voicevox-ort/load-dynamic"]
onnxruntime-link-dylib = []
load-onnxruntime = ["voicevox-ort/load-dynamic"]
link-onnxruntime = []

cuda = ["voicevox-ort/cuda"]
directml = ["voicevox-ort/directml"]
Expand Down
6 changes: 3 additions & 3 deletions crates/voicevox_core/src/__internal/doctest_fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ use crate::{AccelerationMode, InitializeOptions};

pub async fn synthesizer_with_sample_voice_model(
voice_model_path: impl AsRef<Path>,
#[cfg_attr(feature = "onnxruntime-link-dylib", allow(unused_variables))] onnxruntime_dylib_path: impl Into<
#[cfg_attr(feature = "link-onnxruntime", allow(unused_variables))] onnxruntime_dylib_path: impl Into<
OsString,
>,
open_jtalk_dic_dir: impl AsRef<Utf8Path>,
) -> anyhow::Result<crate::tokio::Synthesizer<crate::tokio::OpenJtalk>> {
let syntesizer = crate::tokio::Synthesizer::new(
#[cfg(feature = "onnxruntime-libloading")]
#[cfg(feature = "load-onnxruntime")]
crate::tokio::Onnxruntime::load_once()
.filename(onnxruntime_dylib_path)
.exec()
.await?,
#[cfg(feature = "onnxruntime-link-dylib")]
#[cfg(feature = "link-onnxruntime")]
crate::tokio::Onnxruntime::init_once().await?,
crate::tokio::OpenJtalk::new(open_jtalk_dic_dir).await?,
&InitializeOptions {
Expand Down
4 changes: 2 additions & 2 deletions crates/voicevox_core/src/blocking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub use crate::{
};

pub mod onnxruntime {
#[cfg(feature = "onnxruntime-libloading")]
#[cfg_attr(docsrs, doc(cfg(feature = "onnxruntime-libloading")))]
#[cfg(feature = "load-onnxruntime")]
#[cfg_attr(docsrs, doc(cfg(feature = "load-onnxruntime")))]
pub use crate::infer::runtimes::onnxruntime::blocking::LoadOnce;
}
64 changes: 32 additions & 32 deletions crates/voicevox_core/src/infer/runtimes/onnxruntime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,13 +262,13 @@ pub(crate) mod blocking {

impl Onnxruntime {
/// ONNX Runtimeのライブラリ名。
#[cfg(feature = "onnxruntime-libloading")]
#[cfg_attr(docsrs, doc(cfg(feature = "onnxruntime-libloading")))]
#[cfg(feature = "load-onnxruntime")]
#[cfg_attr(docsrs, doc(cfg(feature = "load-onnxruntime")))]
pub const LIB_NAME: &'static str = "onnxruntime";

/// 推奨されるONNX Runtimeのバージョン。
#[cfg(feature = "onnxruntime-libloading")]
#[cfg_attr(docsrs, doc(cfg(feature = "onnxruntime-libloading")))]
#[cfg(feature = "load-onnxruntime")]
#[cfg_attr(docsrs, doc(cfg(feature = "load-onnxruntime")))]
pub const LIB_VERSION: &'static str = ort::downloaded_version!();

/// [`LIB_NAME`]と[`LIB_VERSION`]からなる動的ライブラリのファイル名。
Expand All @@ -278,8 +278,8 @@ pub(crate) mod blocking {
/// [`LIB_NAME`]: Self::LIB_NAME
/// [`LIB_VERSION`]: Self::LIB_VERSION
/// [`LIB_UNVERSIONED_FILENAME`]: Self::LIB_UNVERSIONED_FILENAME
#[cfg(feature = "onnxruntime-libloading")]
#[cfg_attr(docsrs, doc(cfg(feature = "onnxruntime-libloading")))]
#[cfg(feature = "load-onnxruntime")]
#[cfg_attr(docsrs, doc(cfg(feature = "load-onnxruntime")))]
pub const LIB_VERSIONED_FILENAME: &'static str = if cfg!(target_os = "linux") {
const_format::concatcp!(
"lib",
Expand All @@ -302,8 +302,8 @@ pub(crate) mod blocking {
/// [`LIB_NAME`]からなる動的ライブラリのファイル名。
///
/// [`LIB_NAME`]: Self::LIB_NAME
#[cfg(feature = "onnxruntime-libloading")]
#[cfg_attr(docsrs, doc(cfg(feature = "onnxruntime-libloading")))]
#[cfg(feature = "load-onnxruntime")]
#[cfg_attr(docsrs, doc(cfg(feature = "load-onnxruntime")))]
pub const LIB_UNVERSIONED_FILENAME: &'static str = const_format::concatcp!(
std::env::consts::DLL_PREFIX,
Onnxruntime::LIB_NAME,
Expand Down Expand Up @@ -333,32 +333,32 @@ pub(crate) mod blocking {
/// ONNX Runtimeをロードして初期化する。
///
/// 一度成功したら、以後は引数を無視して同じ参照を返す。
#[cfg(feature = "onnxruntime-libloading")]
#[cfg_attr(docsrs, doc(cfg(feature = "onnxruntime-libloading")))]
#[cfg(feature = "load-onnxruntime")]
#[cfg_attr(docsrs, doc(cfg(feature = "load-onnxruntime")))]
pub fn load_once() -> LoadOnce {
LoadOnce::default()
}

/// ONNX Runtimeを初期化する。
///
/// 一度成功したら以後は同じ参照を返す。
#[cfg(feature = "onnxruntime-link-dylib")]
#[cfg_attr(docsrs, doc(cfg(feature = "onnxruntime-link-dylib")))]
#[cfg(feature = "link-onnxruntime")]
#[cfg_attr(docsrs, doc(cfg(feature = "link-onnxruntime")))]
pub fn init_once() -> crate::Result<&'static Self> {
Self::once(|| ort::try_init(None))
}

#[cfg(test)]
pub(crate) fn from_test_util_data() -> anyhow::Result<&'static Self> {
#[cfg(feature = "onnxruntime-libloading")]
#[cfg(feature = "load-onnxruntime")]
{
Self::load_once()
.filename(test_util::ONNXRUNTIME_DYLIB_PATH)
.exec()
.map_err(Into::into)
}

#[cfg(feature = "onnxruntime-link-dylib")]
#[cfg(feature = "link-onnxruntime")]
{
Self::init_once().map_err(Into::into)
}
Expand All @@ -371,20 +371,20 @@ pub(crate) mod blocking {
}

/// [`Onnxruntime::load_once`]のビルダー。
#[cfg(feature = "onnxruntime-libloading")]
#[cfg(feature = "load-onnxruntime")]
pub struct LoadOnce {
filename: std::ffi::OsString,
}

#[cfg(feature = "onnxruntime-libloading")]
#[cfg(feature = "load-onnxruntime")]
impl Default for LoadOnce {
fn default() -> Self {
let filename = Onnxruntime::LIB_VERSIONED_FILENAME.into();
Self { filename }
}
}

#[cfg(feature = "onnxruntime-libloading")]
#[cfg(feature = "load-onnxruntime")]
impl LoadOnce {
/// ONNX Runtimeのfilenameを指定する。
///
Expand Down Expand Up @@ -445,14 +445,14 @@ pub(crate) mod tokio {

impl Onnxruntime {
/// ONNX Runtimeのライブラリ名。
#[cfg(feature = "onnxruntime-libloading")]
#[cfg_attr(docsrs, doc(cfg(feature = "onnxruntime-libloading")))]
#[cfg(feature = "load-onnxruntime")]
#[cfg_attr(docsrs, doc(cfg(feature = "load-onnxruntime")))]
// ブロッキング版と等しいことはテストで担保
pub const LIB_NAME: &'static str = "onnxruntime";

/// 推奨されるONNX Runtimeのバージョン。
#[cfg(feature = "onnxruntime-libloading")]
#[cfg_attr(docsrs, doc(cfg(feature = "onnxruntime-libloading")))]
#[cfg(feature = "load-onnxruntime")]
#[cfg_attr(docsrs, doc(cfg(feature = "load-onnxruntime")))]
// ブロッキング版と等しいことはテストで担保
pub const LIB_VERSION: &'static str = ort::downloaded_version!();

Expand All @@ -463,16 +463,16 @@ pub(crate) mod tokio {
/// [`LIB_NAME`]: Self::LIB_NAME
/// [`LIB_VERSION`]: Self::LIB_VERSION
/// [`LIB_UNVERSIONED_FILENAME`]: Self::LIB_UNVERSIONED_FILENAME
#[cfg(feature = "onnxruntime-libloading")]
#[cfg_attr(docsrs, doc(cfg(feature = "onnxruntime-libloading")))]
#[cfg(feature = "load-onnxruntime")]
#[cfg_attr(docsrs, doc(cfg(feature = "load-onnxruntime")))]
pub const LIB_VERSIONED_FILENAME: &'static str =
super::blocking::Onnxruntime::LIB_VERSIONED_FILENAME;

/// [`LIB_NAME`]からなる動的ライブラリのファイル名。
///
/// [`LIB_NAME`]: Self::LIB_NAME
#[cfg(feature = "onnxruntime-libloading")]
#[cfg_attr(docsrs, doc(cfg(feature = "onnxruntime-libloading")))]
#[cfg(feature = "load-onnxruntime")]
#[cfg_attr(docsrs, doc(cfg(feature = "load-onnxruntime")))]
pub const LIB_UNVERSIONED_FILENAME: &'static str =
super::blocking::Onnxruntime::LIB_UNVERSIONED_FILENAME;

Expand All @@ -489,17 +489,17 @@ pub(crate) mod tokio {
/// ONNX Runtimeをロードして初期化する。
///
/// 一度成功したら、以後は引数を無視して同じ参照を返す。
#[cfg(feature = "onnxruntime-libloading")]
#[cfg_attr(docsrs, doc(cfg(feature = "onnxruntime-libloading")))]
#[cfg(feature = "load-onnxruntime")]
#[cfg_attr(docsrs, doc(cfg(feature = "load-onnxruntime")))]
pub fn load_once() -> LoadOnce {
LoadOnce::default()
}

/// ONNX Runtimeを初期化する。
///
/// 一度成功したら以後は同じ参照を返す。
#[cfg(feature = "onnxruntime-link-dylib")]
#[cfg_attr(docsrs, doc(cfg(feature = "onnxruntime-link-dylib")))]
#[cfg(feature = "link-onnxruntime")]
#[cfg_attr(docsrs, doc(cfg(feature = "link-onnxruntime")))]
pub async fn init_once() -> crate::Result<&'static Self> {
let inner = crate::task::asyncify(super::blocking::Onnxruntime::init_once).await?;
Ok(Self::from_blocking(inner))
Expand All @@ -519,11 +519,11 @@ pub(crate) mod tokio {
}

/// [`Onnxruntime::load_once`]のビルダー。
#[cfg(feature = "onnxruntime-libloading")]
#[cfg(feature = "load-onnxruntime")]
#[derive(Default)]
pub struct LoadOnce(super::blocking::LoadOnce);

#[cfg(feature = "onnxruntime-libloading")]
#[cfg(feature = "load-onnxruntime")]
impl LoadOnce {
/// ONNX Runtimeのfilenameを指定する。
///
Expand All @@ -545,7 +545,7 @@ pub(crate) mod tokio {
mod tests {
use rstest::rstest;

#[cfg(feature = "onnxruntime-libloading")]
#[cfg(feature = "load-onnxruntime")]
#[test]
fn assert_same_lib_names_and_versions() {
use pretty_assertions::assert_eq;
Expand Down
18 changes: 8 additions & 10 deletions crates/voicevox_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,25 @@

#![cfg_attr(docsrs, feature(doc_cfg))]

#[cfg(not(any(feature = "onnxruntime-libloading", feature = "onnxruntime-link-dylib")))]
compile_error!("either `onnxruntime-libloading` or `onnxruntime-link-dylib` must be enabled");
#[cfg(not(any(feature = "load-onnxruntime", feature = "link-onnxruntime")))]
compile_error!("either `load-onnxruntime` or `link-onnxruntime` must be enabled");

#[cfg(not(doc))]
const _: () = {
#[cfg(all(feature = "onnxruntime-libloading", feature = "onnxruntime-link-dylib"))]
compile_error!(
"`onnxruntime-libloading` and `onnxruntime-link-dylib` cannot be enabled at the same time",
);
#[cfg(all(feature = "load-onnxruntime", feature = "link-onnxruntime"))]
compile_error!("`load-onnxruntime` and `link-onnxruntime` cannot be enabled at the same time");

// Rust APIでvoicevox-ortを他のクレートが利用する可能性を考え、voicevox-ort側とfeatureがズレ
// ないようにする

#[cfg(feature = "onnxruntime-libloading")]
#[cfg(feature = "load-onnxruntime")]
ort::assert_load_dynamic_is_enabled!(
"when `onnxruntime-libloading` is enabled,`voicevox-ort/load-dynamic` must be also enabled",
"when `load-onnxruntime` is enabled,`voicevox-ort/load-dynamic` must be also enabled",
);

#[cfg(feature = "onnxruntime-link-dylib")]
#[cfg(feature = "link-onnxruntime")]
ort::assert_load_dynamic_is_disabled!(
"when `onnxruntime-link-dylib` is enabled,`voicevox-ort/load-dynamic` must be disabled",
"when `link-onnxruntime` is enabled,`voicevox-ort/load-dynamic` must be disabled",
);
};

Expand Down
4 changes: 2 additions & 2 deletions crates/voicevox_core/src/tokio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub use crate::{
};

pub mod onnxruntime {
#[cfg(feature = "onnxruntime-libloading")]
#[cfg_attr(docsrs, doc(cfg(feature = "onnxruntime-libloading")))]
#[cfg(feature = "load-onnxruntime")]
#[cfg_attr(docsrs, doc(cfg(feature = "load-onnxruntime")))]
pub use crate::infer::runtimes::onnxruntime::tokio::LoadOnce;
}
4 changes: 2 additions & 2 deletions crates/voicevox_core_c_api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ harness = false
name = "e2e"

[features]
onnxruntime-libloading = ["voicevox_core/onnxruntime-libloading"]
onnxruntime-link-dylib = ["voicevox_core/onnxruntime-link-dylib"]
load-onnxruntime = ["voicevox_core/load-onnxruntime"]
link-onnxruntime = ["voicevox_core/link-onnxruntime"]
cuda = ["voicevox_core/cuda"]
directml = ["voicevox_core/directml"]

Expand Down
16 changes: 8 additions & 8 deletions crates/voicevox_core_c_api/cbindgen.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ after_includes = """
#include <stdint.h>
#endif // __cplusplus
//#define VOICEVOX_ONNXRUNTIME_LIBLOADING
//#define VOICEVOX_ONNXRUNTIME_LINK_DYLIB
//#define VOICEVOX_LINK_ONNXRUNTIME
//#define VOICEVOX_LOAD_ONNXRUNTIME
#if !(defined(VOICEVOX_ONNXRUNTIME_LIBLOADING) || defined(VOICEVOX_ONNXRUNTIME_LINK_DYLIB))
#error "either `VOICEVOX_ONNXRUNTIME_LIBLOADING` or `VOICEVOX_ONNXRUNTIME_LINK_DYLIB` must be enabled"
#if !(defined(VOICEVOX_LINK_ONNXRUNTIME) || defined(VOICEVOX_LOAD_ONNXRUNTIME))
#error "either `VOICEVOX_LINK_ONNXRUNTIME` or `VOICEVOX_LOAD_ONNXRUNTIME` must be enabled"
#endif
#if defined(VOICEVOX_ONNXRUNTIME_LIBLOADING) && defined(VOICEVOX_ONNXRUNTIME_LINK_DYLIB)
#error "`VOICEVOX_ONNXRUNTIME_LIBLOADING` or `VOICEVOX_ONNXRUNTIME_LINK_DYLIB` cannot be enabled at the same time"
#if defined(VOICEVOX_LINK_ONNXRUNTIME) && defined(VOICEVOX_LOAD_ONNXRUNTIME)
#error "`VOICEVOX_LINK_ONNXRUNTIME` or `VOICEVOX_LOAD_ONNXRUNTIME` cannot be enabled at the same time"
#endif"""

# Code Style Options
Expand All @@ -91,5 +91,5 @@ parse_deps = true
include = ["voicevox_core"]

[defines]
"feature = onnxruntime-libloading" = "VOICEVOX_ONNXRUNTIME_LIBLOADING"
"feature = onnxruntime-link-dylib" = "VOICEVOX_ONNXRUNTIME_LINK_DYLIB"
"feature = load-onnxruntime" = "VOICEVOX_LINK_ONNXRUNTIME"
"feature = link-onnxruntime" = "VOICEVOX_LOAD_ONNXRUNTIME"
Loading

0 comments on commit b1dca9c

Please sign in to comment.