From 9d2ca9fb595b5b07f5bdaf8293f0ee190015c328 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 | 2 ++ build.rs | 16 +++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d87de16..ea3c871 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,6 +17,7 @@ repository = "https://github.com/NoXF/libwebp-sys" [build-dependencies] cc = "1" glob = "0.3" +pkg-config = "0.3.27" [features] default = ["std", "parallel", "neon"] @@ -25,3 +26,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-link = [] \ No newline at end of file diff --git a/build.rs b/build.rs index f9f7e98..af39416 100644 --- a/build.rs +++ b/build.rs @@ -1,10 +1,20 @@ -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() + .statik(true) + .probe(lib_name) + .is_ok(); + + if find_system_lib { + println!("cargo:rustc-link-lib=static={}", lib_name); + return; + } + } + let manifest_dir = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR")); let vendor = manifest_dir.join("vendor");