Metal based Package Targets

Hi, do we have any update on when SPM will be able to fully support Metal targets?

As it stands, you can quite far by creating a package with three targets:

  1. Renderer (PublicSwift module with dependencies on 2 and 3)
  2. ShaderLibrary (Swift target which also includes .metal files and code for setting up a MTLLibrary. Dependency on 3)
  3. ShaderTypes (C Target which includes .h header file with types shared between the CPU and GPU)

However, there are a couple of big issues with this set-up:

  1. I haven't been successful in finding a way for the .metal files to be able to include source from the ShaderTypes module with the expected #import "<ShaderTypes/ShaderTypes.h>". You need to do a relative import #import "../ShaderTypes/include/ShaderTypes.h" which isn't ideal.
  2. It's not possible to profile shader code as raised in this post Can't profile Metal shaders within a package.

Perhaps this is something that could be taken care of with a new Swift Package plugin, but then it would need to somehow prevent/cancel the system .metallib build and also ensure the appropriate flags are set as the Metal library evolves.

2 Likes