@@ -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
281285def _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