Skip to content

Commit 7d12b7e

Browse files
authored
Merge pull request #31 from pubref/grpc_gateway_importmap
Propogates importmappings to protoc-gen-grpc-gateway
2 parents b6d3d0f + 3f9bd06 commit 7d12b7e

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

grpc_gateway/rules.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ def grpc_gateway_proto_library(
105105
"name": name + ".gw",
106106
"protos": protos,
107107
"deps": [dep + ".pb" for dep in proto_deps],
108+
"prefix": prefix,
108109
"langs": langs,
109110
"imports": imports,
110111
"importmap": importmap,

protobuf/internal/proto_compile.bzl

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -253,10 +253,6 @@ def _build_importmappings(run, builder):
253253
ctx = run.ctx
254254
go_prefix = run.data.prefix or run.lang.prefix
255255
opts = []
256-
# Add in the 'plugins=grpc' option to the protoc-gen-go plugin if
257-
# the user wants grpc.
258-
if run.data.with_grpc:
259-
opts.append("plugins=grpc")
260256

261257
# Build the list of import mappings. Start with any configured on
262258
# the rule by attributes.
@@ -275,8 +271,16 @@ def _build_importmappings(run, builder):
275271

276272
builder["transitive_mappings"] = mappings
277273

278-
builder[run.lang.name + "_pb_options"] += opts
279-
274+
# protoc-gen-go needs the importmapping in the protobuf options
275+
# whereas protoc-gen-grpc-gateway requires them in the grpc_options.
276+
if run.lang.pb_plugin_implements_grpc:
277+
# Add in the 'plugins=grpc' option to the protoc-gen-go plugin if
278+
# the user wants grpc.
279+
if run.data.with_grpc:
280+
opts.append("plugins=grpc")
281+
builder[run.lang.name + "_pb_options"] += opts
282+
else:
283+
builder[run.lang.name + "_grpc_options"] += opts
280284

281285
def _build_plugin_out(name, outdir, options, builder):
282286
"""Build the --{lang}_out argument for a given plugin."""
@@ -500,12 +504,11 @@ def _proto_compile_impl(ctx):
500504
_build_output_libdir(run, builder)
501505
else:
502506
_build_output_files(run, builder)
503-
if run.lang.prefix:
507+
if run.lang.prefix: # golang-specific
504508
_build_importmappings(run, builder)
505509
if run.lang.supports_pb:
506510
_build_protobuf_invocation(run, builder)
507511
_build_protobuf_out(run, builder)
508-
509512
if not run.lang.pb_plugin_implements_grpc and (data.with_grpc and run.lang.supports_grpc):
510513
_build_grpc_invocation(run, builder)
511514
_build_grpc_out(run, builder)

0 commit comments

Comments
 (0)