Skip to content

Commit 10558ce

Browse files
authored
Add support for Swift 5.7 (#527)
1 parent bf256b9 commit 10558ce

File tree

8 files changed

+48
-39
lines changed

8 files changed

+48
-39
lines changed

.github/workflows/test.yml

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,9 @@ jobs:
1515
strategy:
1616
fail-fast: false
1717
matrix:
18-
xcode: ["13.4.1", "13.3.1", "13.2.1"]
18+
xcode: ["14.0.1"]
1919
include:
20-
- xcode: "13.4.1"
21-
macos: macOS-12
22-
- xcode: "13.3.1"
23-
macos: macOS-12
24-
- xcode: "13.2.1"
20+
- xcode: "14.0.1"
2521
macos: macOS-12
2622
runs-on: ${{ matrix.macos }}
2723
name: macOS
@@ -57,14 +53,11 @@ jobs:
5753
strategy:
5854
fail-fast: false
5955
matrix:
60-
swift: ["5.6", "5.5"]
56+
swift: ["5.7"]
6157
include:
62-
- swift: "5.6"
63-
container: "swift:5.6"
64-
cache-version: 2
65-
- swift: "5.5"
66-
container: "swift:5.5"
67-
cache-version: 2
58+
- swift: "5.7"
59+
container: "swift:5.7"
60+
cache-version: 1
6861
runs-on: ubuntu-20.04
6962
container: ${{ matrix.container }}
7063
name: Linux

Package.resolved

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1-
// swift-tools-version:5.3
1+
// swift-tools-version:5.5
22
import PackageDescription
33

4-
#if compiler(>=5.6)
5-
let swiftSyntaxVersion: Package.Dependency.Requirement = .exact("0.50600.1-static")
6-
#elseif compiler(>=5.5)
7-
let swiftSyntaxVersion: Package.Dependency.Requirement = .exact("0.50500.0-static")
4+
#if os(macOS)
5+
private let staticSwiftSyntax = true
6+
#else
7+
private let staticSwiftSyntax = false
8+
#endif
9+
10+
#if compiler(>=5.7)
11+
let swiftSyntaxVersion: Version = "0.50700.0"
12+
let staticInternalSwiftSyntaxParserVersion = "5.7"
13+
let staticInternalSwiftSyntaxParserChecksum = "99803975d10b2664fc37cc223a39b4e37fe3c79d3d6a2c44432007206d49db15"
814
#else
9-
fatalError("This version of Periphery requires Swift >= 5.5.")
15+
fatalError("This version of Periphery requires Swift >= 5.7 to build from source.")
1016
#endif
1117

1218
var dependencies: [Package.Dependency] = [
@@ -15,7 +21,7 @@ var dependencies: [Package.Dependency] = [
1521
.package(url: "https://github.com/tadija/AEXML", from: "4.0.0"),
1622
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.0.0"),
1723
.package(name: "SwiftIndexStore", url: "https://github.com/kateinoigakukun/swift-indexstore", from: "0.0.0"),
18-
.package(name: "SwiftSyntax", url: "https://github.com/peripheryapp/swift-syntax", swiftSyntaxVersion)
24+
.package(name: "SwiftSyntax", url: "https://github.com/apple/swift-syntax.git", .exact(swiftSyntaxVersion))
1925
]
2026

2127
#if os(macOS)
@@ -43,21 +49,23 @@ var peripheryKitDependencies: [PackageDescription.Target.Dependency] = [
4349
.product(name: "SystemPackage", package: "swift-system"),
4450
.product(name: "AEXML", package: "AEXML"),
4551
.product(name: "SwiftSyntax", package: "SwiftSyntax"),
52+
.product(name: "SwiftSyntaxParser", package: "SwiftSyntax"),
4653
.product(name: "SwiftIndexStore", package: "SwiftIndexStore")
4754
]
48-
49-
#if compiler(>=5.6)
50-
peripheryKitDependencies.append(.product(name: "SwiftSyntaxParser", package: "SwiftSyntax"))
51-
#endif
55+
+ (staticSwiftSyntax ? ["lib_InternalSwiftSyntaxParser"] : [])
5256

5357
var targets: [PackageDescription.Target] = [
54-
.target(
58+
.executableTarget(
5559
name: "Frontend",
5660
dependencies: frontendDependencies
5761
),
5862
.target(
5963
name: "PeripheryKit",
60-
dependencies: peripheryKitDependencies
64+
dependencies: peripheryKitDependencies,
65+
// Pass `-dead_strip_dylibs` to ignore the dynamic version of `lib_InternalSwiftSyntaxParser`
66+
// that ships with SwiftSyntax because we want the static version from
67+
// `StaticInternalSwiftSyntaxParser`.
68+
linkerSettings: staticSwiftSyntax ? [.unsafeFlags(["-Xlinker", "-dead_strip_dylibs"])] : []
6169
),
6270
.target(
6371
name: "Shared",
@@ -143,6 +151,11 @@ targets.append(contentsOf: [
143151
.target(name: "XcodeSupport")
144152
],
145153
exclude: ["UIKitProject", "SwiftUIProject"]
154+
),
155+
.binaryTarget(
156+
name: "lib_InternalSwiftSyntaxParser",
157+
url: "https://github.com/keith/StaticInternalSwiftSyntaxParser/releases/download/\(staticInternalSwiftSyntaxParserVersion)/lib_InternalSwiftSyntaxParser.xcframework.zip",
158+
checksum: staticInternalSwiftSyntaxParserChecksum
146159
)
147160
])
148161
#endif

Sources/PeripheryKit/SwiftVersion.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Shared
44
public struct SwiftVersion {
55
public static let current = Self()
66

7-
static let minimumVersion = "5.5"
7+
static let minimumVersion = "5.6"
88

99
public let version: VersionString
1010
public let fullVersion: String

Sources/PeripheryKit/Syntax/DeclarationVisitor.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ final class DeclarationVisitor: PeripherySyntaxVisitor {
308308
private func typeLocations(for clause: ReturnClauseSyntax?) -> Set<SourceLocation> {
309309
guard let returnTypeSyntax = clause?.returnType else { return [] }
310310

311-
if let someReturnType = returnTypeSyntax.as(SomeTypeSyntax.self) {
311+
if let someReturnType = returnTypeSyntax.as(ConstrainedSugarTypeSyntax.self) {
312312
return typeSyntaxInspector.typeLocations(for: someReturnType.baseType)
313313
}
314314

Sources/PeripheryKit/Syntax/TypeSyntaxInspector.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ struct TypeSyntaxInspector {
3535
} else if let dictType = typeSyntax.as(DictionaryTypeSyntax.self) {
3636
// Dictionary type.
3737
return typeLocations(for: dictType.keyType).union(typeLocations(for: dictType.valueType))
38-
} else if let someType = typeSyntax.as(SomeTypeSyntax.self) {
38+
} else if let someType = typeSyntax.as(ConstrainedSugarTypeSyntax.self) {
3939
// Some type.
4040
return typeLocations(for: someType.baseType)
4141
} else if let implicitUnwrappedOptionalType = typeSyntax.as(ImplicitlyUnwrappedOptionalTypeSyntax.self) {

Tests/PeripheryTests/SwiftVersionParserTest.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,8 @@ class SwiftVersionParserTest: XCTestCase {
1515

1616
let v4 = try SwiftVersionParser.parse("swift-driver version: 1.26.5 Apple Swift version 5.5 (swiftlang-1300.0.24.13 clang-1300.0.25.10)\nTarget: x86_64-apple-macosx11.0")
1717
XCTAssertEqual(v4, "5.5")
18+
19+
let v5 = try SwiftVersionParser.parse("swift-driver version: 1.62.8 Apple Swift version 5.7 (swiftlang-5.7.0.127.4 clang-1400.0.29.50)\nTarget: arm64-apple-macosx12.0")
20+
XCTAssertEqual(v5, "5.7")
1821
}
1922
}

Tests/PeripheryTests/Syntax/TypeSyntaxInspectorTest.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ private class TypeSyntaxInspectorTestVisitor: SyntaxVisitor {
154154

155155
override func visit(_ node: FunctionDeclSyntax) -> SyntaxVisitorContinueKind {
156156
if let returnTypeSyntax = node.signature.output?.returnType {
157-
if let someTypeSyntax = returnTypeSyntax.as(SomeTypeSyntax.self) {
157+
if let someTypeSyntax = returnTypeSyntax.as(ConstrainedSugarTypeSyntax.self) {
158158
addResult(for: someTypeSyntax.baseType)
159159
} else {
160160
addResult(for: returnTypeSyntax)

0 commit comments

Comments
 (0)