Is it currently possible to use SPM plugins with Xcode?

I'm wondering if anyone had successfully used SPM plugins with Xcode. It seems there is some support to it, since I've managed to apply a plugin before building a macOS target, however, when trying to do the same for iOS, the plugin fails.
I also can't find any example in the wild, it seems not even SwiftGen is using plugins, although I was hoping they do, since the example in the proposal was targeting SwiftGen directly.

So, bottom line would be, does anyone know if this is fully implemented and I should invest more time in it making it work or should I just focus on distributing my tools via homebrew + Xcode scripts like in the past?

I had a issue where the executable products where built for iOS.

I managed to work around it by splitting out the plugins dependencies (in my case only executable targets) into a separate repository/package, that only provides a artifact-bundle introduce with swift-evolution/ at main · apple/swift-evolution · GitHub

that repository provides a github release from which the artifact bundle can be downloaded.

Here the plugin adds a dependency on a binaryTarget swift-dependency-injection/Package.swift at b458e6db36ee74a5277139d1a25ddad77d005476 · anreitersimon/swift-dependency-injection · GitHub

Hope this helps,


Also here is a command plugin that helps with creating the artifact bundle

Yeah, that's one problem for sure. I'll try the .binaryTarget path too. Thanks for the input.

I can confirm this works. It's way less convenient than referencing other executable targets, but hopefully Xcode will fix this soon.

Yeah agree its a bit inconvenient.

But i think i will stick with that setup anyways, even if this problem is solved.

It has some advantages IMO:

  • It reduces buildtime because consumers dont have to build my cli tools dependencies
  • it avoid some dependency conflicts (I for instance use SwiftSyntax if a consumer of the plugin wants to use a different version SwiftPM would currently not be able to do that)
1 Like

I can use them in xcode 14 beta 4 now but do not seam to find a way to properly use pre build commands. I made an example project here GitHub - doozMen/SPMPlugin: Basic setup for SPM buildTool plugins for xcode and SPM targets and found this GitHub - icanzilb/DoNilDisturbPlugin: A plugin for your Xcode project that stops you from working outside work hours also helpfull