Skip to content

Commit 2540efe

Browse files
authored
Remove default link-time dependency on GLib (#1144)
### Before you submit your PR Make sure the following is true before submitting your PR: - [x] I have read the [contributing guidelines](https://github.com/livekit/rust-sdks/blob/main/CONTRIBUTING.md) and validated that this PR will be accepted. - [x] I have read and followed the principles regarding breaking changes, testing, and code quality. ### PR Description The webrtc-sys build script used pkg_config::probe_library for glib-2.0/gobject-2.0/gio-2.0, which emitted cargo:rustc-link-lib directives even though only the headers are required at build time. Switch to pkg_config::Config::new().cargo_metadata(false) so the include paths are still discovered but no link metadata is emitted. Drop glib-main-loop from libwebrtc's default features and re-expose it as an opt-in passthrough on the top-level livekit crate. The screensharing example enables it explicitly. Note that the original change (ca86d4c) was somewhat broken on arrival, since it did not provide any way for a `livekit` consumer to opt out of the internal GLib main loop. Fixes: #1129 ### Breaking changes Consumers of `livekit` or `libwebrtc` that rely on Wayland screen sharing must now enable the `glib-main-loop` feature (if they do not have their own GLib main loop). ### MSRV No change. ### Testing Validated that a trivial crate that depends on `livekit` no longer pulls in `glib` as a dependency. Built a cdylib on Linux aarch64 in a build environment where the linker does not use `--as-needed` (or it simply does not work as expected), and validated that the resulting binary does not include library dependencies on GLib. See the [build artifacts](https://github.com/foxglove/foxglove-sdk/actions/runs/27042873647) from foxglove/foxglove-sdk#1292 (`lib/libfoxglove.so`).
1 parent 527aba5 commit 2540efe

5 files changed

Lines changed: 27 additions & 6 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
webrtc-sys: patch
3+
libwebrtc: minor
4+
livekit: minor
5+
---
6+
7+
# Make GLib an opt-in dependency
8+
9+
`webrtc-sys` no longer links against `glib-2.0`/`gobject-2.0`/`gio-2.0` by default.
10+
11+
Breaking: Wayland screen sharing now requires the `glib-main-loop` feature on `livekit` (or `libwebrtc`).

examples/screensharing/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ publish = false
77
[dependencies]
88
tokio = { workspace = true, features = ["full"] }
99
env_logger = { workspace = true }
10-
livekit = { workspace = true, features = ["rustls-tls-native-roots"] }
10+
livekit = { workspace = true, features = ["glib-main-loop", "rustls-tls-native-roots"] }
1111
livekit-api = { workspace = true }
1212
log = { workspace = true }
1313
clap = { workspace = true, features = ["derive"] }

libwebrtc/Cargo.toml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ description = "Livekit safe bindings to libwebrtc"
88
repository.workspace = true
99

1010
[features]
11-
default = [ "glib-main-loop" ]
11+
default = []
12+
1213
# On Wayland, libwebrtc uses GDBus to communicate with the XDG Desktop Portal.
13-
# GDBus requires a GLib event loop to be running. If you already have a GLib
14-
# event loop running in your application, for example if you are using the
15-
# GTK or GStreamer Rust bindings, disable this feature.
14+
# GDBus requires a GLib event loop to be running. Enable this feature if you
15+
# wish to use screensharing, and you do not already have a GLib event loop
16+
# running in your application.
1617
glib-main-loop = [ "dep:glib" ]
1718

1819
[dependencies]

livekit/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ async = ["livekit-api/signal-client-async"]
1515
tokio = ["livekit-api/signal-client-tokio"]
1616
dispatcher = ["livekit-api/signal-client-dispatcher"]
1717

18+
# On Wayland, libwebrtc uses GDBus to communicate with the XDG Desktop Portal.
19+
# GDBus requires a GLib event loop to be running. Enable this feature if you
20+
# wish to use screensharing, and you do not already have a GLib event loop
21+
# running in your application.
22+
glib-main-loop = [ "libwebrtc/glib-main-loop" ]
1823

1924
# Note that the following features only change the behavior of tokio-tungstenite.
2025
# It doesn't change the behavior of libwebrtc/webrtc-sys

webrtc-sys/build.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,12 @@ fn main() {
175175
// In order to avoid any ABI mismatches we use the sysroot's headers.
176176
add_gio_headers(&mut builder);
177177

178+
// Do not use pkg_config::probe_library, because we only require headers.
178179
for lib_name in ["glib-2.0", "gobject-2.0", "gio-2.0"] {
179-
pkg_config::probe_library(lib_name).unwrap();
180+
let lib = pkg_config::Config::new().cargo_metadata(false).probe(lib_name).unwrap();
181+
for path in lib.include_paths {
182+
builder.include(path);
183+
}
180184
}
181185

182186
add_lazy_load_so(

0 commit comments

Comments
 (0)