build(webrtc-sys): allow probing GLib/GIO without panicking on missing system headers#1202
build(webrtc-sys): allow probing GLib/GIO without panicking on missing system headers#1202mjpvl-ai wants to merge 4 commits into
Conversation
| } else { | ||
| println!("cargo:rustc-link-lib=dylib={}", lib_name); | ||
| } |
There was a problem hiding this comment.
🔴 GLib libraries are linked when pkg-config probe fails, contradicting the explicit "headers only" design
The fallback branch links GLib/GIO dynamically (println!("cargo:rustc-link-lib=dylib={}", lib_name) at webrtc-sys/build.rs:190) when pkg-config probe fails, despite the comment on line 183 stating "Do not use pkg_config::probe_library, because we only require headers."
Impact: Builds on systems without GLib pkg-config files will produce binaries with an unwanted hard link-time dependency on GLib, reversing the fix from PR #1144 that deliberately removed this dependency.
Design intent violation and mechanism
PR #1144 (commit 2540efe) specifically switched to cargo_metadata(false) to avoid emitting link directives for GLib. The comment on line 183 explicitly states the intent: only headers are needed. The add_gio_headers function at webrtc-sys/build.rs:498-522 already provides the necessary GLib headers from the WebRTC sysroot, so the pkg-config probe is supplementary.
When probe fails, the correct behavior should be to either:
- Do nothing (since
add_gio_headersalready provides sysroot headers), or - Emit a warning
Instead, the else branch links the library, which:
- Doesn't help compilation (no include paths are added)
- Introduces an unwanted runtime dependency on GLib
- Breaks the use case described in PR Remove default link-time dependency on GLib #1144 where consumers explicitly do NOT want GLib linked
| } else { | |
| println!("cargo:rustc-link-lib=dylib={}", lib_name); | |
| } | |
| } else { | |
| println!("cargo:warning={} not found via pkg-config; using sysroot headers only", lib_name); | |
Was this helpful? React with 👍 or 👎 to provide feedback.
| let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap(); | ||
| let local_links = Path::new(&manifest_dir).join("../local_links"); | ||
| println!("cargo:rustc-link-search=native={}", local_links.display()); |
There was a problem hiding this comment.
🔴 Hardcoded non-existent link search path added unconditionally to all Linux builds
A link search path pointing to a non-existent ../local_links directory is unconditionally added (webrtc-sys/build.rs:181) to all Linux builds, which can cause the linker to resolve libraries from an unintended location if that directory happens to exist.
Impact: On any system where a local_links directory exists adjacent to the repo root, the linker may silently pick up wrong library versions, causing hard-to-diagnose link failures or runtime crashes.
Mechanism and context
The code at lines 179-181 adds ../local_links relative to CARGO_MANIFEST_DIR (which is webrtc-sys/) as a native link search path. This directory does not exist in the repository (verified), is not in .gitignore, and is not documented anywhere. This appears to be a local development artifact that was accidentally included in the PR.
This is particularly problematic in combination with BUG-0001: when the GLib probe fails, the linker will attempt to find libglib-2.0.so, libgobject-2.0.so, and libgio-2.0.so in this local_links directory.
| let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap(); | |
| let local_links = Path::new(&manifest_dir).join("../local_links"); | |
| println!("cargo:rustc-link-search=native={}", local_links.display()); |
Was this helpful? React with 👍 or 👎 to provide feedback.
PR description
The Problem
In the
webrtc-sysbuild script (build.rs), the script previously called.unwrap()when probing forglib-2.0,gobject-2.0, andgio-2.0viapkg-config. If these system development headers/libraries were not installed globally or configured inpkg-config, the build script would panic immediately, blocking compilation even if the required libraries were provided via local linking paths.The Solution
This PR makes the GLib/GIO probing process environment-aware and robust:
.unwrap()withif let Ok(lib)so that the build script does not panic if headers are missing.pkg-configcannot probe the libraries, it falls back to printingcargo:rustc-link-lib=dylib={lib_name}to allow resolving them dynamically at link time.../local_linksdirectory (relative to thewebrtc-syscrate) to the library search path (cargo:rustc-link-search=native=...). This allows building and linking against pre-compiled system libraries placed in a local directory.Breaking changes
None. This is a backward-compatible build system improvement.
MSRV
No changes to the Minimum Supported Rust Version (MSRV).
Testing
glib/gio/gobject.