Skip to content

Commit

Permalink
Replace gogo protobuf with google's protobuf v2 compiler (#317)
Browse files Browse the repository at this point in the history
**What changed?**

gogo/protobuf has been replaced with Google's official go compiler.

I also changed our code generation to use buf as it was slightly easier to manage plugin versions, though I may revert that.

**Why?**

gogo/protobuf has been deprecated for some time and the community is moving on, building new tools (like vtproto) atop google's v2 compiler.

**Breaking changes**

- `*time.Time` in proto structs will now be [timestamppb.Timestamp](https://pkg.go.dev/google.golang.org/[email protected]/types/known/timestamppb#section-documentation)
- `*time.Duration` will now be [durationpb.Duration](https://pkg.go.dev/google.golang.org/protobuf/types/known/durationpb)
- V2-generated structs embed locks, so you cannot dereference them willy-nilly. `go vet` will scream at you about this
- Proto enums will, when formatted to JSON, now be in `SCREAMING_SNAKE_CASE` rather than `PascalCase`. We decided (in discussion with the SDK team) that now was as good a time as any to rip the bandage off
  • Loading branch information
tdeebswihart authored Nov 21, 2023
1 parent 0165f4a commit a19522a
Show file tree
Hide file tree
Showing 25 changed files with 219 additions and 535 deletions.
4 changes: 2 additions & 2 deletions .buildkite/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
FROM temporalio/base-ci-builder:1.5.0
WORKDIR /temporal
FROM temporalio/base-ci-builder:1.10.3
WORKDIR /temporal
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/.idea
/.gen
/.vscode
/.vscode
/.stamp
47 changes: 25 additions & 22 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ endif

GOBIN := $(if $(shell go env GOBIN),$(shell go env GOBIN),$(GOPATH)/bin)
PATH := $(GOBIN):$(PATH)
STAMPDIR := .stamp

COLOR := "\e[1;36m%s\e[0m\n"

Expand All @@ -34,55 +35,57 @@ PROTO_FILES = $(shell find temporal -name "*.proto")
PROTO_DIRS = $(sort $(dir $(PROTO_FILES)))
PROTO_OUT := .gen
PROTO_IMPORTS = \
-I=$(PROTO_ROOT) \
-I=$(shell go list -modfile build/go.mod -m -f '{{.Dir}}' github.com/temporalio/gogo-protobuf)/protobuf \
-I=$(shell go list -modfile build/go.mod -m -f '{{.Dir}}' github.com/grpc-ecosystem/grpc-gateway)/third_party/googleapis
-I=$(PROTO_ROOT)
PROTO_PATHS = paths=source_relative:$(PROTO_OUT)

$(PROTO_OUT):
mkdir $(PROTO_OUT)

##### Compile proto files for go #####
grpc: buf-lint api-linter buf-breaking gogo-grpc fix-path
grpc: buf-lint api-linter buf-breaking clean go-grpc fix-path

gogo-grpc: clean $(PROTO_OUT)
printf $(COLOR) "Compile for gogo-gRPC..."
go-grpc: clean $(PROTO_OUT)
printf $(COLOR) "Compile for go-gRPC..."
$(foreach PROTO_DIR,$(PROTO_DIRS),\
protoc --fatal_warnings $(PROTO_IMPORTS) \
--gogoslick_out=Mgoogle/protobuf/any.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/wrappers.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/duration.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/descriptor.proto=github.com/golang/protobuf/protoc-gen-go/descriptor,Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types,plugins=grpc,paths=source_relative:$(PROTO_OUT) \
--grpc-gateway_out=allow_patch_feature=false,paths=source_relative:$(PROTO_OUT) \
--go_out=$(PROTO_PATHS) \
--grpc-gateway_out=allow_patch_feature=false,$(PROTO_PATHS)\
--doc_out=html,index.html,source_relative:$(PROTO_OUT) \
$(PROTO_DIR)*.proto;)

fix-path:
mv -f $(PROTO_OUT)/temporal/api/* $(PROTO_OUT) && rm -rf $(PROTO_OUT)/temporal

##### Plugins & tools #####
grpc-install: gogo-protobuf-install
printf $(COLOR) "Install/update gRPC plugins..."
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
go install github.com/pseudomuto/protoc-gen-doc/cmd/protoc-gen-doc@latest

gogo-protobuf-install: go-protobuf-install
go install -modfile build/go.mod github.com/temporalio/gogo-protobuf/protoc-gen-gogoslick
go install -modfile build/go.mod github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway

go-protobuf-install:
go install github.com/golang/protobuf/[email protected]
grpc-install:
@printf $(COLOR) "Install/update protoc and plugins..."
@go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
@go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
@go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway@latest
@go install github.com/pseudomuto/protoc-gen-doc/cmd/protoc-gen-doc@latest

api-linter-install:
printf $(COLOR) "Install/update api-linter..."
go install github.com/googleapis/api-linter/cmd/[email protected]

buf-install:
printf $(COLOR) "Install/update buf..."
go install github.com/bufbuild/buf/cmd/buf@v1.6.0
go install github.com/bufbuild/buf/cmd/buf@v1.27.0

##### Linters #####
api-linter:
printf $(COLOR) "Run api-linter..."
$(call silent_exec, api-linter --set-exit-status $(PROTO_IMPORTS) --config $(PROTO_ROOT)/api-linter.yaml $(PROTO_FILES))

buf-lint:
$(STAMPDIR):
mkdir $@

$(STAMPDIR)/buf-mod-prune: $(STAMPDIR) buf.yaml
printf $(COLOR) "Pruning buf module"
buf mod prune
touch $@

buf-lint: $(STAMPDIR)/buf-mod-prune
printf $(COLOR) "Run buf linter..."
(cd $(PROTO_ROOT) && buf lint)

Expand All @@ -93,4 +96,4 @@ buf-breaking:
##### Clean #####
clean:
printf $(COLOR) "Delete generated go files..."
rm -rf $(PROTO_OUT)
rm -rf $(PROTO_OUT) $(BUF_DEPS)
2 changes: 1 addition & 1 deletion api-linter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@
- "core::0127::http-annotation"

- included_paths:
- "dependencies/gogoproto/gogo.proto"
- "google/**/*.proto"
disabled_rules:
- "all"
20 changes: 20 additions & 0 deletions buf.gen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: v1
plugins:
- plugin: buf.build/protocolbuffers/go:v1.31.0
out: ./
opt:
- paths=source_relative
- plugin: buf.build/grpc/go:v1.3.0
out: ./
opt:
- paths=source_relative
- plugin: buf.build/grpc-ecosystem/gateway:v2.18.0
out: ./
opt:
- paths=source_relative
- allow_patch_feature=false
- name: go-helpers
out: ./
path: ["go", "run", "./protoc-gen-go-helpers"]
opt:
- paths=source_relative
9 changes: 9 additions & 0 deletions buf.lock
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
# Generated by buf. DO NOT EDIT.
version: v1
deps:
- remote: buf.build
owner: googleapis
repository: googleapis
commit: 28151c0d0a1641bf938a7672c500e01d
- remote: buf.build
owner: grpc-ecosystem
repository: grpc-gateway
commit: 048ae6ff94ca4476b3225904b1078fad
10 changes: 9 additions & 1 deletion buf.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
version: v1
deps:
- buf.build/grpc-ecosystem/grpc-gateway
build:
excludes:
# Buf won't accept a local dependency on the google protos but we need them
# to run api-linter, so just tell buf it ignore it
- google
breaking:
use:
- WIRE_JSON
ignore:
- google
lint:
use:
- DEFAULT
ignore:
- dependencies
- google
30 changes: 0 additions & 30 deletions build/go.mod

This file was deleted.

Loading

0 comments on commit a19522a

Please sign in to comment.