XcodeGen icon indicating copy to clipboard operation
XcodeGen copied to clipboard

Using 'supportedDestinations' with watchOS app doesn't generate an 'Embed Watch Content' build phase

Open FelixLisczyk opened this issue 1 year ago • 12 comments

I'm currently in the process of migrating my project specs from platform to supportedDestinations. According to the project spec, this should work for all target types:

Note that the definition of supported destinations can be applied to every type of bundle making everything more easy to manage (app targets, unit tests, UI tests etc).

I've noticed when I configure my watch app target with supportedDestinations, XcodeGen no longer generates an 'Embed Watch Content' build phase for the iOS app. Here is an example:

name: MyApp
options:
  bundleIdPrefix: com.example
targets:
  UniversalApp:
    dependencies:
      - target: WatchApp
    supportedDestinations: [iOS, macOS]
    type: application
    sources:
      - Universal
  WatchApp:
    supportedDestinations: [watchOS]
    type: application
    sources:
      - Watch

Is this a bug or intended behavior? Should I continue to use platform for my watchOS targets? Thank you!

FelixLisczyk avatar Mar 23 '24 09:03 FelixLisczyk

I am also looking for an answer on this. The doc's aren't clear if watchOS is supported for supportedDestinations or not. It's not included in the list of supported destrinations but if watchOS isn't supported I was curious as to why and what our options are for including it?

bcardarella avatar Apr 06 '24 15:04 bcardarella

Perhaps it is fixed with https://github.com/yonaskolb/XcodeGen/pull/1438

bcardarella avatar Apr 06 '24 15:04 bcardarella

@atsuky do you have any info on this? Did your PR #1438 get this working? I've just added watchOS as a supported destination in the docs, as that PR missed that out

Also pinging @amatig as the original implementor of the supported destinations work, in case he has any insights

yonaskolb avatar Apr 07 '24 12:04 yonaskolb

Hi, thank you for the doc update. I'll take a look at the issue.

tatsuky avatar Apr 09 '24 04:04 tatsuky

Looks like the following part is causing the issue. https://github.com/yonaskolb/XcodeGen/blob/03017410027ba244f277e03e38d05d3d3c3544fd/Sources/XcodeGenKit/PBXProjGenerator.swift#L779-L780

platform is auto when supportedDestinations is set. I think it's why the "Embed Watch Content" phase gets skipped even if the destinations include watchOS.

I think we can fix it by also checking if supportedDestinations == [.watchOS] here. It's not supportedDestinations.contains(.watchOS) so that we can rule out the apps with e.g., supportedDestinations: [iOS, watchOS] just in case (I find this type of combination (watchOS + other destinations) uncommon for an application, though).

Let me know what you all think. I'll create a PR if this approach looks good.

tatsuky avatar Apr 09 '24 10:04 tatsuky

@tatsuky does this mean that it would skip watchos?

bcardarella avatar Apr 09 '24 11:04 bcardarella

@bcardarella By "it" do you mean:

so that we can rule out the apps with e.g., supportedDestinations: [iOS, watchOS] just in case

If so - it will just skip adding the "Embed Watch Content" phase for the target. The supportedDestinations will be kept as initially configured.


After reading Apple's Configuring a multiplatform app - apparently the watchOS destination for the multiplatform apps is not supported at the moment. The destination is also unavailable (not showing up) for a multiplatform app on Xcode 15.3.

Destination options for multiplatform apps on Xcode 15.3

Given this information & on second thought, we should maybe disallow the watchOS supportedDestination for an application instead of add the logic fix I mentioned in my previous comment?

tatsuky avatar Apr 09 '24 11:04 tatsuky

@tatsuky perhaps emmit a warning or error if it is included and point to this issue so understand why it isn't (yet) supported. Looking at the issue tracker and it seems to be a common question

bcardarella avatar Apr 09 '24 12:04 bcardarella

@tatsuky, I support the change to add the check for supportedDestinations == [.watchOS] when embedding watch content, as well as add an error for configuring a destination to be watchOS AND iOS, as well as highlighting that in the documentation. If you still want to create the PR that would be fantastic

yonaskolb avatar Apr 10 '24 01:04 yonaskolb

@yonaskolb Just to confirm, can we still add the changes you suggested, given Xcode 15.3 seemingly doesn't allow us to create multiplatform apps that contain the watchOS destination? (at least not on the UI, that is)

Alternatively, I think we could consider it as an invalid configuration and have xcodegen error out like @bcardarella suggested.

tatsuky avatar Apr 10 '24 02:04 tatsuky

@tatsuky yes agree. That's what I meant by an error when watchOS and iOS are in the same destinations array 👍

yonaskolb avatar Apr 10 '24 10:04 yonaskolb

OK, I'll work on the fix and open a PR one of these days

tatsuky avatar Apr 11 '24 07:04 tatsuky