From c6d5d66142ff58a2f2d8b1561117e2d3a01f5596 Mon Sep 17 00:00:00 2001 From: MarijnS95 Date: Mon, 3 Aug 2020 11:19:42 +0200 Subject: [PATCH] entry_libloading: Provide Vulkan library loader from custom path (#319) It is in some cases necessary to load a specific Vulkan dll/so with a different name and/or from a different location. Instead of copying this function to a downstream project (and making the LoadingError constructor public to retain the same interface), split Entry::new() such that downstream projects can easily specify and use an alternate Vulkan implementation. --- ash/src/entry_libloading.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/ash/src/entry_libloading.rs b/ash/src/entry_libloading.rs index edf2e4e..9e3f893 100644 --- a/ash/src/entry_libloading.rs +++ b/ash/src/entry_libloading.rs @@ -1,6 +1,7 @@ use crate::entry::EntryCustom; use libloading::Library; use std::error::Error; +use std::ffi::OsStr; use std::fmt; use std::ptr; use std::sync::Arc; @@ -39,6 +40,8 @@ impl Error for LoadingError { } impl EntryCustom> { + /// Load default Vulkan library for the current platform + /// /// ```rust,no_run /// use ash::{vk, Entry, version::EntryV1_0}; /// # fn main() -> Result<(), Box> { @@ -55,9 +58,12 @@ impl EntryCustom> { /// # Ok(()) } /// ``` pub fn new() -> Result { - let lib = Library::new(&LIB_PATH) - .map_err(LoadingError) - .map(Arc::new)?; + Self::with_library(&LIB_PATH) + } + + /// Load Vulkan library at `path` + pub fn with_library>(path: &P) -> Result { + let lib = Library::new(path).map_err(LoadingError).map(Arc::new)?; Ok(Self::new_custom(lib, |vk_lib, name| unsafe { vk_lib