We have a project that supports both iOS and tvOS. We have common code and code per platform. To make everything work we are using EXCLUDED_SOURCE_FILE_NAMES and INCLUDED_SOURCE_FILE_NAMES build settings for [sdk=appletv*] and [sdk=iphone*] respectively (4 combinations). Our development flow requires that we expose our code as a local swift package.
Looking at the Package syntax, I found the following drawbacks:
We have the sources and exclude properties on Target, but they can't be customized per sdk.
We're using the build settings such that we first exclude files and then include some of them back. Afaik you can't do that on Target.
There are some conditional c, cxx, swift and linker settings inside Target but the above build settings don't fall in either category.
I guess one workaround could be to have 2 separate targets for the tv and phone platforms.
But question still holds - is there a way to specify generic build settings inside Package.swift? And are the statements of the above drawbacks correct?
There are two approaches that I could recommend that would solve your problem, both of which involve forgetting about manual source file includes and excludes.
Solution 1
Use conditional compilation and file naming pattern to compose a multi-platform module that will work equally well regardless of build system limitations:
MyFeature~iOS.swift:
#if os(iOS)
/* ... */
#endif
MyFeature~tvOS.swift:
#if os(tvOS)
/* ... */
#endif
Pros:
Easy to set up and scale up with support for more platforms.
Very flexible, can have code that is common between some of the platforms, but not all.
Cons:
Noticeable boilerplate.
Large multi-purpose module.
Solution 2
Split the single module into 4 pieces, subdividing their responsibilities, and allowing each piece to be built only when necessary: