From 81250729d289af20ea69e53394ad7b28867cc0ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=85=88=E9=85=89?= Date: Fri, 10 Nov 2023 14:58:41 +0800 Subject: [PATCH] feat: static system link --- Cargo.toml | 6 ++++-- build.rs | 13 ++++++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f28016d..232db32 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,8 +22,9 @@ edition = "2021" opt-level = 2 [build-dependencies] -cc = "1.1" -glob = "0.3.1" +cc = "1" +glob = "0.3" +pkg-config = "0.3.27" [features] default = ["std", "parallel"] @@ -32,3 +33,4 @@ parallel = ["cc/parallel"] neon = [] # ARM NEON SIMD (will crash on ARM CPUs without it) sse41 = [] # x64 SSE 4.1 (will crash on x86 CPUs without it) avx2 = [] # x64 AVX2 (will crash on x86 CPUs without it) +system-dylib = [] # Use the system-installed dylib instead of compiling a static library from the vendor diff --git a/build.rs b/build.rs index 269b979..e0b9ff5 100644 --- a/build.rs +++ b/build.rs @@ -1,10 +1,17 @@ -extern crate cc; -extern crate glob; - use std::env; use std::path::PathBuf; fn main() { + if cfg!(feature = "system-link") { + let lib_name = "libwebp"; + let find_system_lib = pkg_config::Config::new().probe(lib_name).is_ok(); + + if find_system_lib { + println!("cargo:rustc-link-lib={}", lib_name); + return; + } + } + let manifest_dir = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR")); let vendor = manifest_dir.join("vendor");