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

[SwiftPM] Ability to control deployment target

    XMLWordPrintable

    Details

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

      Description

      On macOS, swift build hardcodes the swiftc flag

      -target x86_64-apple-macosx10.10

      This means that to write portable (macOS 10.11+ and Linux) code that uses a Foundation API introduced in macOS 10.11 we must convert the following straightforward code (2 module-level URL constants):

      import Foundation
      
      let baseURL: URL = ...
      let resourceURL = URL(fileURLWithPath: "path", relativeTo: baseURL)
      

      to this

      import Foundation
      
      let baseURL: URL = ...
      let resourceURL: URL
      #if !os(Linux)
          resourceURL = {
              guard #available(macOS 10.11, *) else {
                  fatalError("This program requires macOS 10.11 or greater.")
              }
              return URL(fileURLWithPath: "path", relativeTo: baseURL)
          }()
      #else
          resourceURL = URL(fileURLWithPath: "path", relativeTo: baseURL)
      #endif
      

      Swift packages should be able to specify a minimum target platform version. There's also the problem of the impedance mismatch - if we were allowed to do #if os(Linux) && available(macOS 10.11, *) the resourceURL assignment line would not need to be duplicated in each block.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              ksweeney Kevin Sweeney
            • Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: