SwiftUI tries to compile SwiftPM packages not included in target, causing build failures during preview

Number:rdar://FB7615076 Date Originated:3/5/2020
Status:Open Resolved:
Product:SwiftUI Product Version:Xcode 11.3.1
Classification:Bug Reproducible:Always
Please describe the issue:

Got complaints from a bunch of users that a mac-only API was trying to compile during SwiftUI previews for Swift PM even if they were not importing or even including the framework which had mac-only API within it. After investigating, it appears all frameworks included in a SwiftPM package are compiled when running SwiftUI previews, even if they are not imported or included within the target. 

Please list the steps you took to reproduce the issue:

1. Create new Swift UI project
2. From repo https://github.com/apollographql/apollo-ios.git, at version exactly 0.23.1, add only the `Apollo` framework to the target. 
3. `import Apollo` into any SwiftUI view. 
4. Attempt to preview the SwiftUI view. 
5. Build fails due to use of a macOS-only API in the `ApolloCodegenLib` library, which has not been included in the project, and is not a dependency of the `Apollo` lib. 

What did you expect to happen?

Only frameworks included in the target using SwiftUI (or any of its dependencies) will be compiled for iOS when previewing for Swift UI. 

What actually happened?

Had to move @available runtime checks to #if os(macOS) compiler directives for framework intended for macOS, so that this issue would stop. 

[attached a copy of a project that already has the specified version of the lib added via SPM]


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!