Skip to content

Commit 5a4d95c

Browse files
authored
Replace gogo protobuf with google's protobuf v2 compiler (#119)
**What changed?** gogo/protobuf has been replaced with Google's official go compiler. **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 Note that history loading will not be impacted by the JSON changes: I rewrote history loading to dynamically fix incoming history JSON data (like all our other sdks); you can find this code in `internal/temporalhistoryv1/load.go`. That will be used by our Go sdk as well as our CLI when I get there. **How did you test it?** All tests for this repo pass as do all SDK tests (except for integration tests, which time out on our official repo on master...) **Potential risks** All errors that could arise from this change should be compile-time errors, so your build will be broken if I haven't yet addressed your code. I plan to port _all_ relevant temporal repos as a part of this effort. In addition the enum-rewriting code (the `fix-enums` makefile target) is rather heinous; if the official go plugin for protobuf ever changes how they name their enums (which they shouldn't) it will break.
1 parent 89e3fc1 commit 5a4d95c

File tree

131 files changed

+49009
-132981
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

131 files changed

+49009
-132981
lines changed

Makefile

+49-30
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
$(VERBOSE).SILENT:
2+
all: install test
23
############################# Main targets #############################
34
# Install everything, update submodule, and compile proto files.
45
install: grpc-install mockgen-install goimports-install update-proto
@@ -22,15 +23,15 @@ COLOR := "\e[1;36m%s\e[0m\n"
2223

2324
PINNED_DEPENDENCIES := \
2425

25-
2626
PROTO_ROOT := proto/api
27-
PROTO_FILES = $(shell find $(PROTO_ROOT)/temporal $(PROTO_ROOT)/dependencies -name "*.proto")
27+
HELPER_FILES = $(shell find ./cmd/protoc-gen-go-helpers)
28+
PROTO_FILES = $(shell find $(PROTO_ROOT)/temporal -name "*.proto")
2829
PROTO_DIRS = $(sort $(dir $(PROTO_FILES)))
30+
PROTO_ENUMS := $(shell grep -R '^enum ' $(PROTO_ROOT) | cut -d ' ' -f2)
2931
PROTO_OUT := .
3032
PROTO_IMPORTS = \
31-
-I=$(PROTO_ROOT) \
32-
-I=$(shell go list -modfile build/go.mod -m -f '{{.Dir}}' github.com/temporalio/gogo-protobuf)/protobuf \
33-
-I=$(shell go list -m -f '{{.Dir}}' github.com/grpc-ecosystem/grpc-gateway)/third_party/googleapis
33+
-I=$(PROTO_ROOT)
34+
PROTO_PATHS = paths=source_relative:$(PROTO_OUT)
3435

3536
$(PROTO_OUT):
3637
mkdir $(PROTO_OUT)
@@ -40,24 +41,48 @@ update-proto-submodule:
4041
printf $(COLOR) "Update proto-submodule..."
4142
git submodule update --init --force --remote $(PROTO_ROOT)
4243

44+
4345
##### Compile proto files for go #####
44-
grpc: gogo-grpc fix-path
46+
grpc: go-grpc fix-path fix-enums fix-enum-string copy-helpers
4547

46-
gogo-grpc: clean $(PROTO_OUT)
47-
printf $(COLOR) "Compiling for gogo-gRPC..."
48+
# Only install helper when its source has changed
49+
.go-helpers-installed: $(HELPER_FILES)
50+
printf $(COLOR) "Installing protoc plugin"
51+
@go install ./cmd/protoc-gen-go-helpers
52+
53+
go-grpc: clean .go-helpers-installed $(PROTO_OUT)
54+
printf $(COLOR) "Compile for go-gRPC..."
4855
$(foreach PROTO_DIR,$(PROTO_DIRS),\
4956
protoc --fatal_warnings $(PROTO_IMPORTS) \
50-
--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/gogo/protobuf/protoc-gen-gogo/descriptor,Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types,plugins=grpc,paths=source_relative:$(PROTO_OUT) \
51-
--grpc-gateway_out=allow_patch_feature=false,paths=source_relative:$(PROTO_OUT) \
52-
$(PROTO_DIR)*.proto;)
57+
--go_out=$(PROTO_PATHS) \
58+
--go-grpc_out=$(PROTO_PATHS) \
59+
--grpc-gateway_out=allow_patch_feature=false,$(PROTO_PATHS) \
60+
--go-helpers_out=$(PROTO_PATHS) \
61+
$(PROTO_DIR)*.proto;)
5362

54-
fix-path:
63+
fix-path: go-grpc
5564
mv -f $(PROTO_OUT)/temporal/api/* $(PROTO_OUT) && rm -rf $(PROTO_OUT)/temporal
56-
# Also copy the payload JSON helper
65+
66+
copy-helpers:
67+
# Copy the payload helpers
5768
cp $(PROTO_OUT)/internal/temporalcommonv1/payload_json.go $(PROTO_OUT)/common/v1/
5869

70+
# The generated enums are go are just plain terrible, so we fix them
71+
# by removing the typename prefixes. We already made good choices with our enum
72+
# names, so this shouldn't be an issue
73+
fix-enums: fix-path
74+
printf $(COLOR) "Fixing enum naming..."
75+
$(foreach PROTO_ENUM,$(PROTO_ENUMS),\
76+
$(shell grep -Rl "$(PROTO_ENUM)" $(PROTO_OUT) | grep -E "\.go" | xargs -P 8 sed -i "" -e "s/$(PROTO_ENUM)_\(.*\) $(PROTO_ENUM)/\1 $(PROTO_ENUM)/g;s/\.$(PROTO_ENUM)_\(.*\)/.\1/g"))
77+
78+
# We rely on the old temporal CamelCase JSON enums for presentation, so we rewrite the String method
79+
# on all generated enums
80+
fix-enum-string: fix-enums
81+
printf $(COLOR) "Rewriting enum String methods"
82+
$(shell find . -name "*.pb.go" | xargs go run ./cmd/enumrewriter/main.go -- )
83+
5984
# All generated service files pathes relative to PROTO_OUT.
60-
PROTO_GRPC_SERVICES = $(patsubst $(PROTO_OUT)/%,%,$(shell find $(PROTO_OUT) -name "service.pb.go"))
85+
PROTO_GRPC_SERVICES = $(patsubst $(PROTO_OUT)/%,%,$(shell find $(PROTO_OUT) -name "service_grpc.pb.go"))
6186
service_name = $(firstword $(subst /, ,$(1)))
6287
mock_file_name = $(call service_name,$(1))mock/$(subst $(call service_name,$(1))/,,$(1:go=mock.go))
6388

@@ -75,21 +100,15 @@ goimports:
75100
goimports -w $(PROTO_OUT)
76101

77102
##### Plugins & tools #####
78-
grpc-install: gogo-protobuf-install
79-
printf $(COLOR) "Install/update gRPC plugins..."
80-
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
81-
82-
gogo-protobuf-install: go-protobuf-install
83-
go install github.com/temporalio/gogo-protobuf/protoc-gen-gogoslick@latest
84-
go install -modfile build/go.mod github.com/temporalio/gogo-protobuf/protoc-gen-gogoslick
85-
go install github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway@latest
86-
87-
go-protobuf-install:
88-
go install github.com/golang/protobuf/protoc-gen-go@latest
103+
grpc-install:
104+
@printf $(COLOR) "Install/update grpc and plugins..."
105+
@go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
106+
@go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
107+
@go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway@latest
89108

90109
mockgen-install:
91110
printf $(COLOR) "Install/update mockgen..."
92-
go install github.com/golang/mock/mockgen@v1.6.0
111+
go install -modfile=build/go.mod github.com/golang/mock/mockgen
93112

94113
goimports-install:
95114
printf $(COLOR) "Install/update goimports..."
@@ -111,19 +130,19 @@ gomodtidy:
111130

112131
##### Test #####
113132

114-
test:
115-
go test ./proxy ./serviceerror
133+
test: copy-helpers
134+
go test ./...
116135

117136
##### Check #####
118137

119138
generatorcheck:
120139
printf $(COLOR) "Check generated code is not stale..."
121-
(cd ./cmd/proxygenerator && go mod tidy && go run ./ -verifyOnly)
140+
#(cd ./cmd/proxygenerator && go mod tidy && go run ./ -verifyOnly)
122141

123142
check: generatorcheck
124143

125144
##### Clean #####
126145
clean:
127146
printf $(COLOR) "Deleting generated go files..."
128147
# Delete all directories with *.pb.go and *.mock.go files from $(PROTO_OUT)
129-
find $(PROTO_OUT) \( -name "*.pb.go" -o -name "*.mock.go" \) | xargs -I{} dirname {} | sort -u | xargs rm -rf
148+
find $(PROTO_OUT) \( -name "*.pb.go" -o -name "*.mock.go" -o -name "*.go-helpers.go" \) | xargs -I{} dirname {} | sort -u | xargs rm -rf

batch/v1/message.go-helpers.go

+249
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,249 @@
1+
// The MIT License
2+
//
3+
// Copyright (c) 2022 Temporal Technologies Inc. All rights reserved.
4+
//
5+
// Permission is hereby granted, free of charge, to any person obtaining a copy
6+
// of this software and associated documentation files (the "Software"), to deal
7+
// in the Software without restriction, including without limitation the rights
8+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
// copies of the Software, and to permit persons to whom the Software is
10+
// furnished to do so, subject to the following conditions:
11+
//
12+
// The above copyright notice and this permission notice shall be included in
13+
// all copies or substantial portions of the Software.
14+
//
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
// THE SOFTWARE.
22+
23+
package batch
24+
25+
import (
26+
"google.golang.org/protobuf/proto"
27+
)
28+
29+
// Marshal an object of type BatchOperationInfo to the protobuf v3 wire format
30+
func (val *BatchOperationInfo) Marshal() ([]byte, error) {
31+
return proto.Marshal(val)
32+
}
33+
34+
// Unmarshal an object of type BatchOperationInfo from the protobuf v3 wire format
35+
func (val *BatchOperationInfo) Unmarshal(buf []byte) error {
36+
return proto.Unmarshal(buf, val)
37+
}
38+
39+
// Size returns the size of the object, in bytes, once serialized
40+
func (val *BatchOperationInfo) Size() int {
41+
return proto.Size(val)
42+
}
43+
44+
// Equal returns whether two BatchOperationInfo values are equivalent by recursively
45+
// comparing the message's fields.
46+
// For more information see the documentation for
47+
// https://pkg.go.dev/google.golang.org/protobuf/proto#Equal
48+
func (this *BatchOperationInfo) Equal(that interface{}) bool {
49+
if that == nil {
50+
return this == nil
51+
}
52+
53+
var that1 *BatchOperationInfo
54+
switch t := that.(type) {
55+
case *BatchOperationInfo:
56+
that1 = t
57+
case BatchOperationInfo:
58+
that1 = &t
59+
default:
60+
return false
61+
}
62+
63+
return proto.Equal(this, that1)
64+
}
65+
66+
// Marshal an object of type BatchOperationTermination to the protobuf v3 wire format
67+
func (val *BatchOperationTermination) Marshal() ([]byte, error) {
68+
return proto.Marshal(val)
69+
}
70+
71+
// Unmarshal an object of type BatchOperationTermination from the protobuf v3 wire format
72+
func (val *BatchOperationTermination) Unmarshal(buf []byte) error {
73+
return proto.Unmarshal(buf, val)
74+
}
75+
76+
// Size returns the size of the object, in bytes, once serialized
77+
func (val *BatchOperationTermination) Size() int {
78+
return proto.Size(val)
79+
}
80+
81+
// Equal returns whether two BatchOperationTermination values are equivalent by recursively
82+
// comparing the message's fields.
83+
// For more information see the documentation for
84+
// https://pkg.go.dev/google.golang.org/protobuf/proto#Equal
85+
func (this *BatchOperationTermination) Equal(that interface{}) bool {
86+
if that == nil {
87+
return this == nil
88+
}
89+
90+
var that1 *BatchOperationTermination
91+
switch t := that.(type) {
92+
case *BatchOperationTermination:
93+
that1 = t
94+
case BatchOperationTermination:
95+
that1 = &t
96+
default:
97+
return false
98+
}
99+
100+
return proto.Equal(this, that1)
101+
}
102+
103+
// Marshal an object of type BatchOperationSignal to the protobuf v3 wire format
104+
func (val *BatchOperationSignal) Marshal() ([]byte, error) {
105+
return proto.Marshal(val)
106+
}
107+
108+
// Unmarshal an object of type BatchOperationSignal from the protobuf v3 wire format
109+
func (val *BatchOperationSignal) Unmarshal(buf []byte) error {
110+
return proto.Unmarshal(buf, val)
111+
}
112+
113+
// Size returns the size of the object, in bytes, once serialized
114+
func (val *BatchOperationSignal) Size() int {
115+
return proto.Size(val)
116+
}
117+
118+
// Equal returns whether two BatchOperationSignal values are equivalent by recursively
119+
// comparing the message's fields.
120+
// For more information see the documentation for
121+
// https://pkg.go.dev/google.golang.org/protobuf/proto#Equal
122+
func (this *BatchOperationSignal) Equal(that interface{}) bool {
123+
if that == nil {
124+
return this == nil
125+
}
126+
127+
var that1 *BatchOperationSignal
128+
switch t := that.(type) {
129+
case *BatchOperationSignal:
130+
that1 = t
131+
case BatchOperationSignal:
132+
that1 = &t
133+
default:
134+
return false
135+
}
136+
137+
return proto.Equal(this, that1)
138+
}
139+
140+
// Marshal an object of type BatchOperationCancellation to the protobuf v3 wire format
141+
func (val *BatchOperationCancellation) Marshal() ([]byte, error) {
142+
return proto.Marshal(val)
143+
}
144+
145+
// Unmarshal an object of type BatchOperationCancellation from the protobuf v3 wire format
146+
func (val *BatchOperationCancellation) Unmarshal(buf []byte) error {
147+
return proto.Unmarshal(buf, val)
148+
}
149+
150+
// Size returns the size of the object, in bytes, once serialized
151+
func (val *BatchOperationCancellation) Size() int {
152+
return proto.Size(val)
153+
}
154+
155+
// Equal returns whether two BatchOperationCancellation values are equivalent by recursively
156+
// comparing the message's fields.
157+
// For more information see the documentation for
158+
// https://pkg.go.dev/google.golang.org/protobuf/proto#Equal
159+
func (this *BatchOperationCancellation) Equal(that interface{}) bool {
160+
if that == nil {
161+
return this == nil
162+
}
163+
164+
var that1 *BatchOperationCancellation
165+
switch t := that.(type) {
166+
case *BatchOperationCancellation:
167+
that1 = t
168+
case BatchOperationCancellation:
169+
that1 = &t
170+
default:
171+
return false
172+
}
173+
174+
return proto.Equal(this, that1)
175+
}
176+
177+
// Marshal an object of type BatchOperationDeletion to the protobuf v3 wire format
178+
func (val *BatchOperationDeletion) Marshal() ([]byte, error) {
179+
return proto.Marshal(val)
180+
}
181+
182+
// Unmarshal an object of type BatchOperationDeletion from the protobuf v3 wire format
183+
func (val *BatchOperationDeletion) Unmarshal(buf []byte) error {
184+
return proto.Unmarshal(buf, val)
185+
}
186+
187+
// Size returns the size of the object, in bytes, once serialized
188+
func (val *BatchOperationDeletion) Size() int {
189+
return proto.Size(val)
190+
}
191+
192+
// Equal returns whether two BatchOperationDeletion values are equivalent by recursively
193+
// comparing the message's fields.
194+
// For more information see the documentation for
195+
// https://pkg.go.dev/google.golang.org/protobuf/proto#Equal
196+
func (this *BatchOperationDeletion) Equal(that interface{}) bool {
197+
if that == nil {
198+
return this == nil
199+
}
200+
201+
var that1 *BatchOperationDeletion
202+
switch t := that.(type) {
203+
case *BatchOperationDeletion:
204+
that1 = t
205+
case BatchOperationDeletion:
206+
that1 = &t
207+
default:
208+
return false
209+
}
210+
211+
return proto.Equal(this, that1)
212+
}
213+
214+
// Marshal an object of type BatchOperationReset to the protobuf v3 wire format
215+
func (val *BatchOperationReset) Marshal() ([]byte, error) {
216+
return proto.Marshal(val)
217+
}
218+
219+
// Unmarshal an object of type BatchOperationReset from the protobuf v3 wire format
220+
func (val *BatchOperationReset) Unmarshal(buf []byte) error {
221+
return proto.Unmarshal(buf, val)
222+
}
223+
224+
// Size returns the size of the object, in bytes, once serialized
225+
func (val *BatchOperationReset) Size() int {
226+
return proto.Size(val)
227+
}
228+
229+
// Equal returns whether two BatchOperationReset values are equivalent by recursively
230+
// comparing the message's fields.
231+
// For more information see the documentation for
232+
// https://pkg.go.dev/google.golang.org/protobuf/proto#Equal
233+
func (this *BatchOperationReset) Equal(that interface{}) bool {
234+
if that == nil {
235+
return this == nil
236+
}
237+
238+
var that1 *BatchOperationReset
239+
switch t := that.(type) {
240+
case *BatchOperationReset:
241+
that1 = t
242+
case BatchOperationReset:
243+
that1 = &t
244+
default:
245+
return false
246+
}
247+
248+
return proto.Equal(this, that1)
249+
}

0 commit comments

Comments
 (0)