From 0b9cfb6af3e0b4709c65cb0cb794f961ff3930b5 Mon Sep 17 00:00:00 2001 From: Dmitry Sharshakov Date: Thu, 30 Dec 2021 17:03:41 +0300 Subject: [PATCH] Search for different versions of libwayland Workaround for distributions that do not have symlinks for Wayland libraries Signed-off-by: Dmitry Sharshakov --- wgpu-hal/src/gles/egl.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/wgpu-hal/src/gles/egl.rs b/wgpu-hal/src/gles/egl.rs index 1b50d22af4..f1c7695355 100644 --- a/wgpu-hal/src/gles/egl.rs +++ b/wgpu-hal/src/gles/egl.rs @@ -114,20 +114,30 @@ fn open_x_display() -> Option<(ptr::NonNull, libloading::Library)> } } +unsafe fn find_library(paths: &[&str]) -> Option { + for path in paths { + match libloading::Library::new(path) { + Ok(lib) => return Some(lib), + _ => continue, + }; + } + None +} + fn test_wayland_display() -> Option { /* We try to connect and disconnect here to simply ensure there * is an active wayland display available. */ log::info!("Loading Wayland library to get the current display"); let library = unsafe { - let client_library = libloading::Library::new("libwayland-client.so").ok()?; + let client_library = find_library(&["libwayland-client.so.0", "libwayland-client.so"])?; let wl_display_connect: libloading::Symbol = client_library.get(b"wl_display_connect").unwrap(); let wl_display_disconnect: libloading::Symbol = client_library.get(b"wl_display_disconnect").unwrap(); let display = ptr::NonNull::new(wl_display_connect(ptr::null()))?; wl_display_disconnect(display.as_ptr()); - libloading::Library::new("libwayland-egl.so").ok()? + find_library(&["libwayland-egl.so.1", "libwayland-egl.so"])? }; Some(library) }