From 75b41204658e68c00c5e561e64c00cec3c643801 Mon Sep 17 00:00:00 2001 From: Ryo Yamashita Date: Fri, 20 Jan 2023 06:01:39 +0900 Subject: [PATCH 01/23] =?UTF-8?q?ASCI=20escape=20sequence=E3=81=AE?= =?UTF-8?q?=E5=87=BA=E5=8A=9B=E3=81=AB=E5=88=B6=E9=99=90=E3=82=92=E3=81=8B?= =?UTF-8?q?=E3=81=91=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.lock | 96 +++++++++++++++++++++++++-- crates/voicevox_core_c_api/Cargo.toml | 1 + crates/voicevox_core_c_api/src/lib.rs | 40 ++++++++--- 3 files changed, 122 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e059f86a7..2f833198a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -250,7 +250,7 @@ version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" dependencies = [ - "hermit-abi", + "hermit-abi 0.1.19", "libc", "winapi", ] @@ -810,6 +810,27 @@ dependencies = [ "termcolor", ] +[[package]] +name = "errno" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1" +dependencies = [ + "errno-dragonfly", + "libc", + "winapi", +] + +[[package]] +name = "errno-dragonfly" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" +dependencies = [ + "cc", + "libc", +] + [[package]] name = "event-listener" version = "2.5.3" @@ -844,7 +865,7 @@ dependencies = [ "cfg-if", "libc", "redox_syscall", - "windows-sys", + "windows-sys 0.36.1", ] [[package]] @@ -1092,6 +1113,15 @@ dependencies = [ "libc", ] +[[package]] +name = "hermit-abi" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" +dependencies = [ + "libc", +] + [[package]] name = "hkdf" version = "0.10.0" @@ -1230,6 +1260,28 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "io-lifetimes" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7d6c6f8c91b4b9ed43484ad1a938e393caf35960fce7f82a040497207bd8e9e" +dependencies = [ + "libc", + "windows-sys 0.42.0", +] + +[[package]] +name = "is-terminal" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28dfb6c8100ccc63462345b67d1bbc3679177c75ee4bf59bf29c8b1d110b8189" +dependencies = [ + "hermit-abi 0.2.6", + "io-lifetimes", + "rustix", + "windows-sys 0.42.0", +] + [[package]] name = "isahc" version = "0.9.14" @@ -1351,6 +1403,12 @@ dependencies = [ "cc", ] +[[package]] +name = "linux-raw-sys" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4" + [[package]] name = "lock_api" version = "0.4.9" @@ -1656,7 +1714,7 @@ dependencies = [ "libc", "redox_syscall", "smallvec", - "windows-sys", + "windows-sys 0.36.1", ] [[package]] @@ -2095,6 +2153,20 @@ dependencies = [ "semver 1.0.14", ] +[[package]] +name = "rustix" +version = "0.36.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4fdebc4b395b7fbb9ab11e462e20ed9051e7b16e42d24042c776eca0ac81b03" +dependencies = [ + "bitflags", + "errno", + "io-lifetimes", + "libc", + "linux-raw-sys", + "windows-sys 0.42.0", +] + [[package]] name = "rustls" version = "0.20.6" @@ -2120,7 +2192,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "88d6731146462ea25d9244b2ed5fd1d716d25c52e4d54aa4fb0f3c4e9854dbe2" dependencies = [ "lazy_static", - "windows-sys", + "windows-sys 0.36.1", ] [[package]] @@ -2822,6 +2894,7 @@ name = "voicevox_core_c_api" version = "0.0.0" dependencies = [ "anyhow", + "is-terminal", "libc", "once_cell", "pretty_assertions", @@ -3041,6 +3114,21 @@ dependencies = [ "windows_x86_64_msvc 0.36.1", ] +[[package]] +name = "windows-sys" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc 0.42.0", + "windows_i686_gnu 0.42.0", + "windows_i686_msvc 0.42.0", + "windows_x86_64_gnu 0.42.0", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc 0.42.0", +] + [[package]] name = "windows_aarch64_gnullvm" version = "0.42.0" diff --git a/crates/voicevox_core_c_api/Cargo.toml b/crates/voicevox_core_c_api/Cargo.toml index 285059e4e..3af537faa 100644 --- a/crates/voicevox_core_c_api/Cargo.toml +++ b/crates/voicevox_core_c_api/Cargo.toml @@ -13,6 +13,7 @@ directml = ["voicevox_core/directml"] [dependencies] voicevox_core.workspace = true +is-terminal = "0.4.2" libc = "0.2.134" once_cell.workspace = true serde_json.workspace = true diff --git a/crates/voicevox_core_c_api/src/lib.rs b/crates/voicevox_core_c_api/src/lib.rs index 7ac2b38b9..e4e74a643 100644 --- a/crates/voicevox_core_c_api/src/lib.rs +++ b/crates/voicevox_core_c_api/src/lib.rs @@ -2,13 +2,15 @@ mod compatible_engine; mod helpers; use self::helpers::*; +use is_terminal::IsTerminal; use libc::c_void; use once_cell::sync::Lazy; +use std::env; use std::ffi::{CStr, CString}; +use std::io::{self, Write}; use std::os::raw::c_char; use std::ptr::null; use std::sync::{Mutex, MutexGuard}; -use std::{env, io}; use tracing_subscriber::EnvFilter; use voicevox_core::AudioQueryModel; use voicevox_core::Result; @@ -20,16 +22,32 @@ use rstest::*; type Internal = VoicevoxCore; static INTERNAL: Lazy> = Lazy::new(|| { - let _ = tracing_subscriber::fmt() - .with_env_filter(if env::var_os(EnvFilter::DEFAULT_ENV).is_some() { - EnvFilter::from_default_env() - } else { - "error,voicevox_core=info,voicevox_core_c_api=info,onnxruntime=info".into() - }) - .with_writer(io::stderr) - .try_init(); - - Internal::new_with_mutex() + let _ = init_logger(); + return Internal::new_with_mutex(); + + fn init_logger() -> std::result::Result<(), impl Sized> { + let ansi = out().is_terminal() && env_allows_ansi(); + + tracing_subscriber::fmt() + .with_env_filter(if env::var_os(EnvFilter::DEFAULT_ENV).is_some() { + EnvFilter::from_default_env() + } else { + "error,voicevox_core=info,voicevox_core_c_api=info,onnxruntime=info".into() + }) + .with_writer(out) + .with_ansi(ansi) + .try_init() + } + + fn out() -> impl Write + IsTerminal + 'static { + io::stderr() + } + + fn env_allows_ansi() -> bool { + // https://docs.rs/termcolor/1.2.0/src/termcolor/lib.rs.html#245-291 + env::var_os("TERM").map_or(cfg!(windows), |term| term != "dumb") + && env::var_os("NO_COLOR").is_none() + } }); pub(crate) fn lock_internal() -> MutexGuard<'static, Internal> { From 8a2748f256ed48ac93fe32b5fac53f61518b590f Mon Sep 17 00:00:00 2001 From: Ryo Yamashita Date: Fri, 20 Jan 2023 06:14:30 +0900 Subject: [PATCH 02/23] =?UTF-8?q?=E4=B8=8D=E8=A6=81=E3=81=AAlifetime?= =?UTF-8?q?=E6=8C=87=E5=AE=9A=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/voicevox_core_c_api/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/voicevox_core_c_api/src/lib.rs b/crates/voicevox_core_c_api/src/lib.rs index e4e74a643..a675e4dbb 100644 --- a/crates/voicevox_core_c_api/src/lib.rs +++ b/crates/voicevox_core_c_api/src/lib.rs @@ -39,7 +39,7 @@ static INTERNAL: Lazy> = Lazy::new(|| { .try_init() } - fn out() -> impl Write + IsTerminal + 'static { + fn out() -> impl Write + IsTerminal { io::stderr() } From b32a4ab8b668811892e0e4e404cf1b816afce851 Mon Sep 17 00:00:00 2001 From: Ryo Yamashita Date: Fri, 20 Jan 2023 06:22:43 +0900 Subject: [PATCH 03/23] =?UTF-8?q?`ansi`=E3=82=92=E3=82=A4=E3=83=B3?= =?UTF-8?q?=E3=83=A9=E3=82=A4=E3=83=B3=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/voicevox_core_c_api/src/lib.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/crates/voicevox_core_c_api/src/lib.rs b/crates/voicevox_core_c_api/src/lib.rs index a675e4dbb..369752416 100644 --- a/crates/voicevox_core_c_api/src/lib.rs +++ b/crates/voicevox_core_c_api/src/lib.rs @@ -26,8 +26,6 @@ static INTERNAL: Lazy> = Lazy::new(|| { return Internal::new_with_mutex(); fn init_logger() -> std::result::Result<(), impl Sized> { - let ansi = out().is_terminal() && env_allows_ansi(); - tracing_subscriber::fmt() .with_env_filter(if env::var_os(EnvFilter::DEFAULT_ENV).is_some() { EnvFilter::from_default_env() @@ -35,7 +33,7 @@ static INTERNAL: Lazy> = Lazy::new(|| { "error,voicevox_core=info,voicevox_core_c_api=info,onnxruntime=info".into() }) .with_writer(out) - .with_ansi(ansi) + .with_ansi(out().is_terminal() && env_allows_ansi()) .try_init() } From 7495a27906ab805a493d2305404169ec9363655d Mon Sep 17 00:00:00 2001 From: Ryo Yamashita Date: Fri, 20 Jan 2023 06:24:20 +0900 Subject: [PATCH 04/23] =?UTF-8?q?=E9=A0=86=E7=95=AA=E3=81=AE=E5=85=A5?= =?UTF-8?q?=E3=82=8C=E6=9B=BF=E3=81=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/voicevox_core_c_api/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/voicevox_core_c_api/src/lib.rs b/crates/voicevox_core_c_api/src/lib.rs index 369752416..458eac12d 100644 --- a/crates/voicevox_core_c_api/src/lib.rs +++ b/crates/voicevox_core_c_api/src/lib.rs @@ -32,12 +32,12 @@ static INTERNAL: Lazy> = Lazy::new(|| { } else { "error,voicevox_core=info,voicevox_core_c_api=info,onnxruntime=info".into() }) - .with_writer(out) .with_ansi(out().is_terminal() && env_allows_ansi()) + .with_writer(out) .try_init() } - fn out() -> impl Write + IsTerminal { + fn out() -> impl IsTerminal + Write { io::stderr() } From 9036eb4a6f8927e87ab8576eae7507f55d09379d Mon Sep 17 00:00:00 2001 From: Ryo Yamashita Date: Fri, 20 Jan 2023 08:56:51 +0900 Subject: [PATCH 05/23] =?UTF-8?q?`ENABLE=5FVIRTUAL=5FTERMINAL=5FPROCESSING?= =?UTF-8?q?`=E3=82=92=E5=95=8F=E3=81=84=E5=90=88=E3=82=8F=E3=81=9B?= =?UTF-8?q?=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/voicevox_core_c_api/src/lib.rs | 32 +++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/crates/voicevox_core_c_api/src/lib.rs b/crates/voicevox_core_c_api/src/lib.rs index 458eac12d..a6b09c1f6 100644 --- a/crates/voicevox_core_c_api/src/lib.rs +++ b/crates/voicevox_core_c_api/src/lib.rs @@ -8,6 +8,7 @@ use once_cell::sync::Lazy; use std::env; use std::ffi::{CStr, CString}; use std::io::{self, Write}; +use std::os::fd::AsRawFd; use std::os::raw::c_char; use std::ptr::null; use std::sync::{Mutex, MutexGuard}; @@ -32,15 +33,42 @@ static INTERNAL: Lazy> = Lazy::new(|| { } else { "error,voicevox_core=info,voicevox_core_c_api=info,onnxruntime=info".into() }) - .with_ansi(out().is_terminal() && env_allows_ansi()) + .with_ansi( + virtual_terminal_processing_enabled() && out().is_terminal() && env_allows_ansi(), + ) .with_writer(out) .try_init() } - fn out() -> impl IsTerminal + Write { + fn out() -> impl AsRawFd + IsTerminal + Write { io::stderr() } + #[cfg(windows)] + fn virtual_terminal_processing_enabled() -> bool { + use std::ptr; + + use windows::Win32::{ + Foundation::HANDLE, + System::Console::{GetConsoleMode, CONSOLE_MODE}, + }; + + #[allow(unsafe_code)] + return unsafe { + let mut mode = CONSOLE_MODE::default(); + let result = GetConsoleMode(HANDLE(out().as_raw_fd() as _), ptr::addr_of!(mode)); + result + && mode & ENABLE_VIRTUAL_TERMINAL_PROCESSING == ENABLE_VIRTUAL_TERMINAL_PROCESSING + }; + + const ENABLE_VIRTUAL_TERMINAL_PROCESSING: CONSOLE_MODE = CONSOLE_MODE(0x0004); + } + + #[cfg(not(windows))] + fn virtual_terminal_processing_enabled() -> bool { + true + } + fn env_allows_ansi() -> bool { // https://docs.rs/termcolor/1.2.0/src/termcolor/lib.rs.html#245-291 env::var_os("TERM").map_or(cfg!(windows), |term| term != "dumb") From b9393a8de9a580c3292cf6f0cf529aaa51cbb6e1 Mon Sep 17 00:00:00 2001 From: Ryo Yamashita Date: Fri, 20 Jan 2023 09:00:55 +0900 Subject: [PATCH 06/23] =?UTF-8?q?`dependencies`=E3=81=B8=E3=81=AE=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0=E3=81=8C=E6=8A=9C=E3=81=91=E3=81=A6=E3=81=84=E3=81=9F?= =?UTF-8?q?=E3=81=AE=E3=81=A7=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.lock | 1 + Cargo.toml | 1 + crates/voicevox_core/Cargo.toml | 2 +- crates/voicevox_core_c_api/Cargo.toml | 3 +++ 4 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 2f833198a..e32857c7a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2903,6 +2903,7 @@ dependencies = [ "thiserror", "tracing-subscriber", "voicevox_core", + "windows", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 222cbeb96..3b3867e27 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,6 +20,7 @@ serde_json = "1.0.85" thiserror = "1.0.37" tracing = { version = "0.1.37", features = ["log"] } voicevox_core = { path = "crates/voicevox_core" } +windows = { version = "0.43.0", features = ["Win32_Foundation", "Win32_Graphics_Dxgi"] } # min-sized-rustを元にrelease buildのサイズが小さくなるようにした # https://github.com/johnthagen/min-sized-rust diff --git a/crates/voicevox_core/Cargo.toml b/crates/voicevox_core/Cargo.toml index b558004d7..2f74c11e4 100644 --- a/crates/voicevox_core/Cargo.toml +++ b/crates/voicevox_core/Cargo.toml @@ -37,4 +37,4 @@ heck = "0.4.0" [target."cfg(windows)".dependencies] humansize = "2.1.2" -windows = { version = "0.43.0", features = ["Win32_Foundation", "Win32_Graphics_Dxgi"] } +windows.workspace = true diff --git a/crates/voicevox_core_c_api/Cargo.toml b/crates/voicevox_core_c_api/Cargo.toml index 3af537faa..0d1a27d06 100644 --- a/crates/voicevox_core_c_api/Cargo.toml +++ b/crates/voicevox_core_c_api/Cargo.toml @@ -24,3 +24,6 @@ tracing-subscriber = { version = "0.3.16", features = ["env-filter"] } pretty_assertions = "1.3.0" anyhow.workspace = true rstest = "0.15.0" + +[target."cfg(windows)".dependencies] +windows.workspace = true From 30a19aa9c2d14153088418f734294faed15f4861 Mon Sep 17 00:00:00 2001 From: Ryo Yamashita Date: Fri, 20 Jan 2023 09:24:32 +0900 Subject: [PATCH 07/23] =?UTF-8?q?`windows/Win32=5FSystem=5FConsole`?= =?UTF-8?q?=E3=82=92=E6=9C=89=E5=8A=B9=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 3b3867e27..5f705c59f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,7 @@ serde_json = "1.0.85" thiserror = "1.0.37" tracing = { version = "0.1.37", features = ["log"] } voicevox_core = { path = "crates/voicevox_core" } -windows = { version = "0.43.0", features = ["Win32_Foundation", "Win32_Graphics_Dxgi"] } +windows = { version = "0.43.0", features = ["Win32_Foundation", "Win32_Graphics_Dxgi", "Win32_System_Console"] } # min-sized-rustを元にrelease buildのサイズが小さくなるようにした # https://github.com/johnthagen/min-sized-rust From 66e3acf8cda0e3407f567506db9ad9f4de40adb0 Mon Sep 17 00:00:00 2001 From: Ryo Yamashita Date: Fri, 20 Jan 2023 09:24:53 +0900 Subject: [PATCH 08/23] =?UTF-8?q?`AsRawhandle`=E3=82=92=E4=BD=BF=E3=81=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/voicevox_core_c_api/src/lib.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/crates/voicevox_core_c_api/src/lib.rs b/crates/voicevox_core_c_api/src/lib.rs index a6b09c1f6..e29b63f07 100644 --- a/crates/voicevox_core_c_api/src/lib.rs +++ b/crates/voicevox_core_c_api/src/lib.rs @@ -40,10 +40,22 @@ static INTERNAL: Lazy> = Lazy::new(|| { .try_init() } - fn out() -> impl AsRawFd + IsTerminal + Write { + fn out() -> impl AsWindowsRawHandle + IsTerminal + Write { io::stderr() } + #[cfg(windows)] + trait AsWindowsRawHandle: std::os::windows::io::AsRawHandle {} + + #[cfg(windows)] + impl AsWindowsRawHandle for H {} + + #[cfg(not(windows))] + trait AsWindowsRawHandle {} + + #[cfg(not(windows))] + impl AsWindowsRawHandle for T {} + #[cfg(windows)] fn virtual_terminal_processing_enabled() -> bool { use std::ptr; @@ -56,7 +68,7 @@ static INTERNAL: Lazy> = Lazy::new(|| { #[allow(unsafe_code)] return unsafe { let mut mode = CONSOLE_MODE::default(); - let result = GetConsoleMode(HANDLE(out().as_raw_fd() as _), ptr::addr_of!(mode)); + let result = GetConsoleMode(HANDLE(out().as_raw_handle() as _), ptr::addr_of!(mode)); result && mode & ENABLE_VIRTUAL_TERMINAL_PROCESSING == ENABLE_VIRTUAL_TERMINAL_PROCESSING }; From 978334dcbbcca817265af7ef6f019a2e41df8d72 Mon Sep 17 00:00:00 2001 From: Ryo Yamashita Date: Fri, 20 Jan 2023 09:33:51 +0900 Subject: [PATCH 09/23] =?UTF-8?q?`bool`=E3=81=98=E3=82=83=E3=81=AA?= =?UTF-8?q?=E3=81=8F=E3=81=A6`BOOL`=E3=81=AA=E3=81=AE=E3=81=A7`Into`?= =?UTF-8?q?=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/voicevox_core_c_api/src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/voicevox_core_c_api/src/lib.rs b/crates/voicevox_core_c_api/src/lib.rs index e29b63f07..c3be94870 100644 --- a/crates/voicevox_core_c_api/src/lib.rs +++ b/crates/voicevox_core_c_api/src/lib.rs @@ -66,12 +66,12 @@ static INTERNAL: Lazy> = Lazy::new(|| { }; #[allow(unsafe_code)] - return unsafe { + let result = unsafe { let mut mode = CONSOLE_MODE::default(); - let result = GetConsoleMode(HANDLE(out().as_raw_handle() as _), ptr::addr_of!(mode)); - result - && mode & ENABLE_VIRTUAL_TERMINAL_PROCESSING == ENABLE_VIRTUAL_TERMINAL_PROCESSING + GetConsoleMode(HANDLE(out().as_raw_handle() as _), ptr::addr_of!(mode)).into() }; + return result + && mode & ENABLE_VIRTUAL_TERMINAL_PROCESSING == ENABLE_VIRTUAL_TERMINAL_PROCESSING; const ENABLE_VIRTUAL_TERMINAL_PROCESSING: CONSOLE_MODE = CONSOLE_MODE(0x0004); } From ded168a2c9f6d16afaaa953b43376d4941734cfa Mon Sep 17 00:00:00 2001 From: Ryo Yamashita Date: Fri, 20 Jan 2023 09:34:43 +0900 Subject: [PATCH 10/23] Remove dead code --- crates/voicevox_core_c_api/src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/voicevox_core_c_api/src/lib.rs b/crates/voicevox_core_c_api/src/lib.rs index c3be94870..9acb59d9a 100644 --- a/crates/voicevox_core_c_api/src/lib.rs +++ b/crates/voicevox_core_c_api/src/lib.rs @@ -8,7 +8,6 @@ use once_cell::sync::Lazy; use std::env; use std::ffi::{CStr, CString}; use std::io::{self, Write}; -use std::os::fd::AsRawFd; use std::os::raw::c_char; use std::ptr::null; use std::sync::{Mutex, MutexGuard}; From 27b9288a180c53e0deac3534717fbd68d95ae0f0 Mon Sep 17 00:00:00 2001 From: Ryo Yamashita Date: Fri, 20 Jan 2023 09:35:23 +0900 Subject: [PATCH 11/23] =?UTF-8?q?`addr=5Fof!`=20=E2=86=92=20`addr=5Fof=5Fm?= =?UTF-8?q?ut!`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/voicevox_core_c_api/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/voicevox_core_c_api/src/lib.rs b/crates/voicevox_core_c_api/src/lib.rs index 9acb59d9a..90b33300d 100644 --- a/crates/voicevox_core_c_api/src/lib.rs +++ b/crates/voicevox_core_c_api/src/lib.rs @@ -67,7 +67,7 @@ static INTERNAL: Lazy> = Lazy::new(|| { #[allow(unsafe_code)] let result = unsafe { let mut mode = CONSOLE_MODE::default(); - GetConsoleMode(HANDLE(out().as_raw_handle() as _), ptr::addr_of!(mode)).into() + GetConsoleMode(HANDLE(out().as_raw_handle() as _), ptr::addr_of_mut!(mode)).into() }; return result && mode & ENABLE_VIRTUAL_TERMINAL_PROCESSING == ENABLE_VIRTUAL_TERMINAL_PROCESSING; From 4b3d48e571ac2e40ac65eba463f780503b63cde9 Mon Sep 17 00:00:00 2001 From: Ryo Yamashita Date: Fri, 20 Jan 2023 09:36:26 +0900 Subject: [PATCH 12/23] =?UTF-8?q?=E3=83=88=E3=83=AC=E3=82=A4=E3=83=88?= =?UTF-8?q?=E3=82=92use=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/voicevox_core_c_api/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/voicevox_core_c_api/src/lib.rs b/crates/voicevox_core_c_api/src/lib.rs index 90b33300d..7fcfeb2df 100644 --- a/crates/voicevox_core_c_api/src/lib.rs +++ b/crates/voicevox_core_c_api/src/lib.rs @@ -57,7 +57,7 @@ static INTERNAL: Lazy> = Lazy::new(|| { #[cfg(windows)] fn virtual_terminal_processing_enabled() -> bool { - use std::ptr; + use std::{os::windows::io::AsRawHandle as _, ptr}; use windows::Win32::{ Foundation::HANDLE, From b1a0ca395582986f78aa9cf0c7af8ec94532c989 Mon Sep 17 00:00:00 2001 From: Ryo Yamashita Date: Fri, 20 Jan 2023 09:38:42 +0900 Subject: [PATCH 13/23] =?UTF-8?q?`mode`=E3=82=82=E5=BF=85=E8=A6=81?= =?UTF-8?q?=E3=81=A0=E3=81=A3=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/voicevox_core_c_api/src/lib.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/voicevox_core_c_api/src/lib.rs b/crates/voicevox_core_c_api/src/lib.rs index 7fcfeb2df..8b9fe226a 100644 --- a/crates/voicevox_core_c_api/src/lib.rs +++ b/crates/voicevox_core_c_api/src/lib.rs @@ -65,9 +65,11 @@ static INTERNAL: Lazy> = Lazy::new(|| { }; #[allow(unsafe_code)] - let result = unsafe { + let (result, mode) = unsafe { let mut mode = CONSOLE_MODE::default(); - GetConsoleMode(HANDLE(out().as_raw_handle() as _), ptr::addr_of_mut!(mode)).into() + let result = + GetConsoleMode(HANDLE(out().as_raw_handle() as _), ptr::addr_of_mut!(mode)).into(); + (result, mode) }; return result && mode & ENABLE_VIRTUAL_TERMINAL_PROCESSING == ENABLE_VIRTUAL_TERMINAL_PROCESSING; From 66f4854ab5fd02e5172e8d2dc4fb1063dc1dc8a5 Mon Sep 17 00:00:00 2001 From: Ryo Yamashita Date: Thu, 26 Jan 2023 23:06:35 +0900 Subject: [PATCH 14/23] =?UTF-8?q?Revert=20"`mode`=E3=82=82=E5=BF=85?= =?UTF-8?q?=E8=A6=81=E3=81=A0=E3=81=A3=E3=81=9F"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit b1a0ca395582986f78aa9cf0c7af8ec94532c989. --- crates/voicevox_core_c_api/src/lib.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/crates/voicevox_core_c_api/src/lib.rs b/crates/voicevox_core_c_api/src/lib.rs index 8b9fe226a..7fcfeb2df 100644 --- a/crates/voicevox_core_c_api/src/lib.rs +++ b/crates/voicevox_core_c_api/src/lib.rs @@ -65,11 +65,9 @@ static INTERNAL: Lazy> = Lazy::new(|| { }; #[allow(unsafe_code)] - let (result, mode) = unsafe { + let result = unsafe { let mut mode = CONSOLE_MODE::default(); - let result = - GetConsoleMode(HANDLE(out().as_raw_handle() as _), ptr::addr_of_mut!(mode)).into(); - (result, mode) + GetConsoleMode(HANDLE(out().as_raw_handle() as _), ptr::addr_of_mut!(mode)).into() }; return result && mode & ENABLE_VIRTUAL_TERMINAL_PROCESSING == ENABLE_VIRTUAL_TERMINAL_PROCESSING; From 8e7f43d6ada165287c8858dc3bd89767a394f666 Mon Sep 17 00:00:00 2001 From: Ryo Yamashita Date: Thu, 26 Jan 2023 23:06:49 +0900 Subject: [PATCH 15/23] =?UTF-8?q?Revert=20"=E3=83=88=E3=83=AC=E3=82=A4?= =?UTF-8?q?=E3=83=88=E3=82=92use=E3=81=99=E3=82=8B"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 4b3d48e571ac2e40ac65eba463f780503b63cde9. --- crates/voicevox_core_c_api/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/voicevox_core_c_api/src/lib.rs b/crates/voicevox_core_c_api/src/lib.rs index 7fcfeb2df..90b33300d 100644 --- a/crates/voicevox_core_c_api/src/lib.rs +++ b/crates/voicevox_core_c_api/src/lib.rs @@ -57,7 +57,7 @@ static INTERNAL: Lazy> = Lazy::new(|| { #[cfg(windows)] fn virtual_terminal_processing_enabled() -> bool { - use std::{os::windows::io::AsRawHandle as _, ptr}; + use std::ptr; use windows::Win32::{ Foundation::HANDLE, From 068f161ac4ac4c4c61b5d2ad8610ca3052adb142 Mon Sep 17 00:00:00 2001 From: Ryo Yamashita Date: Thu, 26 Jan 2023 23:06:51 +0900 Subject: [PATCH 16/23] =?UTF-8?q?Revert=20"`addr=5Fof!`=20=E2=86=92=20`add?= =?UTF-8?q?r=5Fof=5Fmut!`"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 27b9288a180c53e0deac3534717fbd68d95ae0f0. --- crates/voicevox_core_c_api/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/voicevox_core_c_api/src/lib.rs b/crates/voicevox_core_c_api/src/lib.rs index 90b33300d..9acb59d9a 100644 --- a/crates/voicevox_core_c_api/src/lib.rs +++ b/crates/voicevox_core_c_api/src/lib.rs @@ -67,7 +67,7 @@ static INTERNAL: Lazy> = Lazy::new(|| { #[allow(unsafe_code)] let result = unsafe { let mut mode = CONSOLE_MODE::default(); - GetConsoleMode(HANDLE(out().as_raw_handle() as _), ptr::addr_of_mut!(mode)).into() + GetConsoleMode(HANDLE(out().as_raw_handle() as _), ptr::addr_of!(mode)).into() }; return result && mode & ENABLE_VIRTUAL_TERMINAL_PROCESSING == ENABLE_VIRTUAL_TERMINAL_PROCESSING; From 31474140e5ae7d7ddf53d65ba39dbc970046e9b7 Mon Sep 17 00:00:00 2001 From: Ryo Yamashita Date: Thu, 26 Jan 2023 23:06:52 +0900 Subject: [PATCH 17/23] Revert "Remove dead code" This reverts commit ded168a2c9f6d16afaaa953b43376d4941734cfa. --- crates/voicevox_core_c_api/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/voicevox_core_c_api/src/lib.rs b/crates/voicevox_core_c_api/src/lib.rs index 9acb59d9a..c3be94870 100644 --- a/crates/voicevox_core_c_api/src/lib.rs +++ b/crates/voicevox_core_c_api/src/lib.rs @@ -8,6 +8,7 @@ use once_cell::sync::Lazy; use std::env; use std::ffi::{CStr, CString}; use std::io::{self, Write}; +use std::os::fd::AsRawFd; use std::os::raw::c_char; use std::ptr::null; use std::sync::{Mutex, MutexGuard}; From 4d9da6ba88591967fe38be67efe0b08567f75a33 Mon Sep 17 00:00:00 2001 From: Ryo Yamashita Date: Thu, 26 Jan 2023 23:06:54 +0900 Subject: [PATCH 18/23] =?UTF-8?q?Revert=20"`bool`=E3=81=98=E3=82=83?= =?UTF-8?q?=E3=81=AA=E3=81=8F=E3=81=A6`BOOL`=E3=81=AA=E3=81=AE=E3=81=A7`In?= =?UTF-8?q?to`=E3=81=99=E3=82=8B"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 978334dcbbcca817265af7ef6f019a2e41df8d72. --- crates/voicevox_core_c_api/src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/voicevox_core_c_api/src/lib.rs b/crates/voicevox_core_c_api/src/lib.rs index c3be94870..e29b63f07 100644 --- a/crates/voicevox_core_c_api/src/lib.rs +++ b/crates/voicevox_core_c_api/src/lib.rs @@ -66,12 +66,12 @@ static INTERNAL: Lazy> = Lazy::new(|| { }; #[allow(unsafe_code)] - let result = unsafe { + return unsafe { let mut mode = CONSOLE_MODE::default(); - GetConsoleMode(HANDLE(out().as_raw_handle() as _), ptr::addr_of!(mode)).into() + let result = GetConsoleMode(HANDLE(out().as_raw_handle() as _), ptr::addr_of!(mode)); + result + && mode & ENABLE_VIRTUAL_TERMINAL_PROCESSING == ENABLE_VIRTUAL_TERMINAL_PROCESSING }; - return result - && mode & ENABLE_VIRTUAL_TERMINAL_PROCESSING == ENABLE_VIRTUAL_TERMINAL_PROCESSING; const ENABLE_VIRTUAL_TERMINAL_PROCESSING: CONSOLE_MODE = CONSOLE_MODE(0x0004); } From 08d0021980f24ab55041c5b3a735b289d4b86b1d Mon Sep 17 00:00:00 2001 From: Ryo Yamashita Date: Thu, 26 Jan 2023 23:06:55 +0900 Subject: [PATCH 19/23] =?UTF-8?q?Revert=20"`AsRawhandle`=E3=82=92=E4=BD=BF?= =?UTF-8?q?=E3=81=86"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 66e3acf8cda0e3407f567506db9ad9f4de40adb0. --- crates/voicevox_core_c_api/src/lib.rs | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/crates/voicevox_core_c_api/src/lib.rs b/crates/voicevox_core_c_api/src/lib.rs index e29b63f07..a6b09c1f6 100644 --- a/crates/voicevox_core_c_api/src/lib.rs +++ b/crates/voicevox_core_c_api/src/lib.rs @@ -40,22 +40,10 @@ static INTERNAL: Lazy> = Lazy::new(|| { .try_init() } - fn out() -> impl AsWindowsRawHandle + IsTerminal + Write { + fn out() -> impl AsRawFd + IsTerminal + Write { io::stderr() } - #[cfg(windows)] - trait AsWindowsRawHandle: std::os::windows::io::AsRawHandle {} - - #[cfg(windows)] - impl AsWindowsRawHandle for H {} - - #[cfg(not(windows))] - trait AsWindowsRawHandle {} - - #[cfg(not(windows))] - impl AsWindowsRawHandle for T {} - #[cfg(windows)] fn virtual_terminal_processing_enabled() -> bool { use std::ptr; @@ -68,7 +56,7 @@ static INTERNAL: Lazy> = Lazy::new(|| { #[allow(unsafe_code)] return unsafe { let mut mode = CONSOLE_MODE::default(); - let result = GetConsoleMode(HANDLE(out().as_raw_handle() as _), ptr::addr_of!(mode)); + let result = GetConsoleMode(HANDLE(out().as_raw_fd() as _), ptr::addr_of!(mode)); result && mode & ENABLE_VIRTUAL_TERMINAL_PROCESSING == ENABLE_VIRTUAL_TERMINAL_PROCESSING }; From bd7e219672c8a995a4e419b75bee995e4e6b27dc Mon Sep 17 00:00:00 2001 From: Ryo Yamashita Date: Thu, 26 Jan 2023 23:06:57 +0900 Subject: [PATCH 20/23] =?UTF-8?q?Revert=20"`windows/Win32=5FSystem=5FConso?= =?UTF-8?q?le`=E3=82=92=E6=9C=89=E5=8A=B9=E5=8C=96"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 30a19aa9c2d14153088418f734294faed15f4861. --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 5f705c59f..3b3867e27 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,7 @@ serde_json = "1.0.85" thiserror = "1.0.37" tracing = { version = "0.1.37", features = ["log"] } voicevox_core = { path = "crates/voicevox_core" } -windows = { version = "0.43.0", features = ["Win32_Foundation", "Win32_Graphics_Dxgi", "Win32_System_Console"] } +windows = { version = "0.43.0", features = ["Win32_Foundation", "Win32_Graphics_Dxgi"] } # min-sized-rustを元にrelease buildのサイズが小さくなるようにした # https://github.com/johnthagen/min-sized-rust From 211731125dd1f59a72a2393c2c2139642cbb08e5 Mon Sep 17 00:00:00 2001 From: Ryo Yamashita Date: Thu, 26 Jan 2023 23:06:58 +0900 Subject: [PATCH 21/23] =?UTF-8?q?Revert=20"`dependencies`=E3=81=B8?= =?UTF-8?q?=E3=81=AE=E8=BF=BD=E5=8A=A0=E3=81=8C=E6=8A=9C=E3=81=91=E3=81=A6?= =?UTF-8?q?=E3=81=84=E3=81=9F=E3=81=AE=E3=81=A7=E8=BF=BD=E5=8A=A0"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit b9393a8de9a580c3292cf6f0cf529aaa51cbb6e1. --- Cargo.lock | 1 - Cargo.toml | 1 - crates/voicevox_core/Cargo.toml | 2 +- crates/voicevox_core_c_api/Cargo.toml | 3 --- 4 files changed, 1 insertion(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e32857c7a..2f833198a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2903,7 +2903,6 @@ dependencies = [ "thiserror", "tracing-subscriber", "voicevox_core", - "windows", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 3b3867e27..222cbeb96 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,6 @@ serde_json = "1.0.85" thiserror = "1.0.37" tracing = { version = "0.1.37", features = ["log"] } voicevox_core = { path = "crates/voicevox_core" } -windows = { version = "0.43.0", features = ["Win32_Foundation", "Win32_Graphics_Dxgi"] } # min-sized-rustを元にrelease buildのサイズが小さくなるようにした # https://github.com/johnthagen/min-sized-rust diff --git a/crates/voicevox_core/Cargo.toml b/crates/voicevox_core/Cargo.toml index 2f74c11e4..b558004d7 100644 --- a/crates/voicevox_core/Cargo.toml +++ b/crates/voicevox_core/Cargo.toml @@ -37,4 +37,4 @@ heck = "0.4.0" [target."cfg(windows)".dependencies] humansize = "2.1.2" -windows.workspace = true +windows = { version = "0.43.0", features = ["Win32_Foundation", "Win32_Graphics_Dxgi"] } diff --git a/crates/voicevox_core_c_api/Cargo.toml b/crates/voicevox_core_c_api/Cargo.toml index 0d1a27d06..3af537faa 100644 --- a/crates/voicevox_core_c_api/Cargo.toml +++ b/crates/voicevox_core_c_api/Cargo.toml @@ -24,6 +24,3 @@ tracing-subscriber = { version = "0.3.16", features = ["env-filter"] } pretty_assertions = "1.3.0" anyhow.workspace = true rstest = "0.15.0" - -[target."cfg(windows)".dependencies] -windows.workspace = true From 8ca51d217cd9168ea4cad12db6ae7c245ac680f4 Mon Sep 17 00:00:00 2001 From: Ryo Yamashita Date: Thu, 26 Jan 2023 23:06:59 +0900 Subject: [PATCH 22/23] =?UTF-8?q?Revert=20"`ENABLE=5FVIRTUAL=5FTERMINAL=5F?= =?UTF-8?q?PROCESSING`=E3=82=92=E5=95=8F=E3=81=84=E5=90=88=E3=82=8F?= =?UTF-8?q?=E3=81=9B=E3=82=8B"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 9036eb4a6f8927e87ab8576eae7507f55d09379d. --- crates/voicevox_core_c_api/src/lib.rs | 32 ++------------------------- 1 file changed, 2 insertions(+), 30 deletions(-) diff --git a/crates/voicevox_core_c_api/src/lib.rs b/crates/voicevox_core_c_api/src/lib.rs index a6b09c1f6..458eac12d 100644 --- a/crates/voicevox_core_c_api/src/lib.rs +++ b/crates/voicevox_core_c_api/src/lib.rs @@ -8,7 +8,6 @@ use once_cell::sync::Lazy; use std::env; use std::ffi::{CStr, CString}; use std::io::{self, Write}; -use std::os::fd::AsRawFd; use std::os::raw::c_char; use std::ptr::null; use std::sync::{Mutex, MutexGuard}; @@ -33,42 +32,15 @@ static INTERNAL: Lazy> = Lazy::new(|| { } else { "error,voicevox_core=info,voicevox_core_c_api=info,onnxruntime=info".into() }) - .with_ansi( - virtual_terminal_processing_enabled() && out().is_terminal() && env_allows_ansi(), - ) + .with_ansi(out().is_terminal() && env_allows_ansi()) .with_writer(out) .try_init() } - fn out() -> impl AsRawFd + IsTerminal + Write { + fn out() -> impl IsTerminal + Write { io::stderr() } - #[cfg(windows)] - fn virtual_terminal_processing_enabled() -> bool { - use std::ptr; - - use windows::Win32::{ - Foundation::HANDLE, - System::Console::{GetConsoleMode, CONSOLE_MODE}, - }; - - #[allow(unsafe_code)] - return unsafe { - let mut mode = CONSOLE_MODE::default(); - let result = GetConsoleMode(HANDLE(out().as_raw_fd() as _), ptr::addr_of!(mode)); - result - && mode & ENABLE_VIRTUAL_TERMINAL_PROCESSING == ENABLE_VIRTUAL_TERMINAL_PROCESSING - }; - - const ENABLE_VIRTUAL_TERMINAL_PROCESSING: CONSOLE_MODE = CONSOLE_MODE(0x0004); - } - - #[cfg(not(windows))] - fn virtual_terminal_processing_enabled() -> bool { - true - } - fn env_allows_ansi() -> bool { // https://docs.rs/termcolor/1.2.0/src/termcolor/lib.rs.html#245-291 env::var_os("TERM").map_or(cfg!(windows), |term| term != "dumb") From d0015a9d7137bd63be56f4119e8d75501a8add86 Mon Sep 17 00:00:00 2001 From: Ryo Yamashita Date: Thu, 26 Jan 2023 23:18:38 +0900 Subject: [PATCH 23/23] =?UTF-8?q?PowerShell=E3=81=A3=E3=81=BD=E3=81=8B?= =?UTF-8?q?=E3=81=A3=E3=81=9F=E3=82=89=E8=A8=B1=E5=8F=AF=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/voicevox_core_c_api/src/lib.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/crates/voicevox_core_c_api/src/lib.rs b/crates/voicevox_core_c_api/src/lib.rs index 458eac12d..195f510ba 100644 --- a/crates/voicevox_core_c_api/src/lib.rs +++ b/crates/voicevox_core_c_api/src/lib.rs @@ -43,8 +43,13 @@ static INTERNAL: Lazy> = Lazy::new(|| { fn env_allows_ansi() -> bool { // https://docs.rs/termcolor/1.2.0/src/termcolor/lib.rs.html#245-291 - env::var_os("TERM").map_or(cfg!(windows), |term| term != "dumb") - && env::var_os("NO_COLOR").is_none() + // ただしWindowsではPowerShellっぽかったらそのまま許可する。 + // ちゃんとやるなら`ENABLE_VIRTUAL_TERMINAL_PROCESSING`をチェックするなり、そもそも + // fwdansiとかでWin32の色に変換するべきだが、面倒。 + env::var_os("TERM").map_or( + cfg!(windows) && env::var_os("PSModulePath").is_some(), + |term| term != "dumb", + ) && env::var_os("NO_COLOR").is_none() } });