Swift package setup for a metal renderer

Hey everyone,

I have been working on a Metal Renderer and I would like to set this up as a Swift Package. However I am running into some issues with setting up the package and I have not been able to find a solution, so I thought I'd give it a shot here.

To keep it simple, in my project I have a .swift file doing the rendering, a .metal file that contains my shader code and a .h file (which is a bridging header in my project) which contains stuff like Types to be shared between the metal shaders and the swift code.

I am stuck of how I can include the .h and .metal files in the swift package. Right now the swift file doesn't pick up on the stuff inside the header file and the metal file is just loaded with errors as if it doesn't recognize the file type. Ideally I would also like to expose this header to the outside.

Has anyone ever done something like this, or know if this is even possible?

Thanks in advance, and kind regards
  • I wonder if there are any updates for this for swift-tools-version:5.5 (October 2021). I'd like to put metal shaders in a Swift package.

Add a Comment

Replies

With the help of this thread here: https://developer.apple.com/forums/thread/649579 I was able to do this. Specifically the three-part comment from annca.

However, I did have to compromise by removing the bridging header, and creating a Swift file with the duplicate enumerations and structures from the bridging header.

  • In the package, do you have a .h file containing types for the metal shaders? Or did you just paste the types into the .metal shader files? I tried the former, but I don't think the .h file was being picked up my the .metal or the .swift files. Maybe I need to say something in the Package.swift to tell it about the .h file.

Add a Comment