Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-14786] Can't build a multi-platform Swift Package with a platform-specific dependency #4412

Open
swift-ci opened this issue Jun 16, 2021 · 5 comments
Labels

Comments

@swift-ci
Copy link
Contributor

Previous ID SR-14786
Radar rdar://problem/79401147
Original Reporter darrarski (JIRA User)
Type Bug
Environment

Apple Swift version 5.4 (swiftlang-1205.0.26.9 clang-1205.0.19.55) that comes with Xcode 12.5 (12E262)

macOS Big Sur 11.4 (20F71)

Additional Detail from JIRA
Votes 1
Component/s Package Manager
Labels Bug
Assignee None
Priority Medium

md5: 7d1dd3f8d0e24cc9189b0198a0636522

Issue Description:

I have a Swift Package that supports multiple platforms (iOS and tvOS in my case).

The package contains a single library product, build from a target that depends on platform-specific dependency.

Despite adding a condition property to the platform-specific dependency, I can only build the library for the platform supported by the dependency.

My Package.swift looks like this:

// swift-tools-version:5.4
import PackageDescription

let package = Package(
  name: "Demo",
  platforms: [
    .iOS(.v14),
    .tvOS(.v14),
  ],
  products: [
    .library(
      name: "Demo",
      targets: ["Demo"]
    ),
  ],
  dependencies: [
    .package(
      name: "Firebase",
      url: "https://github.com/firebase/firebase-ios-sdk.git",
      .exact("8.1.1")
    ),
  ],
  targets: [
    .target(
      name: "Demo",
      dependencies: [
        .product(
          name: "FirebaseAnalytics",
          package: "Firebase",
          condition: .when(platforms: [.iOS])
        ),
      ]
    ),
    .testTarget(
      name: "DemoTests",
      dependencies: [
        .target(name: "Demo")
      ]
    ),
  ]
)

Note that FirebaseAnalytics is used here as an example of a dependency that supports a single platform - in this case, it's iOS.

The package builds correctly for iOS, but fails to build for tvOS with the following error:

[...]/FirebaseAnalytics.xcframework:1:1: While building for tvOS Simulator, no library for this platform was found in '[...]/FirebaseAnalytics.xcframework'.

It looks like condition: .when(platforms: [.iOS]) is ignored for some reason.

Here you can find an example project that reproduces the issue:

https://github.com/darrarski/spm-platform-specific-dependecy-demo

@typesanitizer
Copy link

@swift-ci create

@swift-ci
Copy link
Contributor Author

Comment by Mike Achtelik (JIRA)

Is there any workaround or plan to fix this? It's still a problem in Swift 5.5 which comes with Xcode 13.1.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 4, 2022
@alexsereno
Copy link

alexsereno commented Jan 28, 2024

Also running into this issue several years later. Are there any workarounds or ongoing solutions? This breaks previews for vision and watchOS as well.

It seems like this might be a dupe of #5866

#5866 (comment)

Wherein this comment indicates that the issue is resolved for SPM but not in XCode. Can someone verify this? If so, it’s an old post from literally years ago, I’d like to verify that the issue is XCode dependent and that Apple has just sat on the issue for this long

@neonichu

@neonichu
Copy link
Member

neonichu commented Jan 29, 2024

If you're seeing an issue with previews specifically, the problem is most likely different from this and specific to Xcode.

@alexsereno
Copy link

alexsereno commented Jan 29, 2024

If you're seeing an issue with previews specifically, the problem is most likely different from this and specific to Xcode.

Thanks for the fast reply - seems like previews will try to build for vision and watchOS even if the package doesn't support the platform (firebase analytics is a common one) and gives this error message. I'll respond to the open ticket I have with Apple asserting this is SPM lol.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants