Skip to content

Commit bd49ee0

Browse files
committed
feat: Add additional platform checks
1 parent 5b90f0b commit bd49ee0

22 files changed

+132
-9
lines changed

Package.swift

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,20 @@
33
import PackageDescription
44
import CompilerPluginSupport
55

6+
let applePlatforms: [Platform] = [
7+
.iOS,
8+
.macOS,
9+
.macCatalyst,
10+
.watchOS,
11+
.tvOS,
12+
.visionOS
13+
]
14+
15+
let define_appleOS: SwiftSetting = .define(
16+
"appleOS",
17+
.when(platforms: applePlatforms)
18+
)
19+
620
let package = Package(
721
name: "swift-interception",
822
platforms: [
@@ -55,21 +69,38 @@ let package = Package(
5569
dependencies: [
5670
.target(name: "InterceptionMacrosPlugin"),
5771
.target(name: "_InterceptionCustomSelectors")
72+
],
73+
swiftSettings: [
74+
define_appleOS
75+
]
76+
),
77+
.target(
78+
name: "_InterceptionCustomSelectors",
79+
swiftSettings: [
80+
define_appleOS
5881
]
5982
),
60-
.target(name: "_InterceptionCustomSelectors"),
61-
.target(name: "_InterceptionUtilsObjc"),
6283
.target(
6384
name: "_InterceptionUtils",
6485
dependencies: [
65-
.target(name: "_InterceptionUtilsObjc"),
86+
.target(
87+
name: "_InterceptionUtilsObjc",
88+
condition: .when(platforms: applePlatforms)
89+
),
90+
],
91+
swiftSettings: [
92+
define_appleOS
6693
]
6794
),
95+
.target(name: "_InterceptionUtilsObjc"),
6896
.target(
6997
name: "Interception",
7098
dependencies: [
7199
.target(name: "_InterceptionCustomSelectors"),
72100
.target(name: "_InterceptionUtils"),
101+
],
102+
swiftSettings: [
103+
define_appleOS
73104
]
74105
),
75106
.target(
@@ -93,18 +124,27 @@ let package = Package(
93124
dependencies: [
94125
.target(name: "InterceptionMacrosPlugin"),
95126
.product(name: "MacroTesting", package: "swift-macro-testing"),
127+
],
128+
swiftSettings: [
129+
define_appleOS
96130
]
97131
),
98132
.testTarget(
99133
name: "InterceptionTests",
100134
dependencies: [
101135
.target(name: "Interception"),
136+
],
137+
swiftSettings: [
138+
define_appleOS
102139
]
103140
),
104141
.testTarget(
105142
name: "InterceptionMacrosTests",
106143
dependencies: [
107144
.target(name: "InterceptionMacros"),
145+
],
146+
swiftSettings: [
147+
define_appleOS
108148
]
109149
),
110150
],

Package@swift-5.9.swift

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,20 @@
33
import PackageDescription
44
import CompilerPluginSupport
55

6+
let applePlatforms: [Platform] = [
7+
.iOS,
8+
.macOS,
9+
.macCatalyst,
10+
.watchOS,
11+
.tvOS,
12+
.visionOS
13+
]
14+
15+
let define_appleOS: SwiftSetting = .define(
16+
"appleOS",
17+
.when(platforms: applePlatforms)
18+
)
19+
620
let package = Package(
721
name: "swift-interception",
822
platforms: [
@@ -55,21 +69,38 @@ let package = Package(
5569
dependencies: [
5670
.target(name: "InterceptionMacrosPlugin"),
5771
.target(name: "_InterceptionCustomSelectors")
72+
],
73+
swiftSettings: [
74+
define_appleOS,
75+
]
76+
),
77+
.target(
78+
name: "_InterceptionCustomSelectors",
79+
swiftSettings: [
80+
define_appleOS,
5881
]
5982
),
60-
.target(name: "_InterceptionCustomSelectors"),
61-
.target(name: "_InterceptionUtilsObjc"),
6283
.target(
6384
name: "_InterceptionUtils",
6485
dependencies: [
65-
.target(name: "_InterceptionUtilsObjc"),
86+
.target(
87+
name: "_InterceptionUtilsObjc",
88+
condition: .when(platforms: applePlatforms)
89+
),
90+
],
91+
swiftSettings: [
92+
define_appleOS,
6693
]
6794
),
95+
.target(name: "_InterceptionUtilsObjc"),
6896
.target(
6997
name: "Interception",
7098
dependencies: [
7199
.target(name: "_InterceptionCustomSelectors"),
72100
.target(name: "_InterceptionUtils"),
101+
],
102+
swiftSettings: [
103+
define_appleOS,
73104
]
74105
),
75106
.target(
@@ -93,18 +124,27 @@ let package = Package(
93124
dependencies: [
94125
.target(name: "InterceptionMacrosPlugin"),
95126
.product(name: "MacroTesting", package: "swift-macro-testing"),
127+
],
128+
swiftSettings: [
129+
define_appleOS,
96130
]
97131
),
98132
.testTarget(
99133
name: "InterceptionTests",
100134
dependencies: [
101135
.target(name: "Interception"),
136+
],
137+
swiftSettings: [
138+
define_appleOS,
102139
]
103140
),
104141
.testTarget(
105142
name: "InterceptionMacrosTests",
106143
dependencies: [
107144
.target(name: "InterceptionMacros"),
145+
],
146+
swiftSettings: [
147+
define_appleOS,
108148
]
109149
),
110150
]

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ Do not forget about target dependencies:
144144
)
145145
```
146146

147+
> [!NOTE]
148+
>
149+
> _The package is compatible with non-Apple platforms, however this package uses conditional compilation, so APIs are only available on Apple platforms_
150+
147151
## License
148152

149153
This library is released under the MIT license. See [LICENSE](LICENSE) for details.

Sources/Interception/NSObject+Interception.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if canImport(Combine)
1+
#if appleOS
22
import Foundation
33
import _InterceptionUtils
44
import _InterceptionCustomSelectors

Sources/_InterceptionCustomSelectors/KeyPath+.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Foundation
22

3+
#if appleOS
34
extension KeyPath {
45
public var getterSelector: Selector? {
56
guard let property = _kvcKeyPathString else { return nil }
@@ -13,3 +14,4 @@ extension WritableKeyPath {
1314
return Selector("set" + property.first!.uppercased() + String(property.dropFirst()) + ":")
1415
}
1516
}
17+
#endif

Sources/_InterceptionCustomSelectors/_MethodSelector.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#if appleOS
12
import Foundation
23

34
public protocol _MethodSelectorProtocol<Args, Output> {
@@ -83,3 +84,4 @@ public func _makeMethodSelector<Object, each Arg, Output>(
8384
) -> _MethodSelector<(repeat each Arg), Output> {
8485
return ._unchecked(selector)
8586
}
87+
#endif

Sources/_InterceptionCustomSelectors/_MutablePropertySelector.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#if appleOS
12
import Foundation
23

34
public protocol _MutablePropertySelectorProtocol<Value>: _PropertySelectorProtocol {
@@ -43,3 +44,4 @@ public func _unsafeMakePropertySelector<Object: NSObject, Value>(
4344
) -> _MutablePropertySelector<Value> {
4445
return .init(keyPath)!
4546
}
47+
#endif

Sources/_InterceptionCustomSelectors/_PropertySelector.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#if appleOS
12
import Foundation
23

34
public protocol _PropertySelectorProtocol<Value> {
@@ -27,3 +28,4 @@ public func _unsafeMakePropertySelector<Object: NSObject, Value>(
2728
) -> _ReadonlyPropertySelector<Value> {
2829
return .init(keyPath)!
2930
}
31+
#endif

Sources/_InterceptionMacros/Macros.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import Foundation
2+
3+
#if appleOS
24
import _InterceptionCustomSelectors
35

46
// MARK: - PropertySelectors
@@ -70,3 +72,4 @@ public macro methodSelector<Object, each Arg, Output>(
7072
_: (Object) -> (repeat each Arg) -> Output
7173
) -> _MethodSelector<(repeat each Arg), Output> =
7274
#externalMacro(module: "InterceptionMacrosPlugin", type: "MethodSelectorMacro")
75+
#endif
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
#if canImport(_InterceptionUtilsObjc)
1+
import Foundation
2+
3+
#if appleOS
24
@_exported import _InterceptionUtilsObjc
35
#endif

0 commit comments

Comments
 (0)