Xcodebuild, Plugins and Platforms
October 11, 2024

For quite a while, I’ve experienced what I thought was a bug when using xcodebuild to build projects for iOS (or any non-macOS platform), if the project or one of its dependencies used a Swift Package Manager plugin.

I typically invoked the build with something like this:

xcodebuild archive -scheme MyProject -sdk iphonesimulator -destination 'generic/platform=iOS Simulator' -archivePath "archives/MyProject-iOS_Simulator"

The build would seem to be working, but would fail because the plugin was being built against the iphonesimulator SDK, and not against the macOS one.

This puzzled me, and for a long time I thought that it was a bug, and so eventually I got round to reporting it.

It turns out that this is expected behaviour: applying -sdk iphonesimulator will force that SDK for all targets, including plugins.

The trick here is just to omit that argument. The -destination argument is sufficient to tell Xcode which sdk to use for the targets that will actually end up as part of the built products, but allows it to also choose the correct sdk (macOS) for any plugins.

I’m not certain, but I also suspect that this mistake of mine stemmed from the fact that I’ve been using xcodebuild since long before the -destination argument existed, and certainly since the generic/platform= pattern existed, and so I hadn’t really considered that it was sufficient.

« What Next?
Got a comment on this post? Let us know at @elegantchaos@mastodon.scot.