Skip to content

Commit aa95a38

Browse files
committed
Allow the gRPC module name to be customised when generating code
Motivation: Some Cocoapods may find themselves in a situation where their dependency graph contains both gRPC Swift and the gRPC core library. This is problematic since both have the same module name ("GRPC"). Changing our own module name is a very large breaking change and one we'd like to avoid. As an escape valve, users who take a direct dependency on us may rename our module via their Podfile; doing so would require their generated code to depend on that module, rather than the currently hardcoded 'GRPC' module. Modifications: - Add an option to the codegen to specify the gRPC module name - Remove a couple of imports which were previously used but are now no longer require - Regenerate Result: It's possible for Cocoapods users to take a direct dependency on gRPC Swift and libgrpc.
1 parent d0eb34d commit aa95a38

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

Sources/protoc-gen-grpc-swift/Generator.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,8 @@ class Generator {
8888
""")
8989

9090
let moduleNames = [
91-
"Foundation",
91+
self.options.gRPCModuleName,
9292
"NIO",
93-
"NIOHTTP1",
94-
"GRPC",
95-
"SwiftProtobuf",
9693
]
9794

9895
for moduleName in (moduleNames + self.options.extraModuleImports).sorted() {

Sources/protoc-gen-grpc-swift/options.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ final class GeneratorOptions {
5858
private(set) var protoToModuleMappings = ProtoFileToModuleMappings()
5959
private(set) var fileNaming = FileNaming.FullPath
6060
private(set) var extraModuleImports: [String] = []
61+
private(set) var gRPCModuleName = "GRPC"
6162

6263
init(parameter: String?) throws {
6364
for pair in GeneratorOptions.parseParameter(string: parameter) {
@@ -116,6 +117,13 @@ final class GeneratorOptions {
116117
throw GenerationError.invalidParameterValue(name: pair.key, value: pair.value)
117118
}
118119

120+
case "GRPCModuleName":
121+
if !pair.value.isEmpty {
122+
self.gRPCModuleName = pair.value
123+
} else {
124+
throw GenerationError.invalidParameterValue(name: pair.key, value: pair.value)
125+
}
126+
119127
default:
120128
throw GenerationError.unknownParameter(name: pair.key)
121129
}

0 commit comments

Comments
 (0)