From 34aa7a1236a1f3b88be9c400d435ac74e8607812 Mon Sep 17 00:00:00 2001 From: Donough Liu Date: Sat, 16 Aug 2025 23:21:12 +0800 Subject: [PATCH 1/2] feat: make pkg_config linking respect FFMPEG_LINK_MODE --- build.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/build.rs b/build.rs index df5607e..8d6d749 100644 --- a/build.rs +++ b/build.rs @@ -187,12 +187,18 @@ impl callbacks::ParseCallbacks for FilterCargoCallbacks { } } -#[derive(Clone, Copy)] +#[derive(Clone, Copy, PartialEq, Eq)] enum FFmpegLinkMode { Static, Dynamic, } +impl FFmpegLinkMode { + fn is_static(&self) -> bool { + self == &Self::Static + } +} + impl From for FFmpegLinkMode { fn from(value: String) -> Self { match &*value { @@ -333,10 +339,12 @@ mod pkg_config_linking { /// Note: no side effect if this function errors. pub fn linking_with_pkg_config( library_names: &[&str], + statik: bool, ) -> Result, pkg_config::Error> { // dry run for library linking for libname in library_names { pkg_config::Config::new() + .statik(statik) .cargo_metadata(false) .env_metadata(false) .print_system_libs(false) @@ -348,6 +356,7 @@ mod pkg_config_linking { let mut paths = HashSet::new(); for libname in library_names { let new_paths = pkg_config::Config::new() + .statik(statik) .probe(&format!("lib{}", libname)) .unwrap_or_else(|_| panic!("{} not found!", libname)) .include_paths; @@ -437,7 +446,13 @@ fn linking(env_vars: EnvVars) { output_binding_path: &Path, ) -> Result<(), pkg_config::Error> { // Probe libraries(enable emitting cargo metadata) - let include_paths = pkg_config_linking::linking_with_pkg_config(&*LIBS)?; + let include_paths = pkg_config_linking::linking_with_pkg_config( + &*LIBS, + env_vars + .ffmpeg_link_mode + .map(|x| x.is_static()) + .unwrap_or_default(), + )?; if let Some(ffmpeg_binding_path) = env_vars.ffmpeg_binding_path.as_ref() { use_prebuilt_binding(ffmpeg_binding_path, output_binding_path); } else if let Some(ffmpeg_include_dir) = env_vars.ffmpeg_include_dir.as_ref() { From 66aaa37add98dfe3cb2cc0ef3ea88f53364f922c Mon Sep 17 00:00:00 2001 From: Donough Liu Date: Sat, 16 Aug 2025 23:34:27 +0800 Subject: [PATCH 2/2] Fix windows warning --- build.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/build.rs b/build.rs index 8d6d749..d3051b3 100644 --- a/build.rs +++ b/build.rs @@ -193,6 +193,7 @@ enum FFmpegLinkMode { Dynamic, } +#[cfg(not(target_os = "windows"))] impl FFmpegLinkMode { fn is_static(&self) -> bool { self == &Self::Static