Preserve Package platforms instead Destination.allCases for external dependencies

I would like for external dependencies to have default dependency caching only for those platforms that are explicitly specified in the external dependency’s Package.swift file or based on PackageSettings.productDestinations.

For some reason, when generating an Xcode project, PackageInfoMapper automatically sets all sorts of destinations for external dependencies, which seems a bit premature.

This also led to some bugs intermittently related to MacCatalyst support, causing some packages to fail to compile: GitHub · Where software is built


I also encountered this problem when trying to cache the SDK which is included via Tuist/Package.swift (via .package(path:))

Building scheme Binaries-Cache-iOS for Mac Catalyst
note: Using codesigning identity override: 
⚠️ Target 'VendorPlayerSDK' does not support any of the imposed platforms 'macosx' and a single platform could not be chosen from its own supported platforms 'appletvos appletvsimulator iphoneos iphonesimulator'. For backwards compatibility, it will be built for macOS.
...
...

❌ path/to/vendor-sdk/Modules/SomeModule/Source/Models/ActivityIndicatorComponentStyle.swift:8:8: no such module 'UIKit'

⚠️ `DERIVE_MACCATALYST_PRODUCT_BUNDLE_IDENTIFIER` is not supported. Remove the build setting and conditionalize `PRODUCT_BUNDLE_IDENTIFIER` instead. (in target 'Storage' from project 'VendorPlayerSDK')
⚠️ `DERIVE_MACCATALYST_PRODUCT_BUNDLE_IDENTIFIER` is not supported. Remove the build setting and conditionalize `PRODUCT_BUNDLE_IDENTIFIER` instead. (in target 'PlaylistModule' from project 'VendorPlayerSDK')

Hey :wave:

All Swift packages implicitly support all platforms – and there’s no way to opt-out of that. The platforms property of a package is only there to define the minimum supported version: Package — Swift Package Manager.

However, when caching and generating a project, the platforms of external dependencies should be stripped to the platforms included in downstream targets, such as your app. This logic happens in the ExternalProjectsPlatformNarrowerGraphMapper.

If Tuist is caching/generating dependencies for platforms not included in your own project, then there might be a bug. In which case, I’d suggest creating a GitHub issue with a reproducible sample.