From 2f85c3b2bf38d730338653245ffc431fc89ea23f Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Tue, 18 Aug 2020 15:16:30 -0500 Subject: [PATCH] Add iOS build. --- Cargo.toml | 5 ++--- src/backends/av_foundation.rs | 4 ++-- src/backends/mod.rs | 4 ++-- src/lib.rs | 9 ++++++--- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index fed932d..4a2f44e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,8 +9,7 @@ exclude = ["*.cfg", "*.yml"] edition = "2018" [lib] -name = "tts" -crate-type = ["staticlib", "cdylib"] +crate-type = ["lib", "staticlib"] [dependencies] log = "0.4" @@ -27,7 +26,7 @@ tts_winrt_bindings = { version = "0.1", path="winrt_bindings" } [target.'cfg(target_os = "linux")'.dependencies] speech-dispatcher = "0.4" -[target.'cfg(target_os = "macos")'.dependencies] +[target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies] cocoa-foundation = "0.1" libc = "0.2" objc = "0.2" diff --git a/src/backends/av_foundation.rs b/src/backends/av_foundation.rs index 13ea05c..a04eaea 100644 --- a/src/backends/av_foundation.rs +++ b/src/backends/av_foundation.rs @@ -1,4 +1,4 @@ -#[cfg(target_os = "macos")] +#[cfg(any(target_os = "macos", target_os = "ios"))] #[link(name = "AVFoundation", kind = "framework")] use cocoa_foundation::base::{id, nil}; use cocoa_foundation::foundation::NSString; @@ -132,7 +132,7 @@ impl Backend for AvFoundation { fn is_speaking(&self) -> Result { let is_speaking: i8 = unsafe { msg_send![self.synth, isSpeaking] }; - Ok(is_speaking == YES) + Ok(is_speaking == 1) } } diff --git a/src/backends/mod.rs b/src/backends/mod.rs index 7971db1..c999faf 100644 --- a/src/backends/mod.rs +++ b/src/backends/mod.rs @@ -13,7 +13,7 @@ mod web; #[cfg(target_os = "macos")] mod appkit; -#[cfg(target_os = "macos")] +#[cfg(any(target_os = "macos", target_os = "ios"))] mod av_foundation; #[cfg(target_os = "linux")] @@ -28,5 +28,5 @@ pub use self::web::*; #[cfg(target_os = "macos")] pub use self::appkit::*; -#[cfg(target_os = "macos")] +#[cfg(any(target_os = "macos", target_os = "ios"))] pub use self::av_foundation::*; diff --git a/src/lib.rs b/src/lib.rs index d5d8210..d1dda48 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,8 +11,9 @@ * * WebAssembly */ +use std::boxed::Box; #[cfg(target_os = "macos")] -use std::{boxed::Box, ffi::CStr}; +use std::ffi::CStr; #[cfg(target_os = "macos")] use cocoa_foundation::base::id; @@ -35,7 +36,7 @@ pub enum Backends { WinRT, #[cfg(target_os = "macos")] AppKit, - #[cfg(target_os = "macos")] + #[cfg(any(target_os = "macos", target_os = "ios"))] AvFoundation, } @@ -122,7 +123,7 @@ impl TTS { } #[cfg(target_os = "macos")] Backends::AppKit => Ok(TTS(Box::new(backends::AppKit::new()))), - #[cfg(target_os = "macos")] + #[cfg(any(target_os = "macos", target_os = "ios"))] Backends::AvFoundation => Ok(TTS(Box::new(backends::AvFoundation::new()))), } } @@ -156,6 +157,8 @@ impl TTS { TTS::new(Backends::AppKit) } }; + #[cfg(target_os = "ios")] + let tts = TTS::new(Backends::AvFoundation); tts }