Skip to content

Commit

Permalink
fix: removes explicit erroring when compiling on a future swift versi…
Browse files Browse the repository at this point in the history
…on (#528)

* fix: removes explicit erroring when compiling on a future swift version

* Updates function names"
  • Loading branch information
epau authored Feb 20, 2023
1 parent 4d843d4 commit 1f80a30
Showing 1 changed file with 79 additions and 7 deletions.
86 changes: 79 additions & 7 deletions Sources/ClientRuntime/Util/SwiftVersion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,29 @@
// SPDX-License-Identifier: Apache-2.0
//

/// Returns the swift version of the compiler that is compiling this application.
public var swiftVersion: String {
#if swift(>=5.8)
#error("""
Cannot use a version of Swift greater than available. \
Please create a Github issue for us to add support for the version of Swift you want to use.
"""
)
/**
Unfortunately there isn't a way to grab the compiled swift programmatically and so we must resot to the compiler directives to produce a version string.
We are checking for quite a few versions in the future, that may never exist, in order to future proof our current SDKs. Ideally, all current SDKs should compile
on future Swift versions unless that Swift version introduces a breaking change.

TODO add handling for Swift 8.x versions when Swift 6.0 is released.
*/
return swift5Version()
?? swift6Version()
?? swift7Version()
?? "unknown"
}


fileprivate func swift5Version() -> String? {
#if swift(>=6.0)
return nil
#elseif swift(>=5.9)
return "5.9"
#elseif swift(>=5.8)
return "5.8"
#elseif swift(>=5.7)
return "5.7"
#elseif swift(>=5.6)
Expand All @@ -29,6 +45,62 @@ public var swiftVersion: String {
#elseif swift(>=5.0)
return "5.0"
#else
#error("Cannot use a version of Swift less than 5.0")
return nil
#endif
}

fileprivate func swift6Version() -> String? {
#if swift(>=7.0)
return nil
#elseif swift(>=6.9)
return "6.9"
#elseif swift(>=6.8)
return "6.8"
#elseif swift(>=6.7)
return "6.7"
#elseif swift(>=6.6)
return "6.6"
#elseif swift(>=6.5)
return "6.5"
#elseif swift(>=6.4)
return "6.4"
#elseif swift(>=6.3)
return "6.3"
#elseif swift(>=6.2)
return "6.2"
#elseif swift(>=6.1)
return "6.1"
#elseif swift(>=6.0)
return "6.0"
#else
return nil
#endif
}

fileprivate func swift7Version() -> String? {
#if swift(>=8.0)
return nil
#elseif swift(>=7.9)
return "7.9"
#elseif swift(>=7.8)
return "7.8"
#elseif swift(>=7.7)
return "7.7"
#elseif swift(>=7.6)
return "7.6"
#elseif swift(>=7.5)
return "7.5"
#elseif swift(>=7.4)
return "7.4"
#elseif swift(>=7.3)
return "7.3"
#elseif swift(>=7.2)
return "7.2"
#elseif swift(>=7.1)
return "7.1"
#elseif swift(>=7.0)
return "7.0"
#else
return nil
#endif
}

0 comments on commit 1f80a30

Please sign in to comment.