From 021c111ffba0820406329384533d1f6edb77763c Mon Sep 17 00:00:00 2001 From: FreezyLemon Date: Sun, 28 Apr 2024 15:08:55 +0200 Subject: [PATCH] Use AVLibrary for pkg-config probing --- ffmpeg-sys-the-third/build.rs | 38 ++++++++++------------------------- 1 file changed, 11 insertions(+), 27 deletions(-) diff --git a/ffmpeg-sys-the-third/build.rs b/ffmpeg-sys-the-third/build.rs index e85f4b2..720d51b 100644 --- a/ffmpeg-sys-the-third/build.rs +++ b/ffmpeg-sys-the-third/build.rs @@ -49,6 +49,10 @@ impl Library { } } + fn lib_name(&self) -> String { + format!("lib{}", self.name) + } + fn enabled(&self) -> bool { !self.optional || cargo_feature_enabled(self.name) } @@ -984,37 +988,17 @@ fn main() { } paths - } - // Fallback to pkg-config - else { + } else { + // Fallback to pkg-config add_pkg_config_path(); - pkg_config::Config::new() - .statik(statik) - .probe("libavutil") - .unwrap(); + let mut pkgconfig = pkg_config::Config::new(); + pkgconfig.statik(statik); - let mut libs = vec![ - ("libavformat", "AVFORMAT"), - ("libavfilter", "AVFILTER"), - ("libavdevice", "AVDEVICE"), - ("libswscale", "SWSCALE"), - ("libswresample", "SWRESAMPLE"), - ]; - if ffmpeg_major_version < 5 { - libs.push(("libavresample", "AVRESAMPLE")); + for lib in LIBRARIES.iter().filter(|lib| lib.enabled()) { + let _ = pkgconfig.probe(&lib.lib_name()).unwrap(); } - for (lib_name, env_variable_name) in libs.iter() { - if cargo_feature_enabled(env_variable_name) { - pkg_config::Config::new() - .statik(statik) - .probe(lib_name) - .unwrap(); - } - } - - pkg_config::Config::new() - .statik(statik) + pkgconfig .probe("libavcodec") .unwrap() .include_paths