From 3fdf75a7276d4cf92bfe5e3b82602e841d2de617 Mon Sep 17 00:00:00 2001 From: Codotaku <88196711+CodesOtakuYT@users.noreply.github.com> Date: Sat, 17 Jun 2023 12:25:24 +0100 Subject: [PATCH] Add fallback library names (#2230) --- vulkano/src/library.rs | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/vulkano/src/library.rs b/vulkano/src/library.rs index bf0d66ce..d31612e8 100644 --- a/vulkano/src/library.rs +++ b/vulkano/src/library.rs @@ -60,25 +60,38 @@ impl VulkanLibrary { #[cfg(not(target_os = "ios"))] fn def_loader_impl() -> Result, LoadingError> { #[cfg(windows)] - fn get_path() -> &'static Path { - Path::new("vulkan-1.dll") + fn get_paths() -> [&'static Path; 1] { + [Path::new("vulkan-1.dll")] } #[cfg(all(unix, not(target_os = "android"), not(target_os = "macos")))] - fn get_path() -> &'static Path { - Path::new("libvulkan.so.1") + fn get_paths() -> [&'static Path; 1] { + [Path::new("libvulkan.so.1")] } #[cfg(target_os = "macos")] - fn get_path() -> &'static Path { - Path::new("libvulkan.1.dylib") + fn get_paths() -> [&'static Path; 3] { + [ + Path::new("libvulkan.dylib"), + Path::new("libvulkan.1.dylib"), + Path::new("libMoltenVK.dylib"), + ] } #[cfg(target_os = "android")] - fn get_path() -> &'static Path { - Path::new("libvulkan.so") + fn get_paths() -> [&'static Path; 2] { + [Path::new("libvulkan.so.1"), Path::new("libvulkan.so")] } - let loader = unsafe { DynamicLibraryLoader::new(get_path())? }; + let paths = get_paths(); - Ok(Box::new(loader)) + let mut err: Option = None; + + for path in paths { + match unsafe { DynamicLibraryLoader::new(path) } { + Ok(library) => return Ok(Box::new(library)), + Err(e) => err = Some(e), + } + } + + Err(err.unwrap()) } def_loader_impl().and_then(VulkanLibrary::with_loader)