diff --git a/plugins/grpc/go/v1.6.2/.dockerignore b/plugins/grpc/go/v1.6.2/.dockerignore new file mode 100644 index 000000000..7feaa9bd3 --- /dev/null +++ b/plugins/grpc/go/v1.6.2/.dockerignore @@ -0,0 +1,3 @@ +* +!Dockerfile +!separate-package.patch diff --git a/plugins/grpc/go/v1.6.2/Dockerfile b/plugins/grpc/go/v1.6.2/Dockerfile new file mode 100644 index 000000000..853b284f6 --- /dev/null +++ b/plugins/grpc/go/v1.6.2/Dockerfile @@ -0,0 +1,20 @@ +# syntax=docker/dockerfile:1.23 +FROM --platform=$BUILDPLATFORM golang:1.26.3-trixie@sha256:d08bf3ed2bd263088ca8e23fefaf10f1b71769f6932f0a4017ba28d2a5baf001 AS build + +ARG TARGETOS TARGETARCH +ENV CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH + +WORKDIR /tmp +RUN git clone --depth 1 --branch cmd/protoc-gen-go-grpc/v1.6.2 https://github.com/grpc/grpc-go.git +WORKDIR /tmp/grpc-go +COPY separate-package.patch /tmp/grpc-go +RUN git apply separate-package.patch +WORKDIR /tmp/grpc-go/cmd/protoc-gen-go-grpc +RUN --mount=type=cache,target=/go/pkg/mod \ + go build -o protoc-gen-go-grpc -ldflags "-s -w" -trimpath + +FROM scratch +COPY --from=build --link /etc/passwd /etc/passwd +COPY --from=build --link --chown=root:root /tmp/grpc-go/cmd/protoc-gen-go-grpc/protoc-gen-go-grpc . +USER nobody +ENTRYPOINT [ "/protoc-gen-go-grpc" ] diff --git a/plugins/grpc/go/v1.6.2/buf.plugin.yaml b/plugins/grpc/go/v1.6.2/buf.plugin.yaml new file mode 100644 index 000000000..aeecaaae6 --- /dev/null +++ b/plugins/grpc/go/v1.6.2/buf.plugin.yaml @@ -0,0 +1,22 @@ +version: v1 +name: buf.build/grpc/go +plugin_version: v1.6.2 +source_url: https://github.com/grpc/grpc-go +integration_guide_url: https://grpc.io/docs/languages/go/quickstart +description: Generates Go client and server stubs for the gRPC framework. +output_languages: + - go +deps: + - plugin: buf.build/protocolbuffers/go:v1.36.11 +registry: + go: + min_version: "1.25" + deps: + - module: google.golang.org/grpc + version: v1.81.0 + opts: + - paths=source_relative + - require_unimplemented_servers=false + - separate_package=true +spdx_license_id: Apache-2.0 +license_url: https://github.com/grpc/grpc-go/blob/v1.6.2/LICENSE diff --git a/plugins/grpc/go/v1.6.2/separate-package.patch b/plugins/grpc/go/v1.6.2/separate-package.patch new file mode 100644 index 000000000..a84f5d73b --- /dev/null +++ b/plugins/grpc/go/v1.6.2/separate-package.patch @@ -0,0 +1,62 @@ +diff --git a/cmd/protoc-gen-go-grpc/grpc.go b/cmd/protoc-gen-go-grpc/grpc.go +index abc21602..7d9dd638 100644 +--- a/cmd/protoc-gen-go-grpc/grpc.go ++++ b/cmd/protoc-gen-go-grpc/grpc.go +@@ -20,6 +20,7 @@ package main + + import ( + "fmt" ++ "path" + "strconv" + "strings" + +@@ -135,8 +136,27 @@ func generateFile(gen *protogen.Plugin, file *protogen.File) *protogen.Generated + if len(file.Services) == 0 { + return nil + } +- filename := file.GeneratedFilenamePrefix + "_grpc.pb.go" +- g := gen.NewGeneratedFile(filename, file.GoImportPath) ++ var g *protogen.GeneratedFile ++ if !*separatePackage { ++ filename := file.GeneratedFilenamePrefix + "_grpc.pb.go" ++ g = gen.NewGeneratedFile(filename, file.GoImportPath) ++ } else { ++ file.GoPackageName += "grpc" ++ dir := path.Dir(file.GeneratedFilenamePrefix) ++ base := path.Base(file.GeneratedFilenamePrefix) ++ file.GeneratedFilenamePrefix = path.Join( ++ dir, ++ string(file.GoPackageName), ++ base, ++ ) ++ g = gen.NewGeneratedFile( ++ file.GeneratedFilenamePrefix+"_grpc.pb.go", ++ protogen.GoImportPath(path.Join( ++ string(file.GoImportPath), ++ string(file.GoPackageName), ++ )), ++ ) ++ } + // Attach all comments associated with the syntax field. + genLeadingComments(g, file.Desc.SourceLocations().ByPath(protoreflect.SourcePath{fileDescriptorProtoSyntaxFieldNumber})) + g.P("// Code generated by protoc-gen-go-grpc. DO NOT EDIT.") +diff --git a/cmd/protoc-gen-go-grpc/main.go b/cmd/protoc-gen-go-grpc/main.go +index 183ba697..d0e1be60 100644 +--- a/cmd/protoc-gen-go-grpc/main.go ++++ b/cmd/protoc-gen-go-grpc/main.go +@@ -45,6 +45,7 @@ const version = "1.6.2" + const version = "1.6.2" + + var requireUnimplemented *bool ++var separatePackage *bool + + func main() { + showVersion := flag.Bool("version", false, "print the version and exit") +@@ -56,6 +57,7 @@ func main() { + + var flags flag.FlagSet + requireUnimplemented = flags.Bool("require_unimplemented_servers", true, "set to false to match legacy behavior") ++ separatePackage = flags.Bool("separate_package", false, "set to true to write generated files to a separate grpc package") + + protogen.Options{ + ParamFunc: flags.Set, diff --git a/tests/testdata/buf.build/grpc/go/v1.6.2/eliza/plugin.sum b/tests/testdata/buf.build/grpc/go/v1.6.2/eliza/plugin.sum new file mode 100644 index 000000000..af68986dd --- /dev/null +++ b/tests/testdata/buf.build/grpc/go/v1.6.2/eliza/plugin.sum @@ -0,0 +1 @@ +h1:jsTYtG28SMZEzaH6TapqtkjZFyTpBFQ2ApaqUl0m6Os= diff --git a/tests/testdata/buf.build/grpc/go/v1.6.2/petapis/plugin.sum b/tests/testdata/buf.build/grpc/go/v1.6.2/petapis/plugin.sum new file mode 100644 index 000000000..b89e9e5eb --- /dev/null +++ b/tests/testdata/buf.build/grpc/go/v1.6.2/petapis/plugin.sum @@ -0,0 +1 @@ +h1:YPjZpXcOkltZCxs5jYizDgbYrR60rk9TwZK3bbcWFAc=