Let BuildToolPlugin replace default build rules

It would be great if a BuildToolPlugin could specify that it replaces the default build rules for the files it handles.

Specifically, I want to put Metal kernels for Core Image into a package. They need to be compiled with certain compiler and linker flags. I figured I can now use a BuildToolPlugin to create a custom build step for those kernels. I found this example that does something similar. However, as also noted by them, the big annoyance here is that SPM will still process the .metal files with its default build rule, creating a default.metallib for the package.

As far as I know, there is no way of telling SPM to not also compile the .metal files that my plugin already handled. I thought a possible workaround would be to give the CI kernel files a different file extension like .ci, but the Metal compiler doesn't like that.

Is there a way to prevent SPM from running the default build rules for .metal files?


There's no way to do that today, but would you mind filing a GitHub issue asking for this?

1 Like

Sure, here it is: Let BuildToolPlugin replace default build rules · Issue #6124 · apple/swift-package-manager · GitHub

Thanks for looking into this!

1 Like