Closed
Description
Previous ID | SR-2535 |
Radar | rdar://problem/28253354 |
Original Reporter | @kevints |
Type | Bug |
Status | Resolved |
Resolution | Done |
Additional Detail from JIRA
Votes | 0 |
Component/s | Package Manager |
Labels | Bug |
Assignee | None |
Priority | Medium |
md5: 9a8cd848cb1275b3f7fcb018080fd12e
Issue 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.