From 13e5713e3084b216c67e9dbc36de6e45b73b9824 Mon Sep 17 00:00:00 2001 From: Alaric Senat Date: Fri, 17 Jul 2026 23:36:19 +0200 Subject: [PATCH] build: probe pkg-config once and drop the redundant vlc link pkg-config was probed up to three times per build: once inside generate_bindings for the header include paths, once for linking, and then main unconditionally emitted `cargo:rustc-link-lib=vlc` on top of the directives the successful probe already prints, libvlc ended up on the link line two or three times. Probe a single time in main and thread the resulting Library into generate_bindings for its include paths. Drop the manual rustc-link-lib line, since a successful pkg_config probe emits it. --- libvlc-sys/build.rs | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/libvlc-sys/build.rs b/libvlc-sys/build.rs index 2318e30..3405043 100644 --- a/libvlc-sys/build.rs +++ b/libvlc-sys/build.rs @@ -6,7 +6,7 @@ use pkg_config; const MIN_LIBVLC_VERSION: &str = "3.0.0"; #[cfg(feature = "bindgen")] -fn generate_bindings() { +fn generate_bindings(library: &pkg_config::Library) { println!("cargo:rerun-if-changed=wrapper.h"); let mut bindings = bindgen::Builder::default() @@ -22,9 +22,8 @@ fn generate_bindings() { .allowlist_function("vsnprintf") .parse_callbacks(Box::new(bindgen::CargoCallbacks::new())); - // Set header include paths - let pkg_config_library = pkg_config::Config::new().probe("libvlc").unwrap(); - for include_path in &pkg_config_library.include_paths { + // Set header include paths from the pkg-config probe. + for include_path in &library.include_paths { bindings = bindings.clang_arg(format!("-I{}", include_path.display())); } @@ -167,21 +166,26 @@ mod windows { } fn main() { + // Probe once and reuse the result for both binding generation (include + // paths) and linking (pkg-config emits the link directives on success). + let library = probe_libvlc(); + // Binding generation #[cfg(feature = "bindgen")] - generate_bindings(); + generate_bindings(library.as_ref().expect( + "pkg-config is required to locate the libvlc headers with the `bindgen` feature", + )); #[cfg(not(feature = "bindgen"))] copy_pregenerated_bindings(); - // Link - if let Err(err) = probe_libvlc() { + // Link. On success pkg-config has already emitted the link directives; only + // the failure path needs handling. + if let Err(err) = library { #[cfg(target_os = "windows")] windows::link_vlc(); #[cfg(not(target_os = "windows"))] panic!("libvlc (>= {}) not found: {:?}", MIN_LIBVLC_VERSION, err); } - - println!("cargo:rustc-link-lib=vlc"); }