Skip to content

Conditional dependencies break PackLib.Planner #154

In progress

Description

@kabiroberai

Description

When using a package that has conditionally-included dependencies (such as dependencies that are pulled in iff a Package Trait is enabled), Planner will try to resolve them unconditionally. If the dependency isn't actually pulled in by SwiftPM, then, Planner will fail here:

guard let packageID = packagesByProductName[productName] else {
throw StringError("Could not find package containing product '\(productName)'")
}

To repro: try adding a dependency on https://github.com/pointfreeco/swift-structured-queries @ v0.11.0. We end up with the error Could not find package containing product 'Tagged', because Planner doesn't know that the Tagged dependency is only required when the StructuredQueriesTagged trait is enabled (and in this case the trait is disabled.)

Environment

Host OS: Ubuntu 24.04.3 LTS
Swift version: swift-6.1-RELEASE
SDK version: iOS 18.5

Activity

  1. added
    bug
    on Aug 10, 2025
  2. kabiroberai commented on Aug 10, 2025

    @kabiroberai
    MemberAuthor

    This might not be trivial to fix. Running

    swift package --package-path .build/checkouts/swift-structured-queries -q describe --type json

    revelas

    // ...
    {
      "c99name" : "StructuredQueriesCore",
      "module_type" : "SwiftTarget",
      "name" : "StructuredQueriesCore",
      "path" : "Sources/StructuredQueriesCore",
      "product_dependencies" : [
        "IssueReporting",
        "Tagged" // !!
      ],
      // ...
    }

    observe that Tagged is listed as a dependency without any extra qualification regarding traits, even though the actual Package.swift has a condition on the dependency.

    We do get this information when replacing swift package describe with swift package dump-package so maybe there's a world where we switch to the latter. However describe is a more stable format and is generally preferable to consume from my experience, so we might need to take some sort of mixed/hybrid approach here. dump-package output:

    "dependencies" : [
      {
        "product" : [
          "IssueReporting",
          "xctest-dynamic-overlay",
          null,
          null
        ]
      },
      {
        "product" : [
          "Tagged",
          "swift-tagged",
          null,
          {
            "platformNames" : [
    
            ],
            "traits" : [
              "StructuredQueriesTagged"
            ]
          }
        ]
      }
    ],
  3. chintan100 commented on Oct 9, 2026

    @chintan100
    Contributor

    I couldn't reproduce this with Swift 6.4 (Xcode 27) on current main (d802c71): planning succeeds for a package that depends on swift-structured-queries 0.11.0. SwiftPM 6.4's describe no longer lists trait-gated dependencies when the trait is off (StructuredQueriesCore now reports only IssueReporting), and swift-tagged isn't resolved at all, so Planner never looks for Tagged. I've only tested macOS, but since the Linux install guide now requires 6.4 too, this may be safe to close.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions