-
Notifications
You must be signed in to change notification settings - Fork 38
/
build.rs
67 lines (63 loc) · 1.35 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
55
56
57
58
59
60
61
62
63
64
65
66
67
fn main() {
if let Ok(ref s) = std::env::var("LIBXML2") {
// println!("{:?}", std::env::vars());
// panic!("set libxml2.");
let p = std::path::Path::new(s);
let fname = std::path::Path::new(
p.file_name()
.unwrap_or_else(|| panic!("no file name in LIBXML2 env ({s})")),
);
assert!(
p.is_file(),
"{}",
&format!("not a file in LIBXML2 env ({s})")
);
println!(
"cargo:rustc-link-lib={}",
fname
.file_stem()
.unwrap()
.to_string_lossy()
.strip_prefix("lib")
.unwrap()
);
println!(
"cargo:rustc-link-search={}",
p.parent()
.expect("no library path in LIBXML2 env")
.to_string_lossy()
);
} else {
#[cfg(any(target_family = "unix", target_os = "macos"))]
{
if pkg_config_dep::find() {
return;
}
}
#[cfg(windows)]
{
if vcpkg_dep::find() {
return;
}
}
panic!("Could not find libxml2.")
}
}
#[cfg(any(target_family = "unix", target_os = "macos"))]
mod pkg_config_dep {
pub fn find() -> bool {
if pkg_config::find_library("libxml-2.0").is_ok() {
return true;
}
false
}
}
#[cfg(target_family = "windows")]
mod vcpkg_dep {
pub fn find() -> bool {
if vcpkg::find_package("libxml2").is_ok() {
return true;
}
false
}
}