# Is it currently possible to use SPM plugins with Xcode?

**URL:** <https://forums.swift.org/t/is-it-currently-possible-to-use-spm-plugins-with-xcode/56969>\
**Category:** Using Swift\
**Tags:** packagemanager, plugins\
**Created:** [April 25, 2022, 7:42pm UTC](https://forums.swift.org/t/is-it-currently-possible-to-use-spm-plugins-with-xcode/56969 "2022-04-25T19:42:52Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![valentinradu](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/valentinradu/32/23005_2.png) [@valentinradu](https://forums.swift.org/u/valentinradu)\
**Post date:** [April 25, 2022, 7:42pm UTC](https://forums.swift.org/t/is-it-currently-possible-to-use-spm-plugins-with-xcode/56969/1 "2022-04-25T19:42:52Z")

</div>

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](https://github.com/SwiftGen/SwiftGen/blob/stable/Package.swift) 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?

---

<div class="post-metadata">

**Author:** ![anreitersimon](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/anreitersimon/32/7269_2.png) [@anreitersimon](https://forums.swift.org/u/anreitersimon)\
**Post date:** [April 25, 2022, 8:02pm UTC](https://forums.swift.org/t/is-it-currently-possible-to-use-spm-plugins-with-xcode/56969/2 "2022-04-25T20:02:47Z")

</div>

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/0305-swiftpm-binary-target-improvements.md at main · apple/swift-evolution · GitHub](https://github.com/apple/swift-evolution/blob/main/proposals/0305-swiftpm-binary-target-improvements.md)

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

[https://github.com/anreitersimon/swift-dependency-injection-cli/releases/tag/1.0.0](https://github.com/anreitersimon/swift-dependency-injection-cli/releases/tag/1.0.0)

Here the plugin adds a dependency on a `binaryTarget` [swift-dependency-injection/Package.swift at b458e6db36ee74a5277139d1a25ddad77d005476 · anreitersimon/swift-dependency-injection · GitHub](https://github.com/anreitersimon/swift-dependency-injection/blob/b458e6db36ee74a5277139d1a25ddad77d005476/Package.swift#L25)

Hope this helps,

Simon

---

<div class="post-metadata">

**Author:** ![anreitersimon](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/anreitersimon/32/7269_2.png) [@anreitersimon](https://forums.swift.org/u/anreitersimon)\
**Post date:** [April 25, 2022, 8:04pm UTC](https://forums.swift.org/t/is-it-currently-possible-to-use-spm-plugins-with-xcode/56969/3 "2022-04-25T20:04:45Z")

</div>

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

> **[GitHub - anreitersimon/swift-package-utils](https://github.com/anreitersimon/swift-package-utils)**
>
> Contribute to anreitersimon/swift-package-utils development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![valentinradu](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/valentinradu/32/23005_2.png) [@valentinradu](https://forums.swift.org/u/valentinradu)\
**Post date:** [April 25, 2022, 8:53pm UTC](https://forums.swift.org/t/is-it-currently-possible-to-use-spm-plugins-with-xcode/56969/4 "2022-04-25T20:53:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![valentinradu](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/valentinradu/32/23005_2.png) [@valentinradu](https://forums.swift.org/u/valentinradu)\
**Post date:** [April 25, 2022, 11:28pm UTC](https://forums.swift.org/t/is-it-currently-possible-to-use-spm-plugins-with-xcode/56969/5 "2022-04-25T23:28:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![anreitersimon](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/anreitersimon/32/7269_2.png) [@anreitersimon](https://forums.swift.org/u/anreitersimon)\
**Post date:** [April 26, 2022, 6:41am UTC](https://forums.swift.org/t/is-it-currently-possible-to-use-spm-plugins-with-xcode/56969/6 "2022-04-26T06:41:09Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![doozMen](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/doozmen/32/7803_2.png) [@doozMen](https://forums.swift.org/u/doozMen)\
**Post date:** [July 28, 2022, 10:54am UTC](https://forums.swift.org/t/is-it-currently-possible-to-use-spm-plugins-with-xcode/56969/7 "2022-07-28T10:54:02Z")

</div>

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](https://github.com/doozMen/SPMPlugin) and found this [GitHub - icanzilb/DoNilDisturbPlugin: A plugin for your Xcode project that stops you from working outside work hours](https://github.com/icanzilb/DoNilDisturbPlugin) also helpfull
