@@ -54,26 +54,12 @@ let defaultSwiftSettings: [SwiftSetting] = [
54
54
. enableUpcomingFeature( " MemberImportVisibility " ) ,
55
55
]
56
56
57
- extension Context {
58
- fileprivate static var versionString : String {
59
- guard let git = Self . gitInformation else { return " " }
60
-
61
- if let tag = git. currentTag {
62
- return tag
63
- } else {
64
- let suffix = git. hasUncommittedChanges ? " (modified) " : " "
65
- return git. currentCommit + suffix
66
- }
67
- }
68
- }
69
-
70
- let targets : [ Target ] = [
57
+ var targets : [ Target ] = [
71
58
// protoc plugin for grpc-swift
72
59
. executableTarget(
73
60
name: " protoc-gen-grpc-swift " ,
74
61
dependencies: [
75
62
. target( name: " GRPCProtobufCodeGen " ) ,
76
- . target( name: " CGRPCProtobuf " ) ,
77
63
. product( name: " GRPCCodeGen " , package : " grpc-swift " ) ,
78
64
. product( name: " SwiftProtobuf " , package : " swift-protobuf " ) ,
79
65
. product( name: " SwiftProtobufPluginLibrary " , package : " swift-protobuf " ) ,
@@ -124,12 +110,6 @@ let targets: [Target] = [
124
110
swiftSettings: defaultSwiftSettings
125
111
) ,
126
112
127
- . target(
128
- name: " CGRPCProtobuf " ,
129
- cSettings: [
130
- . define( " CGRPC_GRPC_SWIFT_PROTOBUF_VERSION " , to: " \" \( Context . versionString) \" " )
131
- ]
132
- ) ,
133
113
134
114
// Code generator build plugin
135
115
. plugin(
@@ -164,6 +144,51 @@ let targets: [Target] = [
164
144
) ,
165
145
]
166
146
147
+ // -------------------------------------------------------------------------------------------------
148
+
149
+ extension Context {
150
+ fileprivate static var versionString : String {
151
+ guard let git = Self . gitInformation else { return " " }
152
+
153
+ if let tag = git. currentTag {
154
+ return tag
155
+ } else {
156
+ let suffix = git. hasUncommittedChanges ? " (modified) " : " "
157
+ return git. currentCommit + suffix
158
+ }
159
+ }
160
+
161
+ fileprivate static var buildCGRPCProtobuf : Bool {
162
+ let noVersion = Context . environment. keys. contains ( " GRPC_SWIFT_PROTOBUF_NO_VERSION " )
163
+ return !noVersion
164
+ }
165
+ }
166
+
167
+ // Having a C module as a transitive dependency of a plugin seems to trip up the API breakage
168
+ // checking tool. See also https://github.com/swiftlang/swift-package-manager/issues/8081
169
+ //
170
+ // The CGRPCProtobuf module (which only includes package version information) is conditionally
171
+ // compiled and included based on an environment variable. This is set in CI only for the API
172
+ // breakage checking job to avoid tripping up SwiftPM.
173
+ if Context . buildCGRPCProtobuf {
174
+ targets. append (
175
+ . target(
176
+ name: " CGRPCProtobuf " ,
177
+ cSettings: [
178
+ . define( " CGRPC_GRPC_SWIFT_PROTOBUF_VERSION " , to: " \" \( Context . versionString) \" " )
179
+ ]
180
+ )
181
+ )
182
+
183
+ for target in targets {
184
+ if target. name == " protoc-gen-grpc-swift " {
185
+ target. dependencies. append ( . target( name: " CGRPCProtobuf " ) )
186
+ }
187
+ }
188
+ }
189
+
190
+ // -------------------------------------------------------------------------------------------------
191
+
167
192
let package = Package (
168
193
name: " grpc-swift-protobuf " ,
169
194
platforms: [
0 commit comments