Skip to content

Commit

Permalink
#72-add-vcpkg-optional-dependency
Browse files Browse the repository at this point in the history
add opt in dependency for vcpkg
make pkg-config optional but default
  • Loading branch information
JoshuaNitschke authored and dginev committed Sep 29, 2020
1 parent ad91523 commit 1f5093c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 5 deletions.
6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ name = "libxml"
[dependencies]
libc = "0.2"

[features]
default = ["pkg-config"]

[build-dependencies]
pkg-config = "0.3.2"
pkg-config = {version = "0.3.2", optional = true }
vcpkg = { version = "0.2", optional = true }

[dev-dependencies]
rayon = "1.0.0"
Expand Down
45 changes: 41 additions & 4 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,44 @@
use pkg_config::find_library;
fn main() {
if cfg!(not(feature = "pkg-config")) && cfg!(not(feature = "vcpkg"))
{
panic!(r#"Enable "pkg-config" or "vcpkg" feature flags to locate libxml2"#)
}

#[cfg(feature = "pkg-config")]
{
if pkg_config_dep::find() {
return;
}
}

fn main() {
if find_library("libxml-2.0").is_err() {
panic!("Could not find libxml2 using pkg-config")
#[cfg(feature = "vcpkg")]
{
if vcpkg_dep::find() {
return;
}
}

panic!("Could not find libxml2.")
}

#[cfg(feature = "pkg-config")]
mod pkg_config_dep {
use pkg_config;
pub fn find() -> bool {
if pkg_config::find_library("libxml-2.0").is_ok() {
return true;
}
false
}
}

#[cfg(feature = "vcpkg")]
mod vcpkg_dep {
use vcpkg;
pub fn find() -> bool {
if vcpkg::find_package("libxml2").is_ok() {
return true
}
false
}
}

0 comments on commit 1f5093c

Please sign in to comment.