Skip to content

Commit

Permalink
Merge pull request #211 from cashapp/bradfol/swift6
Browse files Browse the repository at this point in the history
Improve Swift 6 toolchain support
  • Loading branch information
bradfol authored Nov 5, 2024
2 parents 206b96c + 71672a4 commit 98fa6a0
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
with:
swift-version: "5.10"
- name: Checkout
uses: actions/checkout@v4.1.7
uses: actions/checkout@v4.2.2
- name: Create Release
run: |
set -euo pipefail
Expand Down
20 changes: 18 additions & 2 deletions .github/workflows/swift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,32 @@ on:
branches: [ "main" ]

jobs:
build-knit:
build-knit-swift-5:

runs-on: macos-latest

steps:
- uses: actions/checkout@v4.1.7
- uses: actions/checkout@v4.2.2
- uses: swift-actions/[email protected]
with:
swift-version: "5.10"
- name: Build Knit
run: swift build -v
- name: Run Knit tests
run: swift test -v

# Enable below when issue is resolved: https://github.com/swift-actions/setup-swift/issues/683

# build-knit-swift-6:
#
# runs-on: macos-latest
#
# steps:
# - uses: actions/[email protected]
# - uses: swift-actions/[email protected]
# with:
# swift-version: "6.0"
# - name: Build Knit
# run: swift build -v
# - name: Run Knit tests
# run: swift test -v
4 changes: 4 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,9 @@ let package = Package(
"KnitCodeGen",
]
),
],
swiftLanguageVersions: [
// When this SPM package is imported by a Swift 6 toolchain it should still be used in the v5 language mode
.v5,
]
)
4 changes: 2 additions & 2 deletions Sources/KnitCodeGen/AssemblyParsing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
//

import Foundation
import SwiftSyntax
import SwiftParser
@preconcurrency import SwiftSyntax
@preconcurrency import SwiftParser

class AssemblyFileVisitor: SyntaxVisitor, IfConfigVisitor {

Expand Down
4 changes: 2 additions & 2 deletions Sources/KnitCodeGen/Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
import Foundation
import SwiftSyntax

public struct Configuration: Encodable {
public struct Configuration: Encodable, Sendable {

/// Name of the module for this configuration.
public var assemblyName: String
public let moduleName: String
public var directives: KnitDirectives

public enum AssemblyType: String, Encodable {
public enum AssemblyType: String, Encodable, Sendable {
/// `Swinject.Assembly`
case moduleAssembly = "ModuleAssembly"
case autoInitAssembly = "AutoInitModuleAssembly"
Expand Down
2 changes: 1 addition & 1 deletion Sources/KnitCodeGen/FunctionCallRegistrationParsing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//

import Foundation
import SwiftSyntax
@preconcurrency import SwiftSyntax

struct CalledMethod {

Expand Down
12 changes: 6 additions & 6 deletions Sources/KnitCodeGen/KnitDirectives.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import Foundation
import SwiftSyntax

public struct KnitDirectives: Codable, Equatable {
public struct KnitDirectives: Codable, Equatable, Sendable {
var accessLevel: AccessLevel?
var getterConfig: Set<GetterConfig>
var moduleName: String?
Expand Down Expand Up @@ -131,16 +131,16 @@ extension KnitDirectives {
}
}

public enum GetterConfig: Codable, Equatable, Hashable {
public enum GetterConfig: Codable, Equatable, Hashable, Sendable {
/// Only the `callAsFunction()` accessor is generated.
case callAsFunction
/// Only the identified getter is generated.
case identifiedGetter(_ name: String?)

/// Centralized control of the default behavior.
public static var `default`: Set<GetterConfig> = [.identifiedGetter(nil)]
public static let `default`: Set<GetterConfig> = [.identifiedGetter(nil)]

public static var both: Set<GetterConfig> = [.callAsFunction, .identifiedGetter(nil)]
public static let both: Set<GetterConfig> = [.callAsFunction, .identifiedGetter(nil)]

public var isNamed: Bool {
switch self {
Expand All @@ -150,12 +150,12 @@ public enum GetterConfig: Codable, Equatable, Hashable {
}
}

public enum AccessLevel: String, CaseIterable, Codable {
public enum AccessLevel: String, CaseIterable, Codable, Sendable {
case `public`
case `internal`
case hidden
case ignore

/// Centralized control of the default behavior.
public static var `default`: AccessLevel = .internal
public static let `default`: AccessLevel = .internal
}
4 changes: 2 additions & 2 deletions Sources/KnitCodeGen/ModuleImport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
//

import Foundation
import SwiftSyntax
@preconcurrency import SwiftSyntax

public struct ModuleImport {
public struct ModuleImport: Sendable {
let decl: ImportDeclSyntax
let ifConfigCondition: ExprSyntax?
let name: String
Expand Down
10 changes: 5 additions & 5 deletions Sources/KnitCodeGen/Registration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// Copyright © Block, Inc. All rights reserved.
//

import SwiftSyntax
@preconcurrency import SwiftSyntax

public struct Registration: Equatable, Codable {
public struct Registration: Equatable, Codable, Sendable {

public var service: String

Expand Down Expand Up @@ -63,7 +63,7 @@ public struct Registration: Equatable, Codable {

extension Registration {

public struct Argument: Equatable, Codable {
public struct Argument: Equatable, Codable, Sendable {

let identifier: Identifier
let type: String
Expand All @@ -77,7 +77,7 @@ extension Registration {
self.type = type
}

public enum Identifier: Codable, Equatable {
public enum Identifier: Codable, Equatable, Sendable {
/// Used for arguments defined in `.register` registrations.
case fixed(String)

Expand All @@ -87,7 +87,7 @@ extension Registration {

}

public enum FunctionName: String, Codable {
public enum FunctionName: String, Codable, Sendable {
case register
case autoregister
case registerAbstract
Expand Down
2 changes: 1 addition & 1 deletion Sources/KnitCodeGen/RegistrationIntoCollection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/// Represents a single concrete factory registered into a collection
/// A separate instance will be created for each call to `{auto}registerIntoCollection`
public struct RegistrationIntoCollection: Equatable {
public struct RegistrationIntoCollection: Equatable, Sendable {

public var service: String

Expand Down

0 comments on commit 98fa6a0

Please sign in to comment.