xcodebuild for non-macOS target with macOS tool dependencies

I have a fun problem.

I have a Catalyst app which builds for iOS, macOS and tvOS.

The app target in Xcode depends on a command line tool target, also in Xcode.

The command line tool target is actually kind of a dummy, but it pulls in some other dependencies via SPM, which causes SPM to build the real command line tool am using. The Xcode target mostly just exists to cause this build to happen, but also does a bit of other stuff via a run script phase.

When I build (or archive) this for a non-macOS architecture in Xcode, it does the right thing. The main application builds using the sdk for the selected architecture (eg iOS), but the dependent tool builds with the sdk for macOS. The SPM dependencies inherit this sdk and do TheRightThing™.

As part of my automated release process, I archive using xcodebuild. To get the iOS version of the application to build, I am using -sdk iphoneos.

Unfortunately, the dependent tool target chooses to honour this setting too, and attempts to build itself for iOS. This in turn causes the SPM dependencies to try to build for iOS - and fail.

Is there a better way to tell xcodebuild which architecture to build? I'm not sure if it's strictly speaking a build that all of the targets are trying to use the sdk I passed in on the command line, but it feels as though it probably is. Either way, can anyone think of a workaround.

I am seeing this behaviour with Xcode 12b1. Unfortunately I can't go back to try it on 11.6 right now because the SPM package is using some Swift 5.3 features (specifically, resources).
Answered by Developer Tools Engineer in 615348022
It appears that there's an issue with the output of -showdestinations which causes it to not properly report the eligible destination you can use for archive builds. Try this destination: -destination generic/platform=iOS.
I think using -destination instead of -sdk could help with this. Although, I am kind of surprised that we would ever build an executable target in a package for anything other than macOS.
I tried with --destination, using various combinations of platform=iOS, id=dvtdevice-DVTiPhonePlaceholder-iphoneos:placeholder and name=Any iOS Device.

Unfortunately that device shows up in the list of ineligible destinations for the scheme, and produces this output:


xcodebuild: error: Unable to find a destination matching the provided destination specifier:

{ id:dvtdevice-DVTiPhonePlaceholder-iphoneos:placeholder }



The requested device could not be found because no available devices matched the request.




I'm not sure if it's strictly speaking a build that all of the 

That was supposed to say "a bug" rather than "a build". Autocorrect + lateness...
Accepted Answer
It appears that there's an issue with the output of -showdestinations which causes it to not properly report the eligible destination you can use for archive builds. Try this destination: -destination generic/platform=iOS.
Funnily enough I had just discovered the generic/ option here.

It did the trick - thanks!


Apparently the link in my previous reply didn't post properly. For anyone who was curious, I came across the information that I needed in a blog called xcodebuild-destination-options, on a site called mokacoding.
xcodebuild for non-macOS target with macOS tool dependencies
 
 
Q