Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,41 +26,41 @@ jobs:
- macOS
- tvOS
- watchOS
xcode:
- "16.2"
- "16.4"
- "26.0"
include:
- xcode: "16.2"
swift: "6.0"
- xcode: "16.4"
swift: "6.1"
- xcode: "26.0"
swift: "6.2"
- visionOS
swift:
- "6.0"
- "6.1"
- "6.2"
steps:
- name: Git Checkout
uses: actions/checkout@v4
uses: actions/checkout@v5

- name: Disable SwiftSyntax Prebuilts
run: |
defaults write com.apple.dt.Xcode IDEPackageEnablePrebuilts -bool NO

# nuke cache to ensure it takes effect
rm -rf ~/Library/Developer/Xcode/DerivedData
rm -rf ~/Library/Developer/Xcode/SourcePackages
rm -rf ~/Library/Caches/org.swift.swiftpm

- name: Select Xcode version
uses: mxcl/xcodebuild@v3
with:
xcode: ~${{ matrix.xcode }}
swift: ~${{ matrix.swift }}
action: none
verbosity: xcbeautify

- name: Remove Derived Data
run: rm -rf ~/Library/Developer/Xcode/DerivedData

- if: ${{ matrix.platform != 'macOS' }}
name: Download Default Runtime
run: xcodebuild -downloadPlatform ${{ matrix.platform }}

- name: Test Library
uses: mxcl/xcodebuild@v3
with:
action: test
platform: ${{ matrix.platform }}
xcode: ~${{ matrix.xcode }}
swift: ~${{ matrix.swift }}
action: test
workspace: ObjCRuntimeTools.xcworkspace
scheme: ObjCRuntimeTools
verbosity: xcbeautify
19 changes: 11 additions & 8 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ let package = Package(
name: "objc-runtime-tools",
platforms: [
.iOS(.v13),
.macCatalyst(.v13),
.macOS(.v10_15),
.tvOS(.v13),
.visionOS(.v1),
.watchOS(.v6),
],
products: [
Expand All @@ -22,8 +24,7 @@ let package = Package(
"Swizzling",
]
),
],
swiftLanguageModes: [.v5] // disable strict concurrency checks for now
]
)

// MARK: Association
Expand All @@ -37,8 +38,6 @@ package.targets += [
.macro(
name: "AssociationMacro",
dependencies: [
.product(name: "SwiftSyntax", package: "swift-syntax"),
.product(name: "SwiftSyntaxBuilder", package: "swift-syntax"),
.product(name: "SwiftSyntaxMacros", package: "swift-syntax"),
.product(name: "SwiftCompilerPlugin", package: "swift-syntax"),
]
Expand All @@ -50,7 +49,6 @@ package.targets += [
"Association",
"AssociationMacro",
.product(name: "MacroTesting", package: "swift-macro-testing"),
.product(name: "SwiftCompilerPlugin", package: "swift-syntax"),
]
),
]
Expand All @@ -66,8 +64,6 @@ package.targets += [
.macro(
name: "SwizzlingMacro",
dependencies: [
.product(name: "SwiftSyntax", package: "swift-syntax"),
.product(name: "SwiftSyntaxBuilder", package: "swift-syntax"),
.product(name: "SwiftSyntaxMacros", package: "swift-syntax"),
.product(name: "SwiftCompilerPlugin", package: "swift-syntax"),
]
Expand All @@ -79,7 +75,6 @@ package.targets += [
"Swizzling",
"SwizzlingMacro",
.product(name: "MacroTesting", package: "swift-macro-testing"),
.product(name: "SwiftCompilerPlugin", package: "swift-syntax"),
]
),
]
Expand All @@ -88,3 +83,11 @@ package.dependencies += [
.package(url: "https://github.com/pointfreeco/swift-macro-testing", from: "0.6.0"),
.package(url: "https://github.com/swiftlang/swift-syntax", "600.0.0"..<"603.0.0"),
]

for target in package.targets {
target.swiftSettings = target.swiftSettings ?? []
target.swiftSettings? += [
.enableUpcomingFeature("ExistentialAny"),
.enableUpcomingFeature("InternalImportsByDefault"),
]
}
2 changes: 1 addition & 1 deletion Sources/Association/Policy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

import ObjectiveC.runtime
public import ObjectiveC.runtime

// A typealias for `objc_AssociationPolicy`.
public typealias Policy = objc_AssociationPolicy
Expand Down
14 changes: 5 additions & 9 deletions Sources/AssociationMacro/AssociatedMacro.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ import SwiftSyntax
import SwiftSyntaxBuilder
import SwiftSyntaxMacros

public struct AssociatedMacro {}
struct AssociatedMacro {}

extension AssociatedMacro: PeerMacro {
public static func expansion(
static func expansion(
of node: AttributeSyntax,
providingPeersOf declaration: some DeclSyntaxProtocol,
in context: some MacroExpansionContext
Expand Down Expand Up @@ -121,7 +121,7 @@ extension AssociatedMacro: PeerMacro {
}

extension AssociatedMacro: AccessorMacro {
public static func expansion(
static func expansion(
of node: AttributeSyntax,
providingAccessorsOf declaration: some DeclSyntaxProtocol,
in context: some MacroExpansionContext
Expand Down Expand Up @@ -391,9 +391,7 @@ extension AssociatedMacro {
signature: .init(
capture: .init {
ClosureCaptureSyntax(
expression: DeclReferenceExprSyntax(
baseName: .keyword(.`self`)
)
name: .keyword(.`self`)
)
},
parameterClause: .init(ClosureShorthandParameterListSyntax {
Expand Down Expand Up @@ -449,9 +447,7 @@ extension AssociatedMacro {
signature: .init(
capture: .init {
ClosureCaptureSyntax(
expression: DeclReferenceExprSyntax(
baseName: .keyword(.`self`)
)
name: .keyword(.`self`)
)
},
parameterClause: .init(ClosureShorthandParameterListSyntax {
Expand Down
2 changes: 1 addition & 1 deletion Sources/AssociationMacro/AssociatedMacroDiagnostic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import SwiftDiagnostics
import SwiftSyntax

public enum AssociatedMacroDiagnostic {
enum AssociatedMacroDiagnostic {
case requiresVariableDeclaration
case multipleVariableDeclarationIsNotSupported
case getterAndSetterShouldBeNil
Expand Down
2 changes: 1 addition & 1 deletion Sources/AssociationMacro/AssociatedMacrosPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import SwiftSyntaxMacros

@main
struct AssociatedMacrosPlugin: CompilerPlugin {
let providingMacros: [Macro.Type] = [
let providingMacros: [any Macro.Type] = [
AssociatedMacro.self,
]
}
4 changes: 2 additions & 2 deletions Sources/Swizzling/AnyHook.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
/// SOFTWARE.

import Foundation
public import Foundation

/// Base class, represents a hook to exactly one method.
public class AnyHook {
Expand All @@ -40,7 +40,7 @@ public class AnyHook {
var origIMP: IMP?

/// The possible task states
public enum State: Equatable {
public enum State: Equatable, Sendable {
/// The task is prepared to be swizzled.
case prepared

Expand Down
26 changes: 24 additions & 2 deletions Sources/Swizzling/Logging.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,33 @@

import Foundation

private final class Atomic<Value> {
private let lock = NSLock()
private var value: Value

init(_ value: Value) {
self.value = value
}

func withLock<R>(_ body: (inout Value) throws -> R) rethrows -> R {
lock.lock()
defer { lock.unlock() }
return try body(&value)
}
}

extension Atomic: @unchecked Sendable where Value: Sendable {}

// MARK: Logging

public enum Swizzling {
/// Logging uses print and is minimal.
public static var isLoggingEnabled = false
private static let loggingState = Atomic(false)

/// Logging uses print and is minimal. Stored in a lock to keep writes concurrency-safe.
public static var isLoggingEnabled: Bool {
get { loggingState.withLock { $0 } }
set { loggingState.withLock { $0 = newValue } }
}

/// Simple log wrapper for print.
static func log(_ object: Any) {
Expand Down
2 changes: 1 addition & 1 deletion Sources/Swizzling/Swizzle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
/// SOFTWARE.

import Foundation
public import Foundation

extension Swizzling {
/// Hook an `@objc dynamic` instance method via selector on the specified class..
Expand Down
4 changes: 3 additions & 1 deletion Sources/Swizzling/SwizzlingError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
/// SOFTWARE.

import Foundation
public import Foundation

/// The list of errors while hooking a method.
public enum SwizzlingError: LocalizedError {
Expand Down Expand Up @@ -99,3 +99,5 @@ extension SwizzlingError: Equatable {
return self
}
}

extension SwizzlingError: @unchecked Sendable {}
4 changes: 2 additions & 2 deletions Sources/SwizzlingMacro/SwizzleMacro.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import SwiftSyntax
import SwiftSyntaxBuilder
import SwiftSyntaxMacros

public struct SwizzleMacro: ExpressionMacro {
public static func expansion(
struct SwizzleMacro: ExpressionMacro {
static func expansion(
of node: some FreestandingMacroExpansionSyntax,
in context: some MacroExpansionContext
) throws -> ExprSyntax {
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwizzlingMacro/SwizzleMacrosPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import SwiftSyntaxMacros

@main
struct SwizzleMacrosPlugin: CompilerPlugin {
let providingMacros: [Macro.Type] = [
let providingMacros: [any Macro.Type] = [
SwizzleMacro.self,
]
}
5 changes: 1 addition & 4 deletions Tests/AssociationTests/AssociatedMacroTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,15 @@

#if canImport(AssociationMacro)
import MacroTesting
import SwiftSyntaxMacros
import SwiftSyntaxMacrosTestSupport
import Testing

@testable import Association
@testable import AssociationMacro

@Suite(
.macros(
["Associated": AssociatedMacro.self],
indentationWidth: .tab,
record: .never
record: .missing
)
)
struct AssociatedTests {
Expand Down
6 changes: 3 additions & 3 deletions Tests/SwizzlingTests/SwizzleMacroTests.swift
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#if canImport(SwizzlingMacro)
import MacroTesting
import Swizzling
import SwizzlingMacro
import Testing

@testable import SwizzlingMacro

@Suite(
.macros(
["swizzle": SwizzleMacro.self],
indentationWidth: .tab,
record: .failed
record: .missing
)
)
struct SwizzleMacroTests {}
Expand Down
1 change: 1 addition & 0 deletions Tests/SwizzlingTests/SwizzleTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ extension SwizzleTests {
}
}

@MainActor
@Suite(.serialized)
struct SwizzleLifetimeTests {
final class SUT: NSObject {
Expand Down
8 changes: 4 additions & 4 deletions Tests/TestPlans/ObjCRuntimeTools.xctestplan
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
{
"target" : {
"containerPath" : "container:",
"identifier" : "SwizzlingTests",
"name" : "SwizzlingTests"
"identifier" : "AssociationTests",
"name" : "AssociationTests"
}
},
{
"target" : {
"containerPath" : "container:",
"identifier" : "AssociationTests",
"name" : "AssociationTests"
"identifier" : "SwizzlingTests",
"name" : "SwizzlingTests"
}
}
],
Expand Down
Loading