From bae8aa6e7df66d79e6aa5bad2a452c5b4307a9d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Mon, 16 Feb 2026 15:36:15 +0100 Subject: [PATCH] macOS: Fix Vulkan loader loading for Null platform --- src/CMakeLists.txt | 7 +++++-- src/cocoa_init.m | 35 ----------------------------------- src/cocoa_platform.h | 2 -- src/vulkan.c | 39 ++++++++++++++++++++++++++++++++++++--- 4 files changed, 41 insertions(+), 42 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index cf71feca..ab096c95 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -145,12 +145,10 @@ endif() if (GLFW_BUILD_COCOA) target_link_libraries(glfw PRIVATE "-framework Cocoa" "-framework IOKit" - "-framework CoreFoundation" "-framework QuartzCore") list(APPEND glfw_PKG_LIBS "-framework Cocoa" "-framework IOKit" - "-framework CoreFoundation" "-framework QuartzCore") endif() @@ -236,6 +234,11 @@ if (UNIX AND NOT APPLE) endif() endif() +if (APPLE) + target_link_libraries(glfw PRIVATE "-framework CoreFoundation") + list(APPEND glfw_PKG_LIBS "-framework CoreFoundation") +endif() + if (WIN32) if (GLFW_USE_HYBRID_HPG) target_compile_definitions(glfw PRIVATE _GLFW_USE_HYBRID_HPG) diff --git a/src/cocoa_init.m b/src/cocoa_init.m index 4b2094ca..95d6289e 100644 --- a/src/cocoa_init.m +++ b/src/cocoa_init.m @@ -450,41 +450,6 @@ static GLFWbool initializeTIS(void) @end // GLFWApplicationDelegate - -////////////////////////////////////////////////////////////////////////// -////// GLFW internal API ////// -////////////////////////////////////////////////////////////////////////// - -void* _glfwLoadLocalVulkanLoaderCocoa(void) -{ - CFBundleRef bundle = CFBundleGetMainBundle(); - if (!bundle) - return NULL; - - CFURLRef frameworksUrl = CFBundleCopyPrivateFrameworksURL(bundle); - if (!frameworksUrl) - return NULL; - - CFURLRef loaderUrl = CFURLCreateCopyAppendingPathComponent( - kCFAllocatorDefault, frameworksUrl, CFSTR("libvulkan.1.dylib"), false); - if (!loaderUrl) - { - CFRelease(frameworksUrl); - return NULL; - } - - char path[PATH_MAX]; - void* handle = NULL; - - if (CFURLGetFileSystemRepresentation(loaderUrl, true, (UInt8*) path, sizeof(path) - 1)) - handle = _glfwPlatformLoadModule(path); - - CFRelease(loaderUrl); - CFRelease(frameworksUrl); - return handle; -} - - ////////////////////////////////////////////////////////////////////////// ////// GLFW platform API ////// ////////////////////////////////////////////////////////////////////////// diff --git a/src/cocoa_platform.h b/src/cocoa_platform.h index a25d1b2b..175372d6 100644 --- a/src/cocoa_platform.h +++ b/src/cocoa_platform.h @@ -291,8 +291,6 @@ void _glfwRestoreVideoModeCocoa(_GLFWmonitor* monitor); float _glfwTransformYCocoa(float y); -void* _glfwLoadLocalVulkanLoaderCocoa(void); - GLFWbool _glfwInitNSGL(void); void _glfwTerminateNSGL(void); GLFWbool _glfwCreateContextNSGL(_GLFWwindow* window, diff --git a/src/vulkan.c b/src/vulkan.c index b52a57fc..03642a31 100644 --- a/src/vulkan.c +++ b/src/vulkan.c @@ -34,6 +34,40 @@ #define _GLFW_FIND_LOADER 1 #define _GLFW_REQUIRE_LOADER 2 +#if defined(__APPLE__) + +#include + +static void* loadLocalVulkanLoaderMacOS(void) +{ + CFBundleRef bundle = CFBundleGetMainBundle(); + if (!bundle) + return NULL; + + CFURLRef frameworksUrl = CFBundleCopyPrivateFrameworksURL(bundle); + if (!frameworksUrl) + return NULL; + + CFURLRef loaderUrl = CFURLCreateCopyAppendingPathComponent( + kCFAllocatorDefault, frameworksUrl, CFSTR("libvulkan.1.dylib"), false); + if (!loaderUrl) + { + CFRelease(frameworksUrl); + return NULL; + } + + char path[PATH_MAX]; + void* handle = NULL; + + if (CFURLGetFileSystemRepresentation(loaderUrl, true, (UInt8*) path, sizeof(path) - 1)) + handle = _glfwPlatformLoadModule(path); + + CFRelease(loaderUrl); + CFRelease(frameworksUrl); + return handle; +} + +#endif // __APPLE__ ////////////////////////////////////////////////////////////////////////// ////// GLFW internal API ////// @@ -57,11 +91,10 @@ GLFWbool _glfwInitVulkan(int mode) _glfw.vk.handle = _glfwPlatformLoadModule(_GLFW_VULKAN_LIBRARY); #elif defined(_WIN32) _glfw.vk.handle = _glfwPlatformLoadModule("vulkan-1.dll"); -#elif defined(_GLFW_COCOA) +#elif defined(__APPLE__) _glfw.vk.handle = _glfwPlatformLoadModule("libvulkan.1.dylib"); if (!_glfw.vk.handle) - _glfw.vk.handle = _glfwLoadLocalVulkanLoaderCocoa(); -#elif defined(__APPLE__) + _glfw.vk.handle = loadLocalVulkanLoaderMacOS(); #elif defined(__OpenBSD__) || defined(__NetBSD__) _glfw.vk.handle = _glfwPlatformLoadModule("libvulkan.so"); #else