Merge pull request #1 from selfisekai/pkg-config

add linux-pkg-config feature
This commit is contained in:
RustDesk 2023-05-20 10:21:05 +08:00 committed by GitHub
commit 5cd2bf989c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 0 deletions

View File

@ -13,6 +13,10 @@ categories = ["api-bindings", "encoding", "compression",
repository = "https://github.com/DuckerMan/magnum-opus"
documentation = "https://docs.rs/magnum-opus"
[features]
linux-pkg-config = ["dep:pkg-config"]
[build-dependencies]
target_build_utils = "0.3"
bindgen = "0.59"
pkg-config = { version = "0.3.27", optional = true }

View File

@ -3,6 +3,17 @@ use std::{
path::{Path, PathBuf},
};
#[cfg(all(target_os = "linux", feature = "linux-pkg-config"))]
fn link_pkg_config(name: &str) -> Vec<PathBuf> {
let lib = pkg_config::probe_library(name)
.expect(format!(
"unable to find '{name}' development headers with pkg-config (feature linux-pkg-config is enabled).
try installing '{name}-dev' from your system package manager.").as_str());
lib.include_paths
}
#[cfg(not(all(target_os = "linux", feature = "linux-pkg-config")))]
fn link_vcpkg(mut path: PathBuf, name: &str) -> PathBuf {
let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap();
let mut target_arch = std::env::var("CARGO_CFG_TARGET_ARCH").unwrap();
@ -45,6 +56,7 @@ fn link_vcpkg(mut path: PathBuf, name: &str) -> PathBuf {
include
}
#[cfg(not(all(target_os = "linux", feature = "linux-pkg-config")))]
fn link_homebrew_m1(name: &str) -> PathBuf {
let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap();
let target_arch = std::env::var("CARGO_CFG_TARGET_ARCH").unwrap();
@ -95,6 +107,12 @@ fn link_homebrew_m1(name: &str) -> PathBuf {
include
}
#[cfg(all(target_os = "linux", feature = "linux-pkg-config"))]
fn find_package(name: &str) -> Vec<PathBuf> {
return link_pkg_config(name);
}
#[cfg(not(all(target_os = "linux", feature = "linux-pkg-config")))]
fn find_package(name: &str) -> Vec<PathBuf> {
if let Ok(vcpkg_root) = std::env::var("VCPKG_ROOT") {
vec![link_vcpkg(vcpkg_root.into(), name)]