From 3abd816b3afbfefe77e3d95d46596bf34a2bc75c Mon Sep 17 00:00:00 2001 From: qwerty2501 <939468+qwerty2501@users.noreply.github.com> Date: Tue, 30 Aug 2022 02:10:20 +0900 Subject: [PATCH] =?UTF-8?q?version=E5=8F=96=E5=BE=97API=E3=82=92=E4=BD=9C?= =?UTF-8?q?=E3=81=A3=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build_and_deploy.yml | 6 ++++++ Cargo.lock | 2 +- crates/voicevox_core/Cargo.toml | 2 +- crates/voicevox_core/src/publish.rs | 10 ++++++++++ crates/voicevox_core_c_api/src/lib.rs | 11 +++++++++++ 5 files changed, 29 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build_and_deploy.yml b/.github/workflows/build_and_deploy.yml index c76408b12..228069357 100644 --- a/.github/workflows/build_and_deploy.yml +++ b/.github/workflows/build_and_deploy.yml @@ -76,6 +76,12 @@ jobs: with: target: ${{ matrix.target }} default: true + - uses: actions-rs/install@0.1 + 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: diff --git a/Cargo.lock b/Cargo.lock index 1641c8747..f034069ed 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2362,7 +2362,7 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "voicevox_core" -version = "0.1.0" +version = "999.999.999" dependencies = [ "anyhow", "async-std", diff --git a/crates/voicevox_core/Cargo.toml b/crates/voicevox_core/Cargo.toml index 36bae8682..4fcd589ac 100644 --- a/crates/voicevox_core/Cargo.toml +++ b/crates/voicevox_core/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "voicevox_core" -version = "0.1.0" +version = "999.999.999" edition = "2021" [features] diff --git a/crates/voicevox_core/src/publish.rs b/crates/voicevox_core/src/publish.rs index 9d92599ce..15c225bbf 100644 --- a/crates/voicevox_core/src/publish.rs +++ b/crates/voicevox_core/src/publish.rs @@ -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 } @@ -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()); + } } diff --git a/crates/voicevox_core_c_api/src/lib.rs b/crates/voicevox_core_c_api/src/lib.rs index b8a6de8c3..3fb310942 100644 --- a/crates/voicevox_core_c_api/src/lib.rs +++ b/crates/voicevox_core_c_api/src/lib.rs @@ -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; @@ -68,6 +69,16 @@ pub extern "C" fn voicevox_initialize(options: VoicevoxInitializeOptions) -> Voi } } +static VOICEVOX_VERSION: once_cell::sync::Lazy = + 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);