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.merge-requests/17/head
parent
fe83e031af
commit
13e5713e30
|
|
@ -6,7 +6,7 @@ use pkg_config;
|
||||||
const MIN_LIBVLC_VERSION: &str = "3.0.0";
|
const MIN_LIBVLC_VERSION: &str = "3.0.0";
|
||||||
|
|
||||||
#[cfg(feature = "bindgen")]
|
#[cfg(feature = "bindgen")]
|
||||||
fn generate_bindings() {
|
fn generate_bindings(library: &pkg_config::Library) {
|
||||||
println!("cargo:rerun-if-changed=wrapper.h");
|
println!("cargo:rerun-if-changed=wrapper.h");
|
||||||
|
|
||||||
let mut bindings = bindgen::Builder::default()
|
let mut bindings = bindgen::Builder::default()
|
||||||
|
|
@ -22,9 +22,8 @@ fn generate_bindings() {
|
||||||
.allowlist_function("vsnprintf")
|
.allowlist_function("vsnprintf")
|
||||||
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()));
|
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()));
|
||||||
|
|
||||||
// Set header include paths
|
// Set header include paths from the pkg-config probe.
|
||||||
let pkg_config_library = pkg_config::Config::new().probe("libvlc").unwrap();
|
for include_path in &library.include_paths {
|
||||||
for include_path in &pkg_config_library.include_paths {
|
|
||||||
bindings = bindings.clang_arg(format!("-I{}", include_path.display()));
|
bindings = bindings.clang_arg(format!("-I{}", include_path.display()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -167,21 +166,26 @@ mod windows {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
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
|
// Binding generation
|
||||||
#[cfg(feature = "bindgen")]
|
#[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"))]
|
#[cfg(not(feature = "bindgen"))]
|
||||||
copy_pregenerated_bindings();
|
copy_pregenerated_bindings();
|
||||||
|
|
||||||
// Link
|
// Link. On success pkg-config has already emitted the link directives; only
|
||||||
if let Err(err) = probe_libvlc() {
|
// the failure path needs handling.
|
||||||
|
if let Err(err) = library {
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
windows::link_vlc();
|
windows::link_vlc();
|
||||||
|
|
||||||
#[cfg(not(target_os = "windows"))]
|
#[cfg(not(target_os = "windows"))]
|
||||||
panic!("libvlc (>= {}) not found: {:?}", MIN_LIBVLC_VERSION, err);
|
panic!("libvlc (>= {}) not found: {:?}", MIN_LIBVLC_VERSION, err);
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("cargo:rustc-link-lib=vlc");
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue