Using build tool plugins with .xcproj

Hi, not sure if this is Xcode specific or not. But I’m using Xcode version 13.3 (13E113), and have successfully created a little build tool plugin in one of my Swift packages, which generates Swift code for files ending in a specific extension.

I have an iOS app that I want to use to run the code generation with, but it’s using an .xcodeproj, and so xcodebuild as the build system. Does anyone know if it can take advantage of these build tool plugins? The release notes read:

Swift Packages now support build tool plugins, as defined in SE-0303 and SE-0325. This allows packages to define plugins that can specify tools that should run during a build operation, for example to generate source code. This is supported in both swift package and in Xcode’s support for packages. (79876749)

I can see the plugin in the sidebar:

Clicking on the arrow reveals the plugin file in finder. I can’t see Xcode actually attempting to run the build tool plugin.

From what I can tell, only build tool plugins show up in that package plugins section, i.e. command plugins don’t appear.

And if you do add a build tool plugin via a Package.swift file, then Xcode will translate it to a “run custom script” build step in xcodebuild. But once again, this is only if your project uses Package.swift and not a typical .xcodeproj, which seems to be a blocker for using these build tools with apps.

Currently, package plugins are a function only of Swift Packages, and are not related to Xcode projects. It should be possible to have an Xcode project that uses a local package that uses a build tool plugin, though.

And as you noted, command plugins are currently a feature only of the SwiftPM CLI.


From the Xcode 14 beta release notes:

  • Xcode now provides Swift Package plugins with an XcodeProjectPlugin API that extends the Swift Package Manager’s PackagePlugin API. Using this API, the plugin can get a simplified description of the Xcode project’s structure. This lets adapted plugins running in Xcode take advantage of using this API on Xcode projects. You can still use packages that haven’t been adapted to support Xcode projects with Swift Packages in Xcode. (88196725)

This looks exactly like what I’m looking for. Looking forward to trying it out!

Turns out this only seems to support command plugins for now. Hopefully build plugins will be supported at a later date!

Yep, see known issues in the release notes:

Build tool plugins that are adapted to support Xcode projects can’t yet be used with Xcode targets to generate source code and resources. This functionality is expected to be available in a future Xcode 14 beta. (92415898)