Skip to content

Commit 3c89ddc

Browse files
authored
Merge pull request #19 from solo-io/conradhanson/support-optional-proto-field-types
Manage protoc from .bin
2 parents 6735dfd + 2b4d216 commit 3c89ddc

File tree

15 files changed

+231
-164
lines changed

15 files changed

+231
-164
lines changed

.github/workflows/pull_request.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ jobs:
2525
restore-keys: |
2626
${{ runner.os }}-go-
2727
- name: Test
28-
run: make run-tests
28+
run: make install-go-tools run-tests

Makefile

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ EXEC_NAME := $(OUTPUT_DIR)/protoc-gen-ext
88
SOURCES := $(shell find . -name "*.go" | grep -v test.go)
99
VERSION ?= $(shell git describe --tags)
1010

11-
GO_BUILD_FLAGS := GO111MODULE=on CGO_ENABLED=0 GOARCH=amd64
11+
GO_BUILD_FLAGS := GO111MODULE=on CGO_ENABLED=0
1212
GCFLAGS := 'all=-N -l'
1313

1414

@@ -44,14 +44,14 @@ GO_IMPORT_SPACES := ${EXT_IMPORT},\
4444
GO_IMPORT:=$(subst $(space),,$(GO_IMPORT_SPACES))
4545

4646

47-
PHONE: generated-code
47+
.PHONY: generated-code
4848
generated-code:
49-
PATH=$(DEPSGOBIN):$$PATH protoc -I=. --go_out="${EXT_IMPORT}:." extproto/ext.proto
49+
PATH=$(DEPSGOBIN):$$PATH $(DEPSGOBIN)/protoc -I=. -I=./external --go_out="${EXT_IMPORT}:." extproto/ext.proto
5050
PATH=$(DEPSGOBIN):$$PATH cp -r ${PACKAGE}/extproto/* extproto
51-
PATH=$(DEPSGOBIN):$$PATH protoc -I=. -I=./extproto --go_out="." --ext_out="." tests/api/hello.proto
51+
PATH=$(DEPSGOBIN):$$PATH $(DEPSGOBIN)/protoc -I=. -I=./extproto -I=./external --go_out="." --ext_out="." tests/api/hello.proto
5252
PATH=$(DEPSGOBIN):$$PATH cp -r ${PACKAGE}/tests/api/* tests/api/
5353
PATH=$(DEPSGOBIN):$$PATH rm -rf github.com
54-
PATH=$(DEPSGOBIN):$$PATH goimports -w .
54+
PATH=$(DEPSGOBIN):$$PATH $(DEPSGOBIN)/goimports -w .
5555

5656

5757
DEPSGOBIN=$(shell pwd)/_output/.bin
@@ -64,8 +64,39 @@ install-go-tools: install
6464
GOBIN=$(DEPSGOBIN) go install golang.org/x/tools/cmd/goimports
6565
GOBIN=$(DEPSGOBIN) go install github.com/onsi/ginkgo/ginkgo
6666

67+
# proto compiler installation
68+
# no explicit arm build, but x86_64 build works on arm macs
69+
PROTOC_VERSION:=3.15.8
70+
PROTOC_URL:=https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}
71+
.PHONY: install-protoc
72+
install-protoc:
73+
if [ $(shell ${DEPSGOBIN}/protoc --version | grep -c ${PROTOC_VERSION}) -ne 0 ]; then \
74+
echo expected protoc version ${PROTOC_VERSION} already installed ;\
75+
else \
76+
if [ "$(shell uname)" == "Darwin" ]; then \
77+
echo "downloading protoc for osx" ;\
78+
wget $(PROTOC_URL)-osx-x86_64.zip -O $(DEPSGOBIN)/protoc-${PROTOC_VERSION}.zip ;\
79+
elif [ "$(shell uname -m)" == "aarch64" ]; then \
80+
echo "downloading protoc for linux aarch64" ;\
81+
wget $(PROTOC_URL)-linux-aarch_64.zip -O $(DEPSGOBIN)/protoc-${PROTOC_VERSION}.zip ;\
82+
else \
83+
echo "downloading protoc for linux x86-64" ;\
84+
wget $(PROTOC_URL)-linux-x86_64.zip -O $(DEPSGOBIN)/protoc-${PROTOC_VERSION}.zip ;\
85+
fi ;\
86+
unzip $(DEPSGOBIN)/protoc-${PROTOC_VERSION}.zip -d $(DEPSGOBIN)/protoc-${PROTOC_VERSION} ;\
87+
mv $(DEPSGOBIN)/protoc-${PROTOC_VERSION}/bin/protoc $(DEPSGOBIN)/protoc ;\
88+
chmod +x $(DEPSGOBIN)/protoc ;\
89+
@echo manage google protos too, since we have a folder of them based on the protoc version ;\
90+
rm -Rf $(shell pwd)/external/google/protobuf/* ;\
91+
mv $(DEPSGOBIN)/protoc-${PROTOC_VERSION}/include/google/protobuf/*.proto $(shell pwd)/external/google/protobuf ;\
92+
rm -rf $(DEPSGOBIN)/protoc-${PROTOC_VERSION} $(DEPSGOBIN)/protoc-${PROTOC_VERSION}.zip ;\
93+
fi
94+
95+
.PHONY: install-tools
96+
install-tools: install-go-tools install-protoc
97+
6798
.PHONY: run-tests
68-
run-tests: install-go-tools
99+
run-tests:
69100
$(DEPSGOBIN)/ginkgo -r -failFast -trace -progress -race -compilers=4 -failOnPending -noColor $(TEST_PKG)
70101

71102
$(EXEC_NAME):

external/google/protobuf/any.proto

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ syntax = "proto3";
3333
package google.protobuf;
3434

3535
option csharp_namespace = "Google.Protobuf.WellKnownTypes";
36-
option go_package = "github.com/golang/protobuf/ptypes/any";
36+
option go_package = "google.golang.org/protobuf/types/known/anypb";
3737
option java_package = "com.google.protobuf";
3838
option java_outer_classname = "AnyProto";
3939
option java_multiple_files = true;
@@ -77,10 +77,13 @@ option objc_class_prefix = "GPB";
7777
// Example 4: Pack and unpack a message in Go
7878
//
7979
// foo := &pb.Foo{...}
80-
// any, err := ptypes.MarshalAny(foo)
80+
// any, err := anypb.New(foo)
81+
// if err != nil {
82+
// ...
83+
// }
8184
// ...
8285
// foo := &pb.Foo{}
83-
// if err := ptypes.UnmarshalAny(any, foo); err != nil {
86+
// if err := any.UnmarshalTo(foo); err != nil {
8487
// ...
8588
// }
8689
//
@@ -121,7 +124,8 @@ option objc_class_prefix = "GPB";
121124
//
122125
message Any {
123126
// A URL/resource name that uniquely identifies the type of the serialized
124-
// protocol buffer message. The last segment of the URL's path must represent
127+
// protocol buffer message. This string must contain at least
128+
// one "/" character. The last segment of the URL's path must represent
125129
// the fully qualified name of the type (as in
126130
// `path/google.protobuf.Duration`). The name should be in a canonical form
127131
// (e.g., leading "." is not accepted).

external/google/protobuf/api.proto

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ option java_package = "com.google.protobuf";
4040
option java_outer_classname = "ApiProto";
4141
option java_multiple_files = true;
4242
option objc_class_prefix = "GPB";
43-
option go_package = "google.golang.org/genproto/protobuf/api;api";
43+
option go_package = "google.golang.org/protobuf/types/known/apipb";
4444

4545
// Api is a light-weight descriptor for an API Interface.
4646
//
@@ -52,7 +52,6 @@ option go_package = "google.golang.org/genproto/protobuf/api;api";
5252
// this message itself. See https://cloud.google.com/apis/design/glossary for
5353
// detailed terminology.
5454
message Api {
55-
5655
// The fully qualified name of this interface, including package name
5756
// followed by the interface's simple name.
5857
string name = 1;
@@ -99,7 +98,6 @@ message Api {
9998

10099
// Method represents a method of an API interface.
101100
message Method {
102-
103101
// The simple name of this method.
104102
string name = 1;
105103

@@ -169,7 +167,7 @@ message Method {
169167
// The mixin construct implies that all methods in `AccessControl` are
170168
// also declared with same name and request/response types in
171169
// `Storage`. A documentation generator or annotation processor will
172-
// see the effective `Storage.GetAcl` method after inherting
170+
// see the effective `Storage.GetAcl` method after inheriting
173171
// documentation and annotations as follows:
174172
//
175173
// service Storage {

0 commit comments

Comments
 (0)