golang / protobuf

Go support for Google's protocol buffers
BSD 3-Clause "New" or "Revised" License
9.64k stars 1.58k forks source link

How can I use protoc and generate protobuf related files from a .proto file that is in another dir #1569

Closed gabrielforster closed 8 months ago

gabrielforster commented 9 months ago

├── order │ ├── proto │ │ ├── order.proto ├── notification │ ├── Makefile

I have my order.proto on the order/proto dir and I wanna generate protobuf files from it being on the notification dir

Makefile content:

build:
  env GOOS=linux go build -ldflags="-s -w" -o bin/main cmd/main.go

protogen:
  protoc \
          --go_out=. \
          --go_opt=paths=source_relative \
          --go-grpc_out=. \
          --go-grpc_opt=paths=source_relative \
          ../order/proto/order.proto

But when I try to run make protogen I have the following error image "../order/proto/order.proto: File does not reside within any path specified using --proto_path (or -I). You must specify a --proto_path which encompasses this file. Note that the proto_path must be an exact prefix of the .proto file names -- protoc is too dumb to figure out when two paths (e.g. absolute and relative) are equivalent (it's harder than you think). make: *** [Makefile:5: protogen] Error 1"

Is there a way to make it less "dumb"?

gabrielforster commented 8 months ago

Just generated proto result from order dir and point --go-out to be the notification dir