plietar / librespot

Open Source Spotify client library
MIT License
1.13k stars 187 forks source link

Allow avahi support using dns-sd for Discovery #246

Open shanemeagher opened 6 years ago

shanemeagher commented 6 years ago

rust-mdns is still the default but can also be specified explicitly with --feature "with-internal-mdns" switch at build time.

Added --feature "with-external-mdns" switch to build librespot to use avahi for discovery using dns-sd package.

This commit does not provide option for building without mdns.

This pull request replaces pull request https://github.com/plietar/librespot/pull/201 started by @awiouy and has been rebased on the current master branch.

shanemeagher commented 6 years ago

@plietar, It seems I'm still having an issue when building with --no-default-features. As mdns is optional and not a dependency of an enabled feature (with-internal-mdns) in cargo.toml, cargo doesn't pass it to rustc.

In src/lib.rs, I've used cfg-if to reference mdns:

cfg_if! {
    if #[cfg(feature = "with-internal-mdns")] {
        extern crate mdns;
    } else if #[cfg(feature = "with-external-mdns")] {
        extern crate dns_sd;
    } else {
        extern crate mdns;
    }
}

resulting in this error: https://travis-ci.org/plietar/librespot/jobs/272099406#L929

In the PR201, you asked:

Did you use #[cfg(mdns)] around the extern crate mdns ? Would this not have just checked if the dependency mdns was enabled? Which it isn't?

Is there a way to make one of the features a default requirement if none is specified?