From b368782b9db6e0492afcd3391ef8796c09ac3dfc 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 | 14 ++++++++++++++ 2 files changed, 16 insertions(+) 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..3d14cb8 100644 --- a/build.rs +++ b/build.rs @@ -1,10 +1,24 @@ extern crate cc; extern crate glob; +extern crate pkg_config; 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");