Skip to content

Commit

Permalink
Merge branch 'main' into add-morphing
Browse files Browse the repository at this point in the history
  • Loading branch information
qryxip committed Apr 30, 2024
2 parents cfe60f0 + e3cb7be commit c25cde9
Show file tree
Hide file tree
Showing 21 changed files with 288 additions and 687 deletions.
9 changes: 1 addition & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -282,13 +282,6 @@ jobs:
pip install --upgrade poetry
poetry install --with dev --with test
- run: cargo build -p test_util -vv # build scriptにより/crates/test_util/data/の生成
# `macos-latest`(=`macos-12`)で次の問題が発生するため、それに対するワークアラウンド
# https://github.com/VOICEVOX/voicevox_core/issues/653#issuecomment-1782108410
- if: startsWith(matrix.os, 'mac')
name: Build open_jtalk-sys
run: |
poetry run -- cargo build -p voicevox_core_python_api -vv || true
[ -n "$(find ../../target/debug/deps -name 'libopen_jtalk_sys-*.rlib')" ]
- run: poetry run maturin build --locked
- run: poetry run maturin develop --locked
- name: 必要なDLLをコピーしてpytestを実行
Expand Down Expand Up @@ -317,7 +310,7 @@ jobs:
- name: Set up Rust
uses: ./.github/actions/rust-toolchain-from-file
- name: Set up Java
uses: actions/setup-java@v2
uses: actions/setup-java@v4
with:
java-version: "11"
distribution: "adopt"
Expand Down
48 changes: 25 additions & 23 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ assert_cmd = "2.0.8"
async-std = "1.12.0"
async_zip = "=0.0.16"
az = "1.2.1"
bindgen = "0.69.4"
binstall-tar = "0.4.39"
bytes = "1.1.0"
camino = "1.1.6"
Expand Down Expand Up @@ -63,7 +64,7 @@ pyo3-asyncio = "0.20.0"
pyo3-log = "0.9.0"
quote = "1.0.33"
rayon = "1.6.1"
regex = "1.10.2"
regex = "1.10.4"
reqwest = { version = "0.11.13", default-features = false }
rstest = "0.15.0"
rstest_reuse = "0.6.0"
Expand Down Expand Up @@ -95,7 +96,7 @@ rev = "ebb9dcb9b26ee681889b52b6db3b4f642b04a250"

[workspace.dependencies.open_jtalk]
git = "https://github.com/VOICEVOX/open_jtalk-rs.git"
rev = "70c76bb54522830e92803038191bf533ba68ce85"
rev = "e1940f3fd61a48bed5bbec8cd2645e13923b1f80"

# FIXME: iOS対応のpull request(https://github.com/wesleywiser/process_path/pull/16)がマージされる見込みが無いため
[workspace.dependencies.process_path]
Expand Down
5 changes: 4 additions & 1 deletion crates/test_util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ edition.workspace = true
[dependencies]
async_zip = { workspace = true, features = ["deflate"] }
futures-lite.workspace = true
libloading.workspace = true
once_cell.workspace = true
serde = { workspace = true, features = ["derive"] }
serde_json.workspace = true
Expand All @@ -13,6 +14,8 @@ tokio = { workspace = true, features = ["fs", "io-util", "sync"] }
[build-dependencies]
anyhow.workspace = true
async-std = { workspace = true, features = ["attributes"] }
bindgen.workspace = true
camino.workspace = true
flate2.workspace = true
fs-err.workspace = true
serde = { workspace = true, features = ["derive"] }
Expand All @@ -21,5 +24,5 @@ surf.workspace = true
tar.workspace = true

[lints.rust]
unsafe_code = "forbid"
unsafe_code = "allow" # C APIのbindgen
rust_2018_idioms = "warn"
21 changes: 20 additions & 1 deletion crates/test_util/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::{

use anyhow::ensure;
use async_std::io::ReadExt as _;
use camino::Utf8PathBuf;
use flate2::read::GzDecoder;
use tar::Archive;

Expand All @@ -28,7 +29,8 @@ async fn main() -> anyhow::Result<()> {

println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=src/typing.rs");
Ok(())

generate_c_api_rs_bindings()
}

/// OpenJTalkの辞書をダウンロードして展開する。
Expand Down Expand Up @@ -120,3 +122,20 @@ fn generate_example_data_json(dist: &Path) -> anyhow::Result<()> {

Ok(())
}

fn generate_c_api_rs_bindings() -> anyhow::Result<()> {
static C_BINDINGS_PATH: &str = "../voicevox_core_c_api/include/voicevox_core.h";
static ADDITIONAL_C_BINDINGS_PATH: &str = "./compatible_engine.h";

let out_dir = Utf8PathBuf::from(env::var("OUT_DIR").unwrap());
bindgen::Builder::default()
.header(C_BINDINGS_PATH)
.header(ADDITIONAL_C_BINDINGS_PATH)
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
.dynamic_library_name("CApi")
.generate()?
.write_to_file(out_dir.join("c_api.rs"))?;
println!("cargo:rerun-if-changed={C_BINDINGS_PATH}");
println!("cargo:rerun-if-changed={ADDITIONAL_C_BINDINGS_PATH}");
Ok(())
}
28 changes: 28 additions & 0 deletions crates/test_util/compatible_engine.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <stdint.h>

bool initialize(bool use_gpu, int cpu_num_threads, bool load_all_models);

bool load_model(int64_t speaker_id);

bool is_model_loaded(int64_t speaker_id);

void finalize();

const char *metas();

const char *supported_devices();

bool yukarin_s_forward(int64_t length, int64_t *phoneme_list,
int64_t *speaker_id, float *output);

bool yukarin_sa_forward(int64_t length, int64_t *vowel_phoneme_list,
int64_t *consonant_phoneme_list,
int64_t *start_accent_list, int64_t *end_accent_list,
int64_t *start_accent_phrase_list,
int64_t *end_accent_phrase_list, int64_t *speaker_id,
float *output);

bool decode_forward(int64_t length, int64_t phoneme_size, float *f0,
float *phoneme, int64_t *speaker_id, float *output);

const char *last_error_message();
12 changes: 12 additions & 0 deletions crates/test_util/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
mod typing;

#[allow(
non_camel_case_types,
non_snake_case,
non_upper_case_globals,
unused_extern_crates,
clippy::missing_safety_doc,
clippy::too_many_arguments
)]
pub mod c_api {
include!(concat!(env!("OUT_DIR"), "/c_api.rs"));
}

use async_zip::{base::write::ZipFileWriter, Compression, ZipEntryBuilder};
use futures_lite::AsyncWriteExt as _;
use once_cell::sync::Lazy;
Expand Down
3 changes: 0 additions & 3 deletions crates/voicevox_core/src/engine/open_jtalk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,6 @@ pub(crate) mod blocking {
njd: ManagedResource<Njd>,
jpcommon: ManagedResource<JpCommon>,
}

// FIXME: open_jtalk-rs側で宣言する
unsafe impl Send for Resources {}
}

pub(crate) mod tokio {
Expand Down
1 change: 0 additions & 1 deletion crates/voicevox_core_c_api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ ndarray-stats.workspace = true
regex.workspace = true
serde = { workspace = true, features = ["derive"] }
serde_with.workspace = true
strum = { workspace = true, features = ["derive"] }
tempfile.workspace = true
test_util.workspace = true
toml.workspace = true
Expand Down
4 changes: 2 additions & 2 deletions crates/voicevox_core_c_api/tests/e2e/assert_cdylib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub(crate) fn exec<C: TestContext>() -> anyhow::Result<()> {
let exec_c_api_e2e_test = serde_json::from_str::<Box<dyn TestCase>>(&exec_c_api_e2e_test)?;

return unsafe {
let lib = &Library::new(C::cdylib_path())?;
let lib = Library::new(C::cdylib_path())?;
exec_c_api_e2e_test.exec(lib)
};
}
Expand Down Expand Up @@ -113,7 +113,7 @@ pub(crate) trait TestCase: Send {
///
/// `exec`は独立したプロセスで実行されるため、stdout/stderrへの出力をしたりグローバルな状態に
/// 依存してもよい。
unsafe fn exec(&self, lib: &Library) -> anyhow::Result<()>;
unsafe fn exec(&self, lib: Library) -> anyhow::Result<()>;

/// 別プロセスで実行された`exec`の結果をチェックする。
fn assert_output(&self, output: Utf8Output) -> AssertResult;
Expand Down
5 changes: 1 addition & 4 deletions crates/voicevox_core_c_api/tests/e2e/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@ mod assert_cdylib;
mod float_assert;
mod log_mask;
mod snapshots;
mod symbols;
mod testcases;

// voicevox_core_c_apiのcdylibを対象にテストを行う。
//
// C APIの定義を変更する場合:
// 1. symbols.rsの実装を変更する。
// 2. 1.によってコンパイルが通らなくなったら、適宜修正する。
// C APIの定義を変更した場合は、テスト実行前に`cargo xtask update-c-header`を実行すること。
//
// テストを追加する場合:
// 1. testcases/{テスト名}.rsを追加し、testcases.rsでマウントする。
Expand Down
Loading

0 comments on commit c25cde9

Please sign in to comment.