protobuf: remove gogoproto

Removes gogo/protobuf from buildx and updates to a version of
moby/buildkit where gogo is removed.

This also changes how the proto files are generated. This is because
newer versions of protobuf are more strict about name conflicts. If two
files have the same name (even if they are relative paths) and are used
in different protoc commands, they'll conflict in the registry.

Since protobuf file generation doesn't work very well with
`paths=source_relative`, this removes the `go:generate` expression and
just relies on the dockerfile to perform the generation.

Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
This commit is contained in:
Jonathan A. Sternberg
2024-10-02 15:51:59 -05:00
parent 8e47387d02
commit b35a0f4718
592 changed files with 46288 additions and 110420 deletions

View File

@ -17,6 +17,7 @@ import (
"unicode/utf8"
"google.golang.org/protobuf/compiler/protogen"
"google.golang.org/protobuf/internal/editionssupport"
"google.golang.org/protobuf/internal/encoding/tag"
"google.golang.org/protobuf/internal/filedesc"
"google.golang.org/protobuf/internal/genid"
@ -29,7 +30,10 @@ import (
)
// SupportedFeatures reports the set of supported protobuf language features.
var SupportedFeatures = uint64(pluginpb.CodeGeneratorResponse_FEATURE_PROTO3_OPTIONAL)
var SupportedFeatures = uint64(pluginpb.CodeGeneratorResponse_FEATURE_PROTO3_OPTIONAL | pluginpb.CodeGeneratorResponse_FEATURE_SUPPORTS_EDITIONS)
var SupportedEditionsMinimum = editionssupport.Minimum
var SupportedEditionsMaximum = editionssupport.Maximum
// GenerateVersionMarkers specifies whether to generate version markers.
var GenerateVersionMarkers = true
@ -227,7 +231,7 @@ func genImport(gen *protogen.Plugin, g *protogen.GeneratedFile, f *fileInfo, imp
func genEnum(g *protogen.GeneratedFile, f *fileInfo, e *enumInfo) {
// Enum type declaration.
g.Annotate(e.GoIdent.GoName, e.Location)
g.AnnotateSymbol(e.GoIdent.GoName, protogen.Annotation{Location: e.Location})
leadingComments := appendDeprecationSuffix(e.Comments.Leading,
e.Desc.ParentFile(),
e.Desc.Options().(*descriptorpb.EnumOptions).GetDeprecated())
@ -237,7 +241,7 @@ func genEnum(g *protogen.GeneratedFile, f *fileInfo, e *enumInfo) {
// Enum value constants.
g.P("const (")
for _, value := range e.Values {
g.Annotate(value.GoIdent.GoName, value.Location)
g.AnnotateSymbol(value.GoIdent.GoName, protogen.Annotation{Location: value.Location})
leadingComments := appendDeprecationSuffix(value.Comments.Leading,
value.Desc.ParentFile(),
value.Desc.Options().(*descriptorpb.EnumValueOptions).GetDeprecated())
@ -289,11 +293,11 @@ func genEnum(g *protogen.GeneratedFile, f *fileInfo, e *enumInfo) {
genEnumReflectMethods(g, f, e)
// UnmarshalJSON method.
needsUnmarshalJSONMethod := e.genJSONMethod && e.Desc.Syntax() == protoreflect.Proto2
if fde, ok := e.Desc.(*filedesc.Enum); ok && fde.L1.EditionFeatures.GenerateLegacyUnmarshalJSON {
needsUnmarshalJSONMethod = true
needsUnmarshalJSONMethod := false
if fde, ok := e.Desc.(*filedesc.Enum); ok {
needsUnmarshalJSONMethod = fde.L1.EditionFeatures.GenerateLegacyUnmarshalJSON
}
if needsUnmarshalJSONMethod {
if e.genJSONMethod && needsUnmarshalJSONMethod {
g.P("// Deprecated: Do not use.")
g.P("func (x *", e.GoIdent, ") UnmarshalJSON(b []byte) error {")
g.P("num, err := ", protoimplPackage.Ident("X"), ".UnmarshalJSONEnum(x.Descriptor(), b)")
@ -327,7 +331,7 @@ func genMessage(g *protogen.GeneratedFile, f *fileInfo, m *messageInfo) {
}
// Message type declaration.
g.Annotate(m.GoIdent.GoName, m.Location)
g.AnnotateSymbol(m.GoIdent.GoName, protogen.Annotation{Location: m.Location})
leadingComments := appendDeprecationSuffix(m.Comments.Leading,
m.Desc.ParentFile(),
m.Desc.Options().(*descriptorpb.MessageOptions).GetDeprecated())
@ -388,7 +392,7 @@ func genMessageField(g *protogen.GeneratedFile, f *fileInfo, m *messageInfo, fie
tags = append(tags, gotrackTags...)
}
g.Annotate(m.GoIdent.GoName+"."+oneof.GoName, oneof.Location)
g.AnnotateSymbol(m.GoIdent.GoName+"."+oneof.GoName, protogen.Annotation{Location: oneof.Location})
leadingComments := oneof.Comments.Leading
if leadingComments != "" {
leadingComments += "\n"
@ -427,7 +431,7 @@ func genMessageField(g *protogen.GeneratedFile, f *fileInfo, m *messageInfo, fie
if field.Desc.IsWeak() {
name = genid.WeakFieldPrefix_goname + name
}
g.Annotate(m.GoIdent.GoName+"."+name, field.Location)
g.AnnotateSymbol(m.GoIdent.GoName+"."+name, protogen.Annotation{Location: field.Location})
leadingComments := appendDeprecationSuffix(field.Comments.Leading,
field.Desc.ParentFile(),
field.Desc.Options().(*descriptorpb.FieldOptions).GetDeprecated())
@ -555,7 +559,7 @@ func genMessageGetterMethods(g *protogen.GeneratedFile, f *fileInfo, m *messageI
// Getter for parent oneof.
if oneof := field.Oneof; oneof != nil && oneof.Fields[0] == field && !oneof.Desc.IsSynthetic() {
g.Annotate(m.GoIdent.GoName+".Get"+oneof.GoName, oneof.Location)
g.AnnotateSymbol(m.GoIdent.GoName+".Get"+oneof.GoName, protogen.Annotation{Location: oneof.Location})
g.P("func (m *", m.GoIdent.GoName, ") Get", oneof.GoName, "() ", oneofInterfaceName(oneof), " {")
g.P("if m != nil {")
g.P("return m.", oneof.GoName)
@ -568,7 +572,7 @@ func genMessageGetterMethods(g *protogen.GeneratedFile, f *fileInfo, m *messageI
// Getter for message field.
goType, pointer := fieldGoType(g, f, field)
defaultValue := fieldDefaultValue(g, f, m, field)
g.Annotate(m.GoIdent.GoName+".Get"+field.GoName, field.Location)
g.AnnotateSymbol(m.GoIdent.GoName+".Get"+field.GoName, protogen.Annotation{Location: field.Location})
leadingComments := appendDeprecationSuffix("",
field.Desc.ParentFile(),
field.Desc.Options().(*descriptorpb.FieldOptions).GetDeprecated())
@ -811,8 +815,8 @@ func genMessageOneofWrapperTypes(g *protogen.GeneratedFile, f *fileInfo, m *mess
g.P("}")
g.P()
for _, field := range oneof.Fields {
g.Annotate(field.GoIdent.GoName, field.Location)
g.Annotate(field.GoIdent.GoName+"."+field.GoName, field.Location)
g.AnnotateSymbol(field.GoIdent.GoName, protogen.Annotation{Location: field.Location})
g.AnnotateSymbol(field.GoIdent.GoName+"."+field.GoName, protogen.Annotation{Location: field.Location})
g.P("type ", field.GoIdent, " struct {")
goType, _ := fieldGoType(g, f, field)
tags := structTags{

View File

@ -0,0 +1,58 @@
// Copyright 2018 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// The protoc-gen-go binary is a protoc plugin to generate Go code for
// both proto2 and proto3 versions of the protocol buffer language.
//
// For more information about the usage of this plugin, see:
// https://protobuf.dev/reference/go/go-generated.
package main
import (
"errors"
"flag"
"fmt"
"os"
"path/filepath"
gengo "google.golang.org/protobuf/cmd/protoc-gen-go/internal_gengo"
"google.golang.org/protobuf/compiler/protogen"
"google.golang.org/protobuf/internal/version"
)
const genGoDocURL = "https://protobuf.dev/reference/go/go-generated"
const grpcDocURL = "https://grpc.io/docs/languages/go/quickstart/#regenerate-grpc-code"
func main() {
if len(os.Args) == 2 && os.Args[1] == "--version" {
fmt.Fprintf(os.Stdout, "%v %v\n", filepath.Base(os.Args[0]), version.String())
os.Exit(0)
}
if len(os.Args) == 2 && os.Args[1] == "--help" {
fmt.Fprintf(os.Stdout, "See "+genGoDocURL+" for usage information.\n")
os.Exit(0)
}
var (
flags flag.FlagSet
plugins = flags.String("plugins", "", "deprecated option")
)
protogen.Options{
ParamFunc: flags.Set,
}.Run(func(gen *protogen.Plugin) error {
if *plugins != "" {
return errors.New("protoc-gen-go: plugins are not supported; use 'protoc --go-grpc_out=...' to generate gRPC\n\n" +
"See " + grpcDocURL + " for more information.")
}
for _, f := range gen.Files {
if f.Generate {
gengo.GenerateFile(gen, f)
}
}
gen.SupportedFeatures = gengo.SupportedFeatures
gen.SupportedEditionsMinimum = gengo.SupportedEditionsMinimum
gen.SupportedEditionsMaximum = gengo.SupportedEditionsMaximum
return nil
})
}