Add fallback library names (#2230)

This commit is contained in:
Codotaku 2023-06-17 12:25:24 +01:00 committed by GitHub
parent 638f72279b
commit 3fdf75a727
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -60,25 +60,38 @@ impl VulkanLibrary {
#[cfg(not(target_os = "ios"))] #[cfg(not(target_os = "ios"))]
fn def_loader_impl() -> Result<Box<dyn Loader>, LoadingError> { fn def_loader_impl() -> Result<Box<dyn Loader>, LoadingError> {
#[cfg(windows)] #[cfg(windows)]
fn get_path() -> &'static Path { fn get_paths() -> [&'static Path; 1] {
Path::new("vulkan-1.dll") [Path::new("vulkan-1.dll")]
} }
#[cfg(all(unix, not(target_os = "android"), not(target_os = "macos")))] #[cfg(all(unix, not(target_os = "android"), not(target_os = "macos")))]
fn get_path() -> &'static Path { fn get_paths() -> [&'static Path; 1] {
Path::new("libvulkan.so.1") [Path::new("libvulkan.so.1")]
} }
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
fn get_path() -> &'static Path { fn get_paths() -> [&'static Path; 3] {
Path::new("libvulkan.1.dylib") [
Path::new("libvulkan.dylib"),
Path::new("libvulkan.1.dylib"),
Path::new("libMoltenVK.dylib"),
]
} }
#[cfg(target_os = "android")] #[cfg(target_os = "android")]
fn get_path() -> &'static Path { fn get_paths() -> [&'static Path; 2] {
Path::new("libvulkan.so") [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<LoadingError> = 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) def_loader_impl().and_then(VulkanLibrary::with_loader)