php-grpc icon indicating copy to clipboard operation
php-grpc copied to clipboard

php class for message of imported proto file not generated

Open wurststulle opened this issue 7 years ago • 10 comments

i tried to run protoc --php_out=test/ --php-grpc_out=test/ import/service.proto from inside the cmd/protoc-gen-php-grpc/testdata dir. everything worked, except for the PHP file of Sub\Message class is not generated. Message and ServiceInterface classes from namespace Import are fine. am i doing something wrong here?

wurststulle avatar Apr 26 '19 11:04 wurststulle

Can you provide sample Proto file? What version did you use?

wolfy-j avatar May 22 '19 08:05 wolfy-j

This seems to be one of the "gotchas" working with protoc: https://groups.google.com/forum/#!topic/protobuf/rRDqUT2ddYo

Currently you can run command like: protoc --php_out=test/ --php-grpc_out=test/ import/service.proto import/sub/message.proto

I'm digging into specifications.

wolfy-j avatar May 24 '19 10:05 wolfy-j

More info: https://github.com/protocolbuffers/protobuf/issues/4176

wolfy-j avatar May 24 '19 10:05 wolfy-j

I'm having the same problem, I'm trying to generate code with imported messages. Seems that the protoc-gen-php-grpc compiler totally ignores the imports. Here are my protos:

service.proto

syntax = "proto3";
package location;
import "common/graphql.proto"
message CityRequest {
    int32 id = 1;
    string lang = 2;
    repeated common.GraphSelection selections = 3;
}

common/graphql.proto

syntax = "proto3";
package common;
message GraphSelection {
  string name = 1;
  repeated common.GraphSelection selections = 2;
}

The CityRequest interface is generated correctly with references to \Common\GraphSelection but no GraphSelection.php

heh9 avatar May 24 '19 10:05 heh9

Hi, i'm digging into this issue as well, it is actually not protoc-get-php-grpc limitation but rather protoc iself. You can see that it generate correct references but it never receives call from protoc to render other php files.

See for reference: https://github.com/golang/protobuf/issues/322

The solution is very easy - specify imports you want to render with original service.

wolfy-j avatar May 24 '19 10:05 wolfy-j

FYI, messages are generated by native php-out plugin, not by php-grpc.

Example: protoc --php_out=./test/ import/service.proto

wolfy-j avatar May 24 '19 10:05 wolfy-j

On linux you can also use * to specify multiple files.

wolfy-j avatar May 24 '19 10:05 wolfy-j

I can propose an option to create vendor/bin/grpc-generate command which will automatically all included files.

wolfy-j avatar May 24 '19 10:05 wolfy-j

This is implementation I use to bypass this problem in our framework: https://github.com/spiral/framework/blob/master/src/GRPC/ProtoCompiler.php

Also, in next 2 hours I will provide application bundle which simplifies GRPC application creation a lot: https://github.com/spiral/app-grpc

wolfy-j avatar May 24 '19 11:05 wolfy-j

This is implementation I use to bypass this problem in our framework: https://github.com/spiral/framework/blob/master/src/GRPC/ProtoCompiler.php

Also, in next 2 hours I will provide application bundle which simplifies GRPC application creation a lot: https://github.com/spiral/app-grpc

Thank you for the solution, I think the issue can be closed now.

heh9 avatar Jun 03 '19 05:06 heh9