From fa216a534e90ea0969c4f0de228ce01e66979b36 Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Thu, 8 Oct 2020 19:07:07 -0500 Subject: [PATCH] Gate Tolk behind use_tolk feature to support compilation on UWP. --- Cargo.toml | 6 +++++- src/backends/mod.rs | 4 ++-- src/backends/tolk.rs | 2 +- src/lib.rs | 8 +++++--- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3e25114..085a080 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,6 +11,10 @@ edition = "2018" [lib] crate-type = ["lib", "cdylib", "staticlib"] +[features] + +use_tolk = ["tolk"] + [dependencies] lazy_static = "1" log = "0.4" @@ -20,7 +24,7 @@ thiserror = "1" env_logger = "0.7" [target.'cfg(windows)'.dependencies] -tolk = ">= 0.2.1" +tolk = { version = ">= 0.2.1", optional = true } winrt = "0.7" tts_winrt_bindings = { version = "0.1", path="winrt_bindings" } diff --git a/src/backends/mod.rs b/src/backends/mod.rs index 6274692..408e5bf 100644 --- a/src/backends/mod.rs +++ b/src/backends/mod.rs @@ -1,7 +1,7 @@ #[cfg(target_os = "linux")] mod speech_dispatcher; -#[cfg(windows)] +#[cfg(all(windows, feature = "use_tolk"))] mod tolk; #[cfg(windows)] @@ -19,7 +19,7 @@ mod av_foundation; #[cfg(target_os = "linux")] pub(crate) use self::speech_dispatcher::*; -#[cfg(windows)] +#[cfg(all(windows, feature = "use_tolk"))] pub(crate) use self::tolk::*; #[cfg(target_arch = "wasm32")] diff --git a/src/backends/tolk.rs b/src/backends/tolk.rs index 66c88e7..4cf7315 100644 --- a/src/backends/tolk.rs +++ b/src/backends/tolk.rs @@ -1,4 +1,4 @@ -#[cfg(windows)] +#[cfg(all(windows, feature = "use_tolk"))] use log::{info, trace}; use tolk::Tolk as TolkPtr; diff --git a/src/lib.rs b/src/lib.rs index ecf89ad..c6a7a58 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -33,7 +33,7 @@ pub enum Backends { SpeechDispatcher, #[cfg(target_arch = "wasm32")] Web, - #[cfg(windows)] + #[cfg(all(windows, feature = "use_tolk"))] Tolk, #[cfg(windows)] WinRT, @@ -167,7 +167,7 @@ impl TTS { let tts = backends::Web::new()?; Ok(TTS(Box::new(tts))) } - #[cfg(windows)] + #[cfg(all(windows, feature = "use_tolk"))] Backends::Tolk => { let tts = backends::Tolk::new(); if let Some(tts) = tts { @@ -200,12 +200,14 @@ impl TTS { pub fn default() -> Result { #[cfg(target_os = "linux")] let tts = TTS::new(Backends::SpeechDispatcher); - #[cfg(windows)] + #[cfg(all(windows, feature = "use_tolk"))] let tts = if let Ok(tts) = TTS::new(Backends::Tolk) { Ok(tts) } else { TTS::new(Backends::WinRT) }; + #[cfg(all(windows, not(feature = "use_tolk")))] + let tts = TTS::new(Backends::WinRT); #[cfg(target_arch = "wasm32")] let tts = TTS::new(Backends::Web); #[cfg(target_os = "macos")]