Skip to content

Commit

Permalink
enhancement: Support editions (#36)
Browse files Browse the repository at this point in the history
Signed-off-by: Charith Ellawala <charith@cerbos.dev>
  • Loading branch information
charithe authored Dec 20, 2024
1 parent be394e8 commit b079973
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
6 changes: 4 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
module github.com/cerbos/protoc-gen-go-hashpb

go 1.19
go 1.21

toolchain go1.23.3

require (
github.com/cespare/xxhash/v2 v2.1.2
google.golang.org/protobuf v1.33.0
google.golang.org/protobuf v1.36.0
)

require (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
google.golang.org/protobuf v1.36.0 h1:mjIs9gYtt56AzC4ZaffQuh88TZurBGhIJMBZGSxNerQ=
google.golang.org/protobuf v1.36.0/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
11 changes: 8 additions & 3 deletions internal/generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"google.golang.org/protobuf/compiler/protogen"
"google.golang.org/protobuf/reflect/protoreflect"
"google.golang.org/protobuf/types/descriptorpb"
"google.golang.org/protobuf/types/pluginpb"
)

Expand Down Expand Up @@ -54,16 +55,20 @@ func init() {
}

func Generate(p *protogen.Plugin) error {
p.SupportedFeatures = uint64(pluginpb.CodeGeneratorResponse_FEATURE_PROTO3_OPTIONAL)
p.SupportedFeatures = uint64(pluginpb.CodeGeneratorResponse_FEATURE_PROTO3_OPTIONAL) | uint64(pluginpb.CodeGeneratorResponse_FEATURE_SUPPORTS_EDITIONS)
p.SupportedEditionsMinimum = descriptorpb.Edition_EDITION_2023
p.SupportedEditionsMaximum = descriptorpb.Edition_EDITION_2024
// group files by import path because the helpers need to be generated at the package level.
pkgFiles := make(map[protogen.GoImportPath][]*protogen.File)
for _, f := range p.Files {
if !f.Generate {
continue
}

if f.Desc.Syntax() != protoreflect.Proto3 {
return fmt.Errorf("file is not protobuf v3: %s", f.Desc.Path())
switch f.Desc.Syntax() {
case protoreflect.Editions, protoreflect.Proto3:
default:
return fmt.Errorf("unsupported syntax %q: %s", f.Desc.Syntax(), f.Desc.Path())
}

pkgFiles[f.GoImportPath] = append(pkgFiles[f.GoImportPath], f)
Expand Down

0 comments on commit b079973

Please sign in to comment.