protobuild
protobuild copied to clipboard
Use paths=source_relative flag
https://developers.google.com/protocol-buffers/docs/reference/go-generated documents a flag paths=source_relative
:
If the paths=source_relative flag is specified, the output file is placed in the same relative directory as the input file. For example, an input file protos/buzz.proto results in an output file at protos/buzz.pb.go.
This fixes a chief issue with module-based output, allowing to move to using --go_out=.
to work from the repo root.
We should probably move the version 2 config to emit with these options.
With this, we can now support Go module-based generation on containerd with the creation of a directory tree and a single link back to the project:
module=$(go list -m)
mkdir -p /tmp/protoimportroot/$(dirname $module)
ln -sf $PWD /tmp/protoimportroot/$module
protoc -I/tmp/protoimportroot --go_out=/tmp/protoimportroot/ --go_opt=paths=source_relative --go-grpc_out=/tmp/protoimportroot/ --go-grpc_opt=paths=source_relative /tmp/protoimportroot/$module/api/services/whatever.proto
We do lose support for having other Go projects work as generation and import dependencies, but that's ok for the time-being. It's possible that is a much easier fix, since those all have direct paths in the module cache.
After having #54, we should be able to pass arbitrary parameters with small changes.
#54 is all we need actually. It works now (see https://github.com/containerd/cgroups/pull/251).