Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetch gRPC go v1.5.1 #1388

Merged
merged 8 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 0 additions & 4 deletions plugins/grpc/go/source.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
source:
# Temporarily disabled until we can fix both the patch and tests.
#
# See https://github.com/bufbuild/plugins/issues/1382 for more details.
disabled: true
goproxy:
name: google.golang.org/grpc/cmd/protoc-gen-go-grpc
3 changes: 3 additions & 0 deletions plugins/grpc/go/v1.5.0/.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.5.0/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# syntax=docker/dockerfile:1.7
oliversun9 marked this conversation as resolved.
Show resolved Hide resolved
FROM --platform=$BUILDPLATFORM golang:1.22.5-bookworm 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.5.0 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.5.0/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.5.0
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.34.2
registry:
go:
min_version: "1.19"
mfridman marked this conversation as resolved.
Show resolved Hide resolved
deps:
- module: google.golang.org/grpc
version: v1.62.2
oliversun9 marked this conversation as resolved.
Show resolved Hide resolved
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.5.0/LICENSE
62 changes: 62 additions & 0 deletions plugins/grpc/go/v1.5.0/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"

@@ -136,8 +137,27 @@ func generateFile(gen *protogen.Plugin, file *protogen.File) *protogen.Generated
mfridman marked this conversation as resolved.
Show resolved Hide resolved
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 220a2a28..69971872 100644
--- a/cmd/protoc-gen-go-grpc/main.go
+++ b/cmd/protoc-gen-go-grpc/main.go
@@ -46,6 +46,7 @@ const version = "1.5.0"

var requireUnimplemented *bool
var useGenericStreams *bool
+var separatePackage *bool

func main() {
showVersion := flag.Bool("version", false, "print the version and exit")
@@ -57,6 +58,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")
useGenericStreams = flags.Bool("use_generic_streams_experimental", true, "set to true to use generic types for streaming client and server objects; this flag is EXPERIMENTAL and may be changed or removed in a future release")
mfridman marked this conversation as resolved.
Show resolved Hide resolved

protogen.Options{
1 change: 1 addition & 0 deletions tests/testdata/buf.build/grpc/go/v1.5.0/eliza/plugin.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
h1:j5MtUqCdcT5PPebbv2qPXo9YXUIG3sHyKdH6NTdNYo8=
1 change: 1 addition & 0 deletions tests/testdata/buf.build/grpc/go/v1.5.0/petapis/plugin.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
h1:sN6eJkxYrZWJmaFKxe7T4ky3J0isztMT0Dorx+mIXj8=