I've created a Swift Package for a metal-backed Core Image Filter that generates Simplex Noise and (both simple and fractal). The issue that I have is a Metal file that contains a Core Image Filter must be compiled with the -fcikernel flag and then linked with the -cikernel flag in order to work correctly with CIKernel's init(functionName:fromMetalLibraryData:)
I've accomplished this in my own projects by following the guidelines in the Build Metal-based Core Image kernels with Xcode from WWDC20. This involves naming the source files with a ".ci.metal" extension and then putting in a build rule that takes files that extension and uses the correct flag to create a ".ci.air" file which is then linked into a metallib using the appropriate linker flag in a second custom build rule.
Thus far, I have not determined a way to accomplish this in a Swift Package short of asking the end user to create the special build rules themselves in my README file, which is a terrible idea because my library would be broken unless the user took fairly complex additional steps in their project.
I settled on the temporary solution of just including the final "SimplexNoise.ci.metallib" as a package resource because it's only 7kb. However, this is not a great solution either, because I have to separately recompile and update the metallib file any time I want to make changes to the metal source code.
My dream would be to somehow include my custom build rules along with my library so that the metallib file could be created at build time in the user's project, but I have not found anything in the Swift Package documentation to even hint that such a thing is possible.
Does anyone have any ideas?
I've accomplished this in my own projects by following the guidelines in the Build Metal-based Core Image kernels with Xcode from WWDC20. This involves naming the source files with a ".ci.metal" extension and then putting in a build rule that takes files that extension and uses the correct flag to create a ".ci.air" file which is then linked into a metallib using the appropriate linker flag in a second custom build rule.
Thus far, I have not determined a way to accomplish this in a Swift Package short of asking the end user to create the special build rules themselves in my README file, which is a terrible idea because my library would be broken unless the user took fairly complex additional steps in their project.
I settled on the temporary solution of just including the final "SimplexNoise.ci.metallib" as a package resource because it's only 7kb. However, this is not a great solution either, because I have to separately recompile and update the metallib file any time I want to make changes to the metal source code.
My dream would be to somehow include my custom build rules along with my library so that the metallib file could be created at build time in the user's project, but I have not found anything in the Swift Package documentation to even hint that such a thing is possible.
Does anyone have any ideas?