Skip to content

Commit

Permalink
version取得APIを作った
Browse files Browse the repository at this point in the history
  • Loading branch information
qwerty2501 committed Aug 29, 2022
1 parent 0172d35 commit 3abd816
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/build_and_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ jobs:
with:
target: ${{ matrix.target }}
default: true
- uses: actions-rs/[email protected]
with:
crate: set-cargo-version
version: latest
- name: set cargo version
run: set-cargo-version ./crates/voicevox_core/Cargo.toml ${{ env.VERSION }}
- name: build release
run: cargo build -p voicevox_core_c_api --features generate-c-header,${{ matrix.additional-features }} --target ${{ matrix.target }} --release
env:
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion crates/voicevox_core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "voicevox_core"
version = "0.1.0"
version = "999.999.999"
edition = "2021"

[features]
Expand Down
10 changes: 10 additions & 0 deletions crates/voicevox_core/src/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ impl VoicevoxCore {
self.synthesis_engine.inference_core_mut().finalize()
}

pub const fn get_version(&self) -> &'static str {
env!("CARGO_PKG_VERSION")
}

pub fn get_metas_json(&self) -> &'static CStr {
&METAS_CSTRING
}
Expand Down Expand Up @@ -884,4 +888,10 @@ mod tests {
assert_eq!(query.accent_phrases()[1].accent(), &1);
assert_eq!(query.kana(), "コレワ'/テ'_ストデ_ス");
}

#[rstest]
fn get_version_works() {
let core = VoicevoxCore::new_with_mutex();
assert_eq!("999.999.999", core.lock().unwrap().get_version());
}
}
11 changes: 11 additions & 0 deletions crates/voicevox_core_c_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ mod helpers;
use helpers::*;
use libc::c_void;
use once_cell::sync::Lazy;
use std::ffi::CString;
use std::ffi::{CStr, CString};
use std::os::raw::c_char;
use std::path::PathBuf;
Expand Down Expand Up @@ -68,6 +69,16 @@ pub extern "C" fn voicevox_initialize(options: VoicevoxInitializeOptions) -> Voi
}
}

static VOICEVOX_VERSION: once_cell::sync::Lazy<CString> =
once_cell::sync::Lazy::new(|| CString::new(lock_internal().get_version()).unwrap());

/// voicevoxのversionを取得する
/// @return SemVerでフォーマットされたバージョン
#[no_mangle]
pub extern "C" fn voicevox_get_version() -> *const c_char {
VOICEVOX_VERSION.as_ptr()
}

#[no_mangle]
pub extern "C" fn voicevox_load_model(speaker_id: u32) -> VoicevoxResultCode {
let result = lock_internal().load_model(speaker_id);
Expand Down

0 comments on commit 3abd816

Please sign in to comment.