-
Notifications
You must be signed in to change notification settings - Fork 4
/
build.rs
54 lines (47 loc) · 1.64 KB
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use std::env::{var, var_os};
use std::path::PathBuf;
fn cfg_arch() -> String {
var("CARGO_CFG_TARGET_ARCH").expect("couldn't find target architecture")
}
fn cfg_family_is(family: &str) -> bool {
var_os("CARGO_CFG_TARGET_FAMILY").unwrap() == *family
}
fn cfg_os_is(family: &str) -> bool {
var_os("CARGO_CFG_TARGET_OS").unwrap() == *family
}
fn find_avahi_compat_dns_sd() {
// on unix but not darwin link avahi compat
if cfg_family_is("unix") && !(cfg_os_is("macos") || cfg_os_is("ios")) {
pkg_config::probe_library("avahi-compat-libdns_sd").unwrap();
}
}
fn dns_sd_lib_path() -> Option<PathBuf> {
if cfg!(feature = "win-bonjour") && cfg_family_is("windows") {
let platform = match cfg_arch().as_str() {
"x86_64" => "x64",
"x86" => "Win32",
arch => panic!("unsupported target architecture: {:?}", arch),
};
match var("BONJOUR_SDK_HOME") {
Ok(path) => Some(PathBuf::from(path).join("Lib").join(platform)),
Err(e) => panic!("Can't find Bonjour SDK (download from https://developer.apple.com/bonjour/ ) at BONJOUR_SDK_HOME: {}", e),
}
} else {
None
}
}
fn find_windows_dns_sd() {
if let Some(path) = dns_sd_lib_path() {
println!("cargo:rustc-link-search=native={}", path.display())
}
if cfg!(feature = "win-bonjour") && cfg_family_is("windows") {
println!("cargo:rustc-link-lib=dnssd");
} else if cfg_family_is("windows") {
println!("cargo:rustc-link-lib=dnsapi");
}
}
fn main() {
println!("cargo:rerun-if-changed=build.rs");
find_avahi_compat_dns_sd();
find_windows_dns_sd();
}