Skip to content

build(webrtc-sys): allow probing GLib/GIO without panicking on missing system headers#1202

Open
mjpvl-ai wants to merge 4 commits into
livekit:mainfrom
mjpvl-ai:feature/a2a-relay-standalone
Open

build(webrtc-sys): allow probing GLib/GIO without panicking on missing system headers#1202
mjpvl-ai wants to merge 4 commits into
livekit:mainfrom
mjpvl-ai:feature/a2a-relay-standalone

Conversation

@mjpvl-ai

@mjpvl-ai mjpvl-ai commented Jun 30, 2026

Copy link
Copy Markdown

PR description

The Problem

In the webrtc-sys build script (build.rs), the script previously called .unwrap() when probing for glib-2.0, gobject-2.0, and gio-2.0 via pkg-config. If these system development headers/libraries were not installed globally or configured in pkg-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:

  1. Fallback Probing: Replaces .unwrap() with if let Ok(lib) so that the build script does not panic if headers are missing.
  2. Link Fallback: If pkg-config cannot probe the libraries, it falls back to printing cargo:rustc-link-lib=dylib={lib_name} to allow resolving them dynamically at link time.
  3. Local Library Path: Adds the ../local_links directory (relative to the webrtc-sys crate) 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

  • Verified that the build script compiles and links successfully on environments without global development packages for glib / gio / gobject.
  • Ran cargo check on the parent monorepo workspace to ensure all dependent crates compile correctly:
    cargo check -p livekit -p webrtc-sys -p livekit-api -p livekit-protocol -p livekit-runtime -p livekit-datatrack

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 2 potential issues.

View 2 additional findings in Devin Review.

Open in Devin Review

Comment thread webrtc-sys/build.rs
Comment on lines +189 to 191
} else {
println!("cargo:rustc-link-lib=dylib={}", lib_name);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 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_headers already provides sysroot headers), or
  • Emit a warning

Instead, the else branch links the library, which:

  1. Doesn't help compilation (no include paths are added)
  2. Introduces an unwanted runtime dependency on GLib
  3. Breaks the use case described in PR Remove default link-time dependency on GLib #1144 where consumers explicitly do NOT want GLib linked
Suggested change
} else {
println!("cargo:rustc-link-lib=dylib={}", lib_name);
}
} else {
println!("cargo:warning={} not found via pkg-config; using sysroot headers only", lib_name);
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Comment thread webrtc-sys/build.rs
Comment on lines +179 to +181
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());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 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.

Suggested change
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());
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant