Skip to content

Commit

Permalink
fix: ipns protobuf namespace conflict (#794)
Browse files Browse the repository at this point in the history
* fix: ipns protobuf namespace conflict
* Prefer `go generate` to `Makefile` for code generation

---------

Co-authored-by: Andrew Gillis <[email protected]>
  • Loading branch information
guillaumemichel and gammazero authored Jan 21, 2025
1 parent 8b305a3 commit 3586985
Show file tree
Hide file tree
Showing 6 changed files with 293 additions and 272 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ The following emojis are used to highlight certain changes:
### Fixed

- `gateway` Fix redirect URLs for subdirectories with characters that need escaping. [#779](https://github.com/ipfs/boxo/pull/779)
- `ipns` Defined a `go_package` name in `ipns-record.proto` to avoid protobuf conflicts [#789](https://github.com/ipfs/boxo/pull/789)
- `ipns` Fix `ipns` protobuf namespace conflicts by using full package name `github.com/ipfs/boxo/ipns/pb/record.proto` instead of the generic `record.proto` [#794](https://github.com/ipfs/boxo/pull/794)

### Security

Expand Down
20 changes: 20 additions & 0 deletions ipns/pb/gen.go
Original file line number Diff line number Diff line change
@@ -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
270 changes: 0 additions & 270 deletions ipns/pb/ipns-record.pb.go

This file was deleted.

Loading

0 comments on commit 3586985

Please sign in to comment.