Dependency resolution w/ cross-platform frameworks

Suppose I have a workspace (or a project with subproject, it doesn't matter) which builds an iOS and a watchOS app. Both the iOS app and the watchOS extension needs a (cross-platform, i.e. compilable for iOS, watchOS, and tvOS) framework foo.framework. Building the iOS app works fine, however the watchOS extension does not find the include files nor the framework itself (since it gets built only once in the <scheme>-iphonesimulator directory). Obviously Xcode does not detect that although the respective framework has been built, it needs to be built _again_ (or copied over) to the <scheme>-watchsimulator directory.


Is there any way I can either force the framework to be built once for every app (thus putting it into the proper directory) or alternatively a way to put it into a "common" location so that it can be built only once and found by both the iOS and the watchOS portions?

Answered by QuinceyMorris in 222491022

One problem is that Apple doesn't support multiple platforms in a single framework bundle. If you want to share the code in iOS, watchOS and tvOS, you'll need 3 frameworks, which means 3 build products, which means 3 targets.


Another problem is that Xcode only supports one platform per target. It has to adapt its editing environment according to platform (e.g. editing a tvOS storyboard is different from editing an iOS storyboard), and it has to look at the target to determine the platform.


It's not hard to imagine these things changing in the future, but for now you're stuck with the housekeeping overhead of maintaining targets for different platforms in parallel.

You won't be able to compile the framework once for all platforms, since there are differences between watchOS and iOS - different CPU architectures, different load commands in the MachO header, and so on, that necessitate compilation per platform. You should configure the project so that you have a framework target per platform, with the SUPPORTED_PLATFORMS build setting set for each target. An example showing this setup is found as the Cross-Platform Sprite Kit Game target when creating a new project in Xcode.

I understand the platform differences and understood that compiling it multiple times is necessary (fat binaries to the rescue), still I don't see why the same framework does not get compiled multiple times by Xcode. That looks like it does not look at the current architecture, but just whether it has been built (once) or not.

Accepted Answer

One problem is that Apple doesn't support multiple platforms in a single framework bundle. If you want to share the code in iOS, watchOS and tvOS, you'll need 3 frameworks, which means 3 build products, which means 3 targets.


Another problem is that Xcode only supports one platform per target. It has to adapt its editing environment according to platform (e.g. editing a tvOS storyboard is different from editing an iOS storyboard), and it has to look at the target to determine the platform.


It's not hard to imagine these things changing in the future, but for now you're stuck with the housekeeping overhead of maintaining targets for different platforms in parallel.

Dependency resolution w/ cross-platform frameworks
 
 
Q