@@ -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,76 @@ 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
- " CoreModel "
51
- ] ,
52
- swiftSettings: [
53
- . swiftLanguageMode( . v5)
39
+ " CoreModel " ,
40
+ . byName(
41
+ name: " CoreDataModel " ,
42
+ condition: . when( platforms: [ . macOS, . iOS, . macCatalyst, . watchOS, . tvOS, . visionOS] )
43
+ )
54
44
]
55
- ) ,
45
+ )
46
+ ]
47
+ )
48
+
49
+ #if canImport(Darwin)
50
+ package . products. append (
51
+ . library(
52
+ name: " CoreDataModel " ,
53
+ type: libraryType,
54
+ targets: [
55
+ " CoreDataModel "
56
+ ]
57
+ )
58
+ )
59
+ package . targets. insert (
60
+ . target(
61
+ name: " CoreDataModel " ,
62
+ dependencies: [
63
+ " CoreModel "
64
+ ] ,
65
+ swiftSettings: [
66
+ . swiftLanguageMode( . v5)
67
+ ]
68
+ ) ,
69
+ at: 1
70
+ )
71
+ #endif
72
+
73
+ // SwiftPM plugins
74
+ if buildDocs {
75
+ package . dependencies += [
76
+ . package (
77
+ url: " https://github.com/swiftlang/swift-docc-plugin.git " ,
78
+ from: " 1.4.5 "
79
+ )
80
+ ]
81
+ }
82
+
83
+ if enableMacros {
84
+ let version : Version
85
+ #if swift(>=6.1)
86
+ version = " 601.0.1 "
87
+ #else
88
+ version = " 600.0.1 "
89
+ #endif
90
+ package . targets [ 0 ] . swiftSettings = [
91
+ . define( " SWIFTPM_ENABLE_MACROS " )
92
+ ]
93
+ package . dependencies += [
94
+ . package (
95
+ url: " https://github.com/swiftlang/swift-syntax.git " ,
96
+ from: version
97
+ )
98
+ ]
99
+ package . targets += [
56
100
. macro(
57
101
name: " CoreModelMacros " ,
58
102
dependencies: [
@@ -65,17 +109,9 @@ let package = Package(
65
109
package : " swift-syntax "
66
110
)
67
111
]
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
112
)
80
113
]
81
- )
114
+ package . targets [ 0 ] . dependencies += [
115
+ " CoreModelMacros "
116
+ ]
117
+ }
0 commit comments