Swift Package Manager, Metal shaders, bridging header?

Does the Swift Package Manager work with Metal shaders? I would like to move my app's code into an "[AppName]Support" package, so I can use DocC. I have two things I don't know how to handle in a package...

  1. The .metal files that I eventually load as mtlDevice.defaultLibrary().
  2. The bridging header that allows me to share some struct types between .swift and .metal files.

Can both of those be moved to a package?

There's some reference to how you can reference metal files from within SwiftPM on the Apple developer forums: Swift Package with Metal - it sounds like SwiftPM version 5.3 and later may have the support you want, but there are some caveats according to that forum post.

There's also a similar question (and answers) on StackOverflow that you might find useful as well.

1 Like

We do use some metal files in packages at my company, but there are some draw backs.

  • We can’t seem to get syntax highlighting and code completion to work inside metal files that reside in packages. We work around this by having a test Xcode project in the Swift Package repo that includes the metal shaders directly and do editing in that project, then compile our main app, which pulls in the Swift Package.
  • We have to do a bit of runscript hackery to profile/debug. You can read more here about how we do it: Can't profile Metal shaders within a package
1 Like

Thank you for the pointers guys. Since I've got my hands full already trying to learn Metal, I will avoid these extra complications for now, and leave the code in my app module.

Same here. However, I found things work great with regular Xcode framework targets. You still get modularity, just without the slickness of SPM.

Terms of Service

Privacy Policy

Cookie Policy