Uploaded image for project: 'Swift'
  1. Swift
  2. SR-13813

The Platform struct in PackageDescription should be Equatable

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Medium
    • Resolution: Done
    • Component/s: Package Manager
    • Labels:
      None

      Description

      In my project, I want to only build an SPM target when the platform I'm building for is not .wasi. For that, I've wrote the following code:

      // This list should be updated whenever SwiftPM adds support for a new platform.
      let supportedPlatforms: [Platform] = [
          .macOS,
          .iOS,
          .watchOS,
          .tvOS,
          .linux,
          .android,
          .windows,
          .wasi,
      ]
      
      extension Array where Element: Equatable {
          func except(_ exceptions: [Element]) -> [Element] {
              return filter { platform in
                  !exceptions.contains(platform)
              }
          }
      }
      

      I expected that I could write:

      .target(name: "WASIIncompatibleTarget",
              condition: .when(platforms: supportedPlatforms.except([.wasi])))
      

      However, that didn't work because Platform is not Equatable. I see no reason why it shouldn't conform to that protocol, and propose that we fix it.

        Attachments

          Activity

            People

            Assignee:
            max.desiatov Max Desiatov
            Reporter:
            broadway_lamb Sergej Jaskiewicz
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: