Skip to content

Commit 3e9e420

Browse files
Ganesh Jangirepau
andauthored
fix: removes explicit erroring when compiling on a future swift version (#528) (#529)
* fix: removes explicit erroring when compiling on a future swift version * Updates function names" Co-authored-by: Ed Paulosky <[email protected]>
1 parent f59ed07 commit 3e9e420

File tree

1 file changed

+79
-7
lines changed

1 file changed

+79
-7
lines changed

Packages/ClientRuntime/Sources/Util/SwiftVersion.swift

Lines changed: 79 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,29 @@
55
// SPDX-License-Identifier: Apache-2.0
66
//
77

8+
/// Returns the swift version of the compiler that is compiling this application.
89
public var swiftVersion: String {
9-
#if swift(>=5.8)
10-
#error("""
11-
Cannot use a version of Swift greater than available. \
12-
Please create a Github issue for us to add support for the version of Swift you want to use.
13-
"""
14-
)
10+
/**
11+
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.
12+
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
13+
on future Swift versions unless that Swift version introduces a breaking change.
14+
15+
TODO add handling for Swift 8.x versions when Swift 6.0 is released.
16+
*/
17+
return swift5Version()
18+
?? swift6Version()
19+
?? swift7Version()
20+
?? "unknown"
21+
}
22+
23+
24+
fileprivate func swift5Version() -> String? {
25+
#if swift(>=6.0)
26+
return nil
27+
#elseif swift(>=5.9)
28+
return "5.9"
29+
#elseif swift(>=5.8)
30+
return "5.8"
1531
#elseif swift(>=5.7)
1632
return "5.7"
1733
#elseif swift(>=5.6)
@@ -29,6 +45,62 @@ public var swiftVersion: String {
2945
#elseif swift(>=5.0)
3046
return "5.0"
3147
#else
32-
#error("Cannot use a version of Swift less than 5.0")
48+
return nil
49+
#endif
50+
}
51+
52+
fileprivate func swift6Version() -> String? {
53+
#if swift(>=7.0)
54+
return nil
55+
#elseif swift(>=6.9)
56+
return "6.9"
57+
#elseif swift(>=6.8)
58+
return "6.8"
59+
#elseif swift(>=6.7)
60+
return "6.7"
61+
#elseif swift(>=6.6)
62+
return "6.6"
63+
#elseif swift(>=6.5)
64+
return "6.5"
65+
#elseif swift(>=6.4)
66+
return "6.4"
67+
#elseif swift(>=6.3)
68+
return "6.3"
69+
#elseif swift(>=6.2)
70+
return "6.2"
71+
#elseif swift(>=6.1)
72+
return "6.1"
73+
#elseif swift(>=6.0)
74+
return "6.0"
75+
#else
76+
return nil
77+
#endif
78+
}
79+
80+
fileprivate func swift7Version() -> String? {
81+
#if swift(>=8.0)
82+
return nil
83+
#elseif swift(>=7.9)
84+
return "7.9"
85+
#elseif swift(>=7.8)
86+
return "7.8"
87+
#elseif swift(>=7.7)
88+
return "7.7"
89+
#elseif swift(>=7.6)
90+
return "7.6"
91+
#elseif swift(>=7.5)
92+
return "7.5"
93+
#elseif swift(>=7.4)
94+
return "7.4"
95+
#elseif swift(>=7.3)
96+
return "7.3"
97+
#elseif swift(>=7.2)
98+
return "7.2"
99+
#elseif swift(>=7.1)
100+
return "7.1"
101+
#elseif swift(>=7.0)
102+
return "7.0"
103+
#else
104+
return nil
33105
#endif
34106
}

0 commit comments

Comments
 (0)