Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

protoc not generating service stub files

I have just started playing with google proto. When I try to compile proto file present in proto-java example, it does not generate any grpc file.

proto file, https://github.com/grpc/grpc-java/blob/master/examples/src/main/proto/hello_world.proto

terminal output,

rsonkhla@raman-OptiPlex-9020:~/sandbox/grpc-java/examples$ protoc --version libprotoc 3.0.0 rsonkhla@raman-OptiPlex-9020:~/sandbox/grpc-java/examples$ protoc --java_out=test/ -I../../grpc-java/examples ../../grpc-java/examples/src/main/proto/hello_world.proto rsonkhla@raman-OptiPlex-9020:~/sandbox/grpc-java/examples$ ls -R test/ test/: io

test/io: grpc

test/io/grpc: examples

test/io/grpc/examples: helloworld

test/io/grpc/examples/helloworld: HelloRequest.java
HelloResponse.java HelloWorldProto.java HelloRequestOrBuilder.java HelloResponseOrBuilder.java

Has anybody else faced this issue?

like image 968
Raman Sonkhla Avatar asked Jun 24 '15 14:06

Raman Sonkhla


People also ask

What is protoc file?

protoc is a compiler for protocol buffers definitions files. It can can generate C++, Java and Python source code for the classes defined in PROTO_FILE.

What does protoc compiler do?

Google provides a compiler called protoc which can produce output for C++, Java or Python. Other schema compilers are available from other sources to create language-dependent output for over 20 other languages.

What is protoc GEN go?

protoc-gen-go is a filter for the protoc(1) protocol buffer compiler. It takes the protocol buffer format from protoc(1) as input and produces Go code as output which can then be used to encode (marshal) and decode (unmarshal) data in the protocol buffer format specified in its input.


2 Answers

The command line you are showing does not enable the grpc plugin. You need to specify an _out argument for the grpc plugin, which enables the plugin and specifies where it should output files. Since the plugin is likely not in your PATH, you also need to tell protoc how to find the plugin with --plugin.

So you need to add two arguments:

--plugin=protoc-gen-grpc-java=path/to/protoc-gen-grpc-java --grpc-java_out=path/to/output/dir 

For more info, see the gRPC compiler documentation.

like image 57
Eric Anderson Avatar answered Sep 22 '22 19:09

Eric Anderson


You can add these option to your .proto (base on your language) to generate abstract services:

option cc_generic_services = true; option java_generic_services = true; option py_generic_services = true; 

You can also add --plugin=EXECUTABLE option in your protoc cmd to use custom code generator plugin to generate code more specific to each system, rather than rely on the "abstract" services. Just like Eric's suggestion.

like image 24
djzhu Avatar answered Sep 25 '22 19:09

djzhu