diff --git a/ipns/pb/Makefile b/ipns/pb/Makefile deleted file mode 100644 index dead1fee2..000000000 --- a/ipns/pb/Makefile +++ /dev/null @@ -1,31 +0,0 @@ -# This Makefile is designed to work around namespace conflicts that occur when -# multiple repositories depend on .proto files with generic filenames. Due to -# the way protobuf registers files (e.g., foo.proto or pb/foo.proto), naming -# collisions can occur when the same filename is used across different -# packages. -# -# The only way to generate a *.pb.go file that includes the full package path -# (e.g., github.com/org/repo/pb/foo.proto) is to place the .proto file in a -# directory structure that mirrors its package path. -# -# References: -# * https://protobuf.dev/reference/go/faq#namespace-conflict -# * https://github.com/golang/protobuf/issues/1122#issuecomment-2045945265 - -PKG_PATH = github.com/ipfs/boxo/ipns/pb -PROTONAME = record -PROTOFILE = ${PROTONAME}.proto - -all: clean build - -build: - mkdir -p ${PKG_PATH} - cp ${PROTOFILE} ${PKG_PATH} - protoc --go_out=. ${PKG_PATH}/${PROTOFILE} - mv ${PKG_PATH}/${PROTONAME}.pb.go . - rm -rf $(firstword $(subst /, ,${PKG_PATH})) - -clean: - rm -f *.pb.go - -.PHONY: all build clean diff --git a/ipns/pb/gen.go b/ipns/pb/gen.go new file mode 100644 index 000000000..db8a7fbff --- /dev/null +++ b/ipns/pb/gen.go @@ -0,0 +1,20 @@ +// These commands work around namespace conflicts that occur when multiple +// repositories depend on .proto files with generic filenames. Due to the way +// protobuf registers files (e.g., foo.proto or pb/foo.proto), naming +// collisions can occur when the same filename is used across different +// packages. +// +// The only way to generate a *.pb.go file that includes the full package path +// (e.g., github.com/org/repo/pb/foo.proto) is to place the .proto file in a +// directory structure that mirrors its package path. +// +// References: +// - https://protobuf.dev/reference/go/faq#namespace-conflict +// - https://github.com/golang/protobuf/issues/1122#issuecomment-2045945265 +// +//go:generate mkdir -p github.com/ipfs/boxo/ipns/pb +//go:generate ln -f record.proto github.com/ipfs/boxo/ipns/pb/ +//go:generate protoc --go_out=. github.com/ipfs/boxo/ipns/pb/record.proto +//go:generate mv -f github.com/ipfs/boxo/ipns/pb/record.pb.go . +//go:generate rm -rf github.com +package pb