Add `asio` cargo feature for optional ASIO support

ASIO introduces quite a few extra crates and requires a fairly
complicated setup process (see the readme), so this feature is disabled
by default.
This commit is contained in:
mitchmindtree 2019-06-29 06:08:35 +10:00
parent 76fab4f982
commit 8f95042b8d
4 changed files with 23 additions and 2 deletions

View File

@ -8,6 +8,9 @@ documentation = "https://docs.rs/cpal"
license = "Apache-2.0" license = "Apache-2.0"
keywords = ["audio", "sound"] keywords = ["audio", "sound"]
[features]
asio = ["asio-sys"] # Only available on Windows. See README for setup instructions.
[dependencies] [dependencies]
failure = "0.1.5" failure = "0.1.5"
lazy_static = "1.3" lazy_static = "1.3"
@ -18,7 +21,7 @@ hound = "3.4"
[target.'cfg(target_os = "windows")'.dependencies] [target.'cfg(target_os = "windows")'.dependencies]
winapi = { version = "0.3", features = ["audiosessiontypes", "audioclient", "coml2api", "combaseapi", "debug", "devpkey", "handleapi", "ksmedia", "mmdeviceapi", "objbase", "std", "synchapi", "winuser"] } winapi = { version = "0.3", features = ["audiosessiontypes", "audioclient", "coml2api", "combaseapi", "debug", "devpkey", "handleapi", "ksmedia", "mmdeviceapi", "objbase", "std", "synchapi", "winuser"] }
asio-sys = { version = "0.1", path = "asio-sys" } asio-sys = { version = "0.1", path = "asio-sys", optional = true }
[target.'cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "openbsd"))'.dependencies] [target.'cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "openbsd"))'.dependencies]
alsa-sys = { version = "0.1", path = "alsa-sys" } alsa-sys = { version = "0.1", path = "alsa-sys" }

View File

@ -83,7 +83,18 @@ WASAPI. To do so, follow these steps:
If you run into an error along the lines of "no variant `Asio` in `HostId`", If you run into an error along the lines of "no variant `Asio` in `HostId`",
make sure that `CPAL_ASIO_DIR` is set correctly and try `cargo clean`. make sure that `CPAL_ASIO_DIR` is set correctly and try `cargo clean`.
9. Make sure to enable the `asio` feature when building CPAL:
```
cargo build --features "asio"
```
or if you are using CPAL as a dependency in a downstream project, enable the
feature like this:
```toml
cpal = { version = "*", features = ["asio"] }
```
In the future we would like to work on automating this process to make it In the future we would like to work on automating this process to make it
easier, but we are not familiar enough with the ASIO license to do so yet. easier, but we are not familiar enough with the ASIO license to do so yet.

View File

@ -1,6 +1,6 @@
#[cfg(any(target_os = "linux", target_os = "freebsd"))] #[cfg(any(target_os = "linux", target_os = "freebsd"))]
pub(crate) mod alsa; pub(crate) mod alsa;
#[cfg(windows)] #[cfg(all(windows, feature = "asio"))]
pub(crate) mod asio; pub(crate) mod asio;
#[cfg(any(target_os = "macos", target_os = "ios"))] #[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) mod coreaudio; pub(crate) mod coreaudio;

View File

@ -521,6 +521,9 @@ mod platform_impl {
// TODO: Add `Asio asio` once #221 lands. // TODO: Add `Asio asio` once #221 lands.
#[cfg(windows)] #[cfg(windows)]
mod platform_impl { mod platform_impl {
#![allow(unreachable_patterns)]
#[cfg(feature = "asio")]
pub use crate::host::asio::{ pub use crate::host::asio::{
Device as AsioDevice, Device as AsioDevice,
Devices as AsioDevices, Devices as AsioDevices,
@ -540,8 +543,12 @@ mod platform_impl {
SupportedOutputFormats as WasapiSupportedOutputFormats, SupportedOutputFormats as WasapiSupportedOutputFormats,
}; };
#[cfg(feature = "asio")]
impl_platform_host!(Asio asio, Wasapi wasapi); impl_platform_host!(Asio asio, Wasapi wasapi);
#[cfg(not(feature = "asio"))]
impl_platform_host!(Wasapi wasapi);
/// The default host for the current compilation target platform. /// The default host for the current compilation target platform.
pub fn default_host() -> Host { pub fn default_host() -> Host {
WasapiHost::new() WasapiHost::new()