Skip to content

Commit 0dd1f77

Browse files
committed
Conditionally build plugins
1 parent 1fcd91b commit 0dd1f77

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

Package.swift

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,42 @@
1717

1818
import PackageDescription
1919

20+
extension Context {
21+
fileprivate static var buildPlugins: Bool {
22+
let noPlugins = Context.environment.keys.contains("GRPC_SWIFT_PROTOBUF_NO_PLUGINS")
23+
return !noPlugins
24+
}
25+
}
26+
27+
extension [Product] {
28+
func removingPluginsIfNecessary() -> Self {
29+
if Context.buildPlugins {
30+
return self
31+
} else {
32+
// Remove plugin products.
33+
return self.filter { !($0 is Product.Plugin) }
34+
}
35+
}
36+
}
37+
38+
extension [Target] {
39+
func removingPluginsIfNecessary() -> Self {
40+
if Context.buildPlugins {
41+
return self
42+
} else {
43+
// Remove plugin targets.
44+
return self.filter { target in
45+
switch target.type {
46+
case .plugin:
47+
return false
48+
default:
49+
return true
50+
}
51+
}
52+
}
53+
}
54+
}
55+
2056
let products: [Product] = [
2157
.library(
2258
name: "GRPCProtobuf",
@@ -173,7 +209,7 @@ let package = Package(
173209
.watchOS(.v11),
174210
.visionOS(.v2),
175211
],
176-
products: products,
212+
products: products.removingPluginsIfNecessary(),
177213
dependencies: dependencies,
178-
targets: targets
214+
targets: targets.removingPluginsIfNecessary()
179215
)

0 commit comments

Comments
 (0)