@@ -3,8 +3,13 @@ import PackageDescription
3
3
import CompilerPluginSupport
4
4
import class Foundation. ProcessInfo
5
5
6
+ // get environment variables
7
+ let environment = ProcessInfo . processInfo. environment
8
+ let dynamicLibrary = environment [ " SWIFT_BUILD_DYNAMIC_LIBRARY " ] == " 1 "
9
+ let enableMacros = environment [ " SWIFTPM_ENABLE_MACROS " ] != " 0 "
10
+ let buildDocs = environment [ " BUILDING_FOR_DOCUMENTATION_GENERATION " ] == " 1 "
11
+
6
12
// force building as dynamic library
7
- let dynamicLibrary = ProcessInfo . processInfo. environment [ " SWIFT_BUILD_DYNAMIC_LIBRARY " ] != nil
8
13
let libraryType : PackageDescription . Product . Library . LibraryType ? = dynamicLibrary ? . dynamic : nil
9
14
10
15
let package = Package (
@@ -22,37 +27,89 @@ let package = Package(
22
27
targets: [
23
28
" CoreModel "
24
29
]
25
- ) ,
26
- . library(
27
- name: " CoreDataModel " ,
28
- type: libraryType,
29
- targets: [
30
- " CoreDataModel "
31
- ]
32
- )
33
- ] ,
34
- dependencies: [
35
- . package (
36
- url: " https://github.com/swiftlang/swift-syntax.git " ,
37
- from: " 600.0.1 "
38
30
)
39
31
] ,
40
32
targets: [
41
33
. target(
42
- name: " CoreModel " ,
43
- dependencies: [
44
- " CoreModelMacros "
45
- ]
34
+ name: " CoreModel "
46
35
) ,
47
- . target (
48
- name: " CoreDataModel " ,
36
+ . testTarget (
37
+ name: " CoreModelTests " ,
49
38
dependencies: [
50
39
" CoreModel "
51
- ] ,
52
- swiftSettings: [
53
- . swiftLanguageMode( . v5)
54
40
]
55
- ) ,
41
+ )
42
+ ]
43
+ )
44
+
45
+ #if canImport(Darwin)
46
+ package . products. append (
47
+ . library(
48
+ name: " CoreDataModel " ,
49
+ type: libraryType,
50
+ targets: [
51
+ " CoreDataModel "
52
+ ]
53
+ )
54
+ )
55
+ package . targets. insert (
56
+ . target(
57
+ name: " CoreDataModel " ,
58
+ dependencies: [
59
+ " CoreModel "
60
+ ] ,
61
+ swiftSettings: [
62
+ . swiftLanguageMode( . v5)
63
+ ]
64
+ ) ,
65
+ at: 1
66
+ )
67
+ package . targets [ package . targets. count - 1 ] = . testTarget(
68
+ name: " CoreModelTests " ,
69
+ dependencies: [
70
+ " CoreModel " ,
71
+ . byName(
72
+ name: " CoreDataModel " ,
73
+ condition: . when( platforms: [
74
+ . macOS,
75
+ . iOS,
76
+ . macCatalyst,
77
+ . watchOS,
78
+ . tvOS,
79
+ . visionOS
80
+ ] )
81
+ )
82
+ ]
83
+ )
84
+ #endif
85
+
86
+ // SwiftPM plugins
87
+ if buildDocs {
88
+ package . dependencies += [
89
+ . package (
90
+ url: " https://github.com/swiftlang/swift-docc-plugin.git " ,
91
+ from: " 1.4.5 "
92
+ )
93
+ ]
94
+ }
95
+
96
+ if enableMacros {
97
+ let version : Version
98
+ #if swift(>=6.1)
99
+ version = " 601.0.1 "
100
+ #else
101
+ version = " 600.0.1 "
102
+ #endif
103
+ package . targets [ 0 ] . swiftSettings = [
104
+ . define( " SWIFTPM_ENABLE_MACROS " )
105
+ ]
106
+ package . dependencies += [
107
+ . package (
108
+ url: " https://github.com/swiftlang/swift-syntax.git " ,
109
+ from: version
110
+ )
111
+ ]
112
+ package . targets += [
56
113
. macro(
57
114
name: " CoreModelMacros " ,
58
115
dependencies: [
@@ -65,17 +122,9 @@ let package = Package(
65
122
package : " swift-syntax "
66
123
)
67
124
]
68
- ) ,
69
- . testTarget(
70
- name: " CoreModelTests " ,
71
- dependencies: [
72
- " CoreModel " ,
73
- " CoreModelMacros " ,
74
- . byName(
75
- name: " CoreDataModel " ,
76
- condition: . when( platforms: [ . macOS, . iOS, . macCatalyst, . watchOS, . tvOS, . visionOS] )
77
- )
78
- ]
79
125
)
80
126
]
81
- )
127
+ package . targets [ 0 ] . dependencies += [
128
+ " CoreModelMacros "
129
+ ]
130
+ }
0 commit comments