Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions plugins/grpc/go/v1.6.2/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*
!Dockerfile
!separate-package.patch
20 changes: 20 additions & 0 deletions plugins/grpc/go/v1.6.2/Dockerfile
Original file line number Diff line number Diff line change
@@ -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" ]
22 changes: 22 additions & 0 deletions plugins/grpc/go/v1.6.2/buf.plugin.yaml
Original file line number Diff line number Diff line change
@@ -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
62 changes: 62 additions & 0 deletions plugins/grpc/go/v1.6.2/separate-package.patch
Original file line number Diff line number Diff line change
@@ -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,
1 change: 1 addition & 0 deletions tests/testdata/buf.build/grpc/go/v1.6.2/eliza/plugin.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
h1:jsTYtG28SMZEzaH6TapqtkjZFyTpBFQ2ApaqUl0m6Os=
1 change: 1 addition & 0 deletions tests/testdata/buf.build/grpc/go/v1.6.2/petapis/plugin.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
h1:YPjZpXcOkltZCxs5jYizDgbYrR60rk9TwZK3bbcWFAc=
Loading