Skip to content

Commit

Permalink
Search for different versions of libwayland
Browse files Browse the repository at this point in the history
Workaround for distributions that do not have symlinks for Wayland libraries

Signed-off-by: Dmitry Sharshakov <d3dx12.xx@gmail.com>
  • Loading branch information
dsseng authored and kvark committed Dec 30, 2021
1 parent 276de0e commit 52f11d8
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions wgpu-hal/src/gles/egl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,20 +114,30 @@ fn open_x_display() -> Option<(ptr::NonNull<raw::c_void>, libloading::Library)>
}
}

unsafe fn find_library(paths: &[&str]) -> Option<libloading::Library> {
for path in paths {
match libloading::Library::new(path) {
Ok(lib) => return Some(lib),
_ => continue,
};
}
None
}

fn test_wayland_display() -> Option<libloading::Library> {
/* 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<WlDisplayConnectFun> =
client_library.get(b"wl_display_connect").unwrap();
let wl_display_disconnect: libloading::Symbol<WlDisplayDisconnectFun> =
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)
}
Expand Down

0 comments on commit 52f11d8

Please sign in to comment.