Skip to content

Commit

Permalink
Merge pull request #19 from solo-io/conradhanson/support-optional-pro…
Browse files Browse the repository at this point in the history
…to-field-types

Manage protoc from .bin
  • Loading branch information
conradhanson authored Jan 24, 2023
2 parents 6735dfd + 2b4d216 commit 3c89ddc
Show file tree
Hide file tree
Showing 15 changed files with 231 additions and 164 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pull_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ jobs:
restore-keys: |
${{ runner.os }}-go-
- name: Test
run: make run-tests
run: make install-go-tools run-tests
43 changes: 37 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ EXEC_NAME := $(OUTPUT_DIR)/protoc-gen-ext
SOURCES := $(shell find . -name "*.go" | grep -v test.go)
VERSION ?= $(shell git describe --tags)

GO_BUILD_FLAGS := GO111MODULE=on CGO_ENABLED=0 GOARCH=amd64
GO_BUILD_FLAGS := GO111MODULE=on CGO_ENABLED=0
GCFLAGS := 'all=-N -l'


Expand Down Expand Up @@ -44,14 +44,14 @@ GO_IMPORT_SPACES := ${EXT_IMPORT},\
GO_IMPORT:=$(subst $(space),,$(GO_IMPORT_SPACES))


PHONE: generated-code
.PHONY: generated-code
generated-code:
PATH=$(DEPSGOBIN):$$PATH protoc -I=. --go_out="${EXT_IMPORT}:." extproto/ext.proto
PATH=$(DEPSGOBIN):$$PATH $(DEPSGOBIN)/protoc -I=. -I=./external --go_out="${EXT_IMPORT}:." extproto/ext.proto
PATH=$(DEPSGOBIN):$$PATH cp -r ${PACKAGE}/extproto/* extproto
PATH=$(DEPSGOBIN):$$PATH protoc -I=. -I=./extproto --go_out="." --ext_out="." tests/api/hello.proto
PATH=$(DEPSGOBIN):$$PATH $(DEPSGOBIN)/protoc -I=. -I=./extproto -I=./external --go_out="." --ext_out="." tests/api/hello.proto
PATH=$(DEPSGOBIN):$$PATH cp -r ${PACKAGE}/tests/api/* tests/api/
PATH=$(DEPSGOBIN):$$PATH rm -rf github.com
PATH=$(DEPSGOBIN):$$PATH goimports -w .
PATH=$(DEPSGOBIN):$$PATH $(DEPSGOBIN)/goimports -w .


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

# proto compiler installation
# no explicit arm build, but x86_64 build works on arm macs
PROTOC_VERSION:=3.15.8
PROTOC_URL:=https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}
.PHONY: install-protoc
install-protoc:
if [ $(shell ${DEPSGOBIN}/protoc --version | grep -c ${PROTOC_VERSION}) -ne 0 ]; then \
echo expected protoc version ${PROTOC_VERSION} already installed ;\
else \
if [ "$(shell uname)" == "Darwin" ]; then \
echo "downloading protoc for osx" ;\
wget $(PROTOC_URL)-osx-x86_64.zip -O $(DEPSGOBIN)/protoc-${PROTOC_VERSION}.zip ;\
elif [ "$(shell uname -m)" == "aarch64" ]; then \
echo "downloading protoc for linux aarch64" ;\
wget $(PROTOC_URL)-linux-aarch_64.zip -O $(DEPSGOBIN)/protoc-${PROTOC_VERSION}.zip ;\
else \
echo "downloading protoc for linux x86-64" ;\
wget $(PROTOC_URL)-linux-x86_64.zip -O $(DEPSGOBIN)/protoc-${PROTOC_VERSION}.zip ;\
fi ;\
unzip $(DEPSGOBIN)/protoc-${PROTOC_VERSION}.zip -d $(DEPSGOBIN)/protoc-${PROTOC_VERSION} ;\
mv $(DEPSGOBIN)/protoc-${PROTOC_VERSION}/bin/protoc $(DEPSGOBIN)/protoc ;\
chmod +x $(DEPSGOBIN)/protoc ;\
@echo manage google protos too, since we have a folder of them based on the protoc version ;\
rm -Rf $(shell pwd)/external/google/protobuf/* ;\
mv $(DEPSGOBIN)/protoc-${PROTOC_VERSION}/include/google/protobuf/*.proto $(shell pwd)/external/google/protobuf ;\
rm -rf $(DEPSGOBIN)/protoc-${PROTOC_VERSION} $(DEPSGOBIN)/protoc-${PROTOC_VERSION}.zip ;\
fi

.PHONY: install-tools
install-tools: install-go-tools install-protoc

.PHONY: run-tests
run-tests: install-go-tools
run-tests:
$(DEPSGOBIN)/ginkgo -r -failFast -trace -progress -race -compilers=4 -failOnPending -noColor $(TEST_PKG)

$(EXEC_NAME):
Expand Down
12 changes: 8 additions & 4 deletions external/google/protobuf/any.proto
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ syntax = "proto3";
package google.protobuf;

option csharp_namespace = "Google.Protobuf.WellKnownTypes";
option go_package = "github.com/golang/protobuf/ptypes/any";
option go_package = "google.golang.org/protobuf/types/known/anypb";
option java_package = "com.google.protobuf";
option java_outer_classname = "AnyProto";
option java_multiple_files = true;
Expand Down Expand Up @@ -77,10 +77,13 @@ option objc_class_prefix = "GPB";
// Example 4: Pack and unpack a message in Go
//
// foo := &pb.Foo{...}
// any, err := ptypes.MarshalAny(foo)
// any, err := anypb.New(foo)
// if err != nil {
// ...
// }
// ...
// foo := &pb.Foo{}
// if err := ptypes.UnmarshalAny(any, foo); err != nil {
// if err := any.UnmarshalTo(foo); err != nil {
// ...
// }
//
Expand Down Expand Up @@ -121,7 +124,8 @@ option objc_class_prefix = "GPB";
//
message Any {
// A URL/resource name that uniquely identifies the type of the serialized
// protocol buffer message. The last segment of the URL's path must represent
// protocol buffer message. This string must contain at least
// one "/" character. The last segment of the URL's path must represent
// the fully qualified name of the type (as in
// `path/google.protobuf.Duration`). The name should be in a canonical form
// (e.g., leading "." is not accepted).
Expand Down
6 changes: 2 additions & 4 deletions external/google/protobuf/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ option java_package = "com.google.protobuf";
option java_outer_classname = "ApiProto";
option java_multiple_files = true;
option objc_class_prefix = "GPB";
option go_package = "google.golang.org/genproto/protobuf/api;api";
option go_package = "google.golang.org/protobuf/types/known/apipb";

// Api is a light-weight descriptor for an API Interface.
//
Expand All @@ -52,7 +52,6 @@ option go_package = "google.golang.org/genproto/protobuf/api;api";
// this message itself. See https://cloud.google.com/apis/design/glossary for
// detailed terminology.
message Api {

// The fully qualified name of this interface, including package name
// followed by the interface's simple name.
string name = 1;
Expand Down Expand Up @@ -99,7 +98,6 @@ message Api {

// Method represents a method of an API interface.
message Method {

// The simple name of this method.
string name = 1;

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

0 comments on commit 3c89ddc

Please sign in to comment.