From 01ce268bfdae89078674894fe617a28753f2e3bd Mon Sep 17 00:00:00 2001 From: Jochen Kiemes Date: Tue, 9 Dec 2025 13:03:19 +0100 Subject: [PATCH] load metallib not only as resource but in root of a bundle --- mlx/backend/metal/device.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/mlx/backend/metal/device.cpp b/mlx/backend/metal/device.cpp index 65cd32d30f..736aaf8c6b 100644 --- a/mlx/backend/metal/device.cpp +++ b/mlx/backend/metal/device.cpp @@ -57,6 +57,16 @@ MTL::Library* try_load_bundle( MTL::Device* device, NS::URL* url, const std::string& lib_name) { + std::string path = + std::string(url->fileSystemRepresentation()) + + "/" + lib_name + ".metallib"; + + auto [lib, error] = load_library_from_path(device, path.c_str()); + if (lib) { + return lib; + } + + // url contains already the resource path. Why to rebuild it here again ? std::string bundle_path = std::string(url->fileSystemRepresentation()) + "/" + SWIFTPM_BUNDLE + ".bundle"; auto bundle = NS::Bundle::alloc()->init( @@ -115,6 +125,11 @@ std::pair load_swiftpm_library( if (library != nullptr) { return {library, nullptr}; } + // MetalCompilerPlugin does not generate a resource, but puts it into the bundle + library = try_load_bundle(device, bundle->bundleURL(), lib_name); + if (library != nullptr) { + return {library, nullptr}; + } } // if SWIFTPM_BUNDLE is a framework identifier, try loading from that auto frameworks = NS::Bundle::allFrameworks();