go.ligato.io/vpp-agent/v3@v3.5.0/scripts/make/buf.make (about) 1 ifndef CACHE_BIN 2 $(error CACHE_BIN is not set) 3 endif 4 ifndef UNAME_OS 5 $(error UNAME_OS is not set) 6 endif 7 ifndef UNAME_ARCH 8 $(error UNAME_ARCH is not set) 9 endif 10 11 REMOTE_GIT := https://github.com/ligato/vpp-agent.git 12 CHECK_BREAKING_BRANCH := master 13 14 # https://github.com/bufbuild/buf/releases 20200724 15 BUF_VERSION := 0.51.1 16 # https://github.com/protocolbuffers/protobuf-go 20200624 17 PROTOC_GEN_GO_VERSION ?= v1.27.1 18 # https://github.com/grpc/grpc-go 20200730 19 PROTOC_GEN_GO_GRPC_VERSION ?= v1.38.0 20 # https://github.com/protocolbuffers/protobuf/releases 20200729 21 PROTOC_VERSION ?= 3.17.3 22 23 GO_BINS := $(GO_BINS) \ 24 buf \ 25 protoc-gen-buf-check-breaking \ 26 protoc-gen-buf-check-lint 27 28 PROTO_PATH := proto 29 PROTOC_GEN_GO_OUT := proto 30 31 PROTOC_GEN_GO_PARAMETER ?= paths=source_relative 32 33 ifeq ($(UNAME_OS),Darwin) 34 PROTOC_OS := osx 35 endif 36 ifeq ($(UNAME_OS),Linux) 37 PROTOC_OS = linux 38 endif 39 PROTOC_ARCH := $(UNAME_ARCH) 40 41 IMAGE_DIR=$(BUILD_DIR)/image 42 43 .PHONY: buf-image 44 buf-image: $(BUF) 45 @echo "# Building buf image" 46 mkdir -p $(IMAGE_DIR)/$(VERSION) 47 buf image build -o $(IMAGE_DIR)/$(VERSION)/image.bin 48 buf image build -o $(IMAGE_DIR)/$(VERSION)/image.json 49 50 # BUF points to the marker file for the installed version. 51 # 52 # If BUF_VERSION is changed, the binary will be re-downloaded. 53 BUF := $(CACHE_VERSIONS)/buf/$(BUF_VERSION) 54 $(BUF): 55 @rm -f $(CACHE_BIN)/buf 56 @mkdir -p $(CACHE_BIN) 57 curl -sSL \ 58 "https://github.com/bufbuild/buf/releases/download/v$(BUF_VERSION)/buf-$(UNAME_OS)-$(UNAME_ARCH)" \ 59 -o "$(CACHE_BIN)/buf" 60 chmod +x "$(CACHE_BIN)/buf" 61 @rm -rf $(dir $(BUF)) 62 @mkdir -p $(dir $(BUF)) 63 @touch $(BUF) 64 65 PROTOC := $(CACHE_VERSIONS)/protoc/$(PROTOC_VERSION) 66 $(PROTOC): 67 @if ! command -v curl >/dev/null 2>/dev/null; then echo "error: curl must be installed" >&2; exit 1; fi 68 @if ! command -v unzip >/dev/null 2>/dev/null; then echo "error: unzip must be installed" >&2; exit 1; fi 69 @rm -f $(CACHE_BIN)/protoc 70 @rm -rf $(CACHE_INCLUDE)/google 71 @mkdir -p $(CACHE_BIN) $(CACHE_INCLUDE) 72 $(eval PROTOC_TMP := $(shell mktemp -d)) 73 cd $(PROTOC_TMP); curl -sSL https://github.com/protocolbuffers/protobuf/releases/download/v$(PROTOC_VERSION)/protoc-$(PROTOC_VERSION)-$(PROTOC_OS)-$(PROTOC_ARCH).zip -o protoc.zip 74 cd $(PROTOC_TMP); unzip protoc.zip && mv bin/protoc $(CACHE_BIN)/protoc && mv include/google $(CACHE_INCLUDE)/google 75 @rm -rf $(PROTOC_TMP) 76 @rm -rf $(dir $(PROTOC)) 77 @mkdir -p $(dir $(PROTOC)) 78 @touch $(PROTOC) 79 80 PROTOC_GEN_GO := $(CACHE_VERSIONS)/protoc-gen-go/$(PROTOC_GEN_GO_VERSION) 81 $(PROTOC_GEN_GO): 82 @rm -f $(GOBIN)/protoc-gen-go 83 $(eval PROTOC_GEN_GO_TMP := $(shell mktemp -d)) 84 cd $(PROTOC_GEN_GO_TMP); go install google.golang.org/protobuf/cmd/protoc-gen-go@$(PROTOC_GEN_GO_VERSION) 85 @rm -rf $(PROTOC_GEN_GO_TMP) 86 @rm -rf $(dir $(PROTOC_GEN_GO)) 87 @mkdir -p $(dir $(PROTOC_GEN_GO)) 88 @touch $(PROTOC_GEN_GO) 89 90 PROTOC_GEN_GO_GRPC := $(CACHE_VERSIONS)/protoc-gen-go-grpc/$(PROTOC_GEN_GO_GRPC_VERSION) 91 $(PROTOC_GEN_GO_GRPC): 92 @if ! command -v git >/dev/null 2>/dev/null; then echo "error: git must be installed" >&2; exit 1; fi 93 @rm -f $(GOBIN)/protoc-gen-go-grpc 94 $(eval PROTOC_GEN_GO_GRPC_TMP := $(shell mktemp -d)) 95 #cd $(PROTOC_GEN_GO_GRPC_TMP); go get -u -v google.golang.org/grpc/cmd/protoc-gen-go-grpc@$(PROTOC_GEN_GO_GRPC_VERSION) 96 cd $(PROTOC_GEN_GO_GRPC_TMP); git clone -b $(PROTOC_GEN_GO_GRPC_VERSION) https://github.com/grpc/grpc-go 97 cd $(PROTOC_GEN_GO_GRPC_TMP); cd grpc-go/cmd/protoc-gen-go-grpc && go install . 98 @rm -rf $(PROTOC_GEN_GO_GRPC_TMP) 99 @rm -rf $(dir $(PROTOC_GEN_GO_GRPC)) 100 @mkdir -p $(dir $(PROTOC_GEN_GO_GRPC)) 101 @touch $(PROTOC_GEN_GO_GRPC) 102 103 .PHONY: buf-ls-packages 104 buf-ls-packages: 105 buf image build --exclude-imports --exclude-source-info \ 106 -o -#format=json | jq '.file[] | .package' | sort | uniq 107 108 .PHONY: buf-ls-files 109 buf-ls-files: 110 buf image build --exclude-imports --exclude-source-info \ 111 -o -#format=json | jq '.file[] | .name' | sort | uniq 112 113 # buf-deps allows us to install deps without running any checks. 114 115 .PHONY: buf-deps 116 buf-deps: $(BUF) 117 118 # buf-lint is what we run when developing 119 # this does linting for proto files 120 121 .PHONY: buf-lint 122 buf-lint: $(BUF) 123 buf check lint 124 125 # buf-breaking-local is what we run when testing locally 126 # this does breaking change detection against our local git repository 127 128 .PHONY: buf-breaking-local 129 buf-breaking-local: $(BUF) 130 buf check breaking --against-input '.git#branch=$(CHECK_BREAKING_BRANCH)' 131 132 # buf-breaking is what we run when testing in most CI providers 133 # this does breaking change detection against our remote git repository 134 135 .PHONY: buf-breaking 136 buf-breaking: $(BUF) 137 buf check breaking --timeout 60s \ 138 --against-input "$(REMOTE_GIT)#branch=$(CHECK_BREAKING_BRANCH)" 139 140 141 .PHONY: protocgengoclean 142 protocgengoclean: 143 find "$(PROTOC_GEN_GO_OUT)" -name "*.pb.go" -exec rm -drfv '{}' \; 144 145 .PHONY: protocgengo 146 protocgengo: protocgengoclean $(PROTOC) $(PROTOC_GEN_GO) $(PROTOC_GEN_GO_GRPC) 147 bash scripts/protoc_gen_go.sh "$(PROTO_PATH)" "$(PROTOC_GEN_GO_OUT)" "$(PROTOC_GEN_GO_PARAMETER)"