Skip to content

Instantly share code, notes, and snippets.

@mweibel
Created May 24, 2023 11:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mweibel/1b1205f0760e3242531d407d5476bfcb to your computer and use it in GitHub Desktop.
Save mweibel/1b1205f0760e3242531d407d5476bfcb to your computer and use it in GitHub Desktop.
Install Go/gRPC tools with Makefile
# GOBIN indicates the path where go tooling is put.
GOBIN=$(shell go env GOPATH)/bin
##@ Tooling
# Versions
GOLANGCI_LINT_VER=v1.52.2
PROTOC_GEN_GO_VERSION=v1.30.0
PROTOC_GEN_GO_GRPC_VERSION=v1.3.0
PROTOC_GEN_VALIDATE_VERSION=v1.0.0
PROTOC_VERSION=21.9
golangci-lint: $(GOBIN)/golangci-lint-$(GOLANGCI_LINT_VER) ## installs golangci-lint if not yet installed
$(GOBIN)/golangci-lint-$(GOLANGCI_LINT_VER):
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOBIN) $(GOLANGCI_LINT_VER)
mv $(GOBIN)/golangci-lint $(GOBIN)/golangci-lint-$(GOLANGCI_LINT_VER)
ln -sf $(GOBIN)/golangci-lint-$(GOLANGCI_LINT_VER) $(GOBIN)/golangci-lint
golangci-lint --version
protobuf: $(GOBIN)/protoc-gen-go-$(PROTOC_GEN_GO_VERSION) $(GOBIN)/protoc-gen-go-grpc-$(PROTOC_GEN_GO_GRPC_VERSION) $(GOBIN)/protoc-gen-validate-$(PROTOC_GEN_VALIDATE_VERSION) $(HOME)/.local/bin/protoc-$(PROTOC_VERSION) ## installs protobuf binaries
$(GOBIN)/protoc-gen-go-$(PROTOC_GEN_GO_VERSION):
go install google.golang.org/protobuf/cmd/protoc-gen-go@$(PROTOC_GEN_GO_VERSION)
mv $(GOBIN)/protoc-gen-go $(GOBIN)/protoc-gen-go-$(PROTOC_GEN_GO_VERSION)
ln -sf $(GOBIN)/protoc-gen-go-$(PROTOC_GEN_GO_VERSION) $(GOBIN)/protoc-gen-go
$(GOBIN)/protoc-gen-go-grpc-$(PROTOC_GEN_GO_GRPC_VERSION):
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@$(PROTOC_GEN_GO_GRPC_VERSION)
mv $(GOBIN)/protoc-gen-go-grpc $(GOBIN)/protoc-gen-go-grpc-$(PROTOC_GEN_GO_GRPC_VERSION)
ln -sf $(GOBIN)/protoc-gen-go-grpc-$(PROTOC_GEN_GO_GRPC_VERSION) $(GOBIN)/protoc-gen-go-grpc
$(GOBIN)/protoc-gen-validate-$(PROTOC_GEN_VALIDATE_VERSION):
go install github.com/envoyproxy/protoc-gen-validate@$(PROTOC_GEN_VALIDATE_VERSION)
mv $(GOBIN)/protoc-gen-validate $(GOBIN)/protoc-gen-validate-$(PROTOC_GEN_VALIDATE_VERSION)
ln -sf $(GOBIN)/protoc-gen-validate-$(PROTOC_GEN_VALIDATE_VERSION) $(GOBIN)/protoc-gen-validate
PB_REL=https://github.com/protocolbuffers/protobuf/releases
PROTOC_BIN_PATH=$(HOME)/.local/bin
OS=linux
ifeq ($(UNAME_S),Darwin)
OS=osx
endif
$(PROTOC_BIN_PATH)/protoc-$(PROTOC_VERSION):
curl -LO $(PB_REL)/download/v$(PROTOC_VERSION)/protoc-$(PROTOC_VERSION)-$(OS)-x86_64.zip
unzip -o protoc-$(PROTOC_VERSION)-$(OS)-x86_64.zip -d $(HOME)/.local
rm protoc-$(PROTOC_VERSION)-$(OS)-x86_64.zip
mv $(PROTOC_BIN_PATH)/protoc $(PROTOC_BIN_PATH)/protoc-$(PROTOC_VERSION)
ln -sf $(PROTOC_BIN_PATH)/protoc-$(PROTOC_VERSION) $(PROTOC_BIN_PATH)/protoc
@echo
@echo "Make sure to add $(PROTOC_BIN_PATH) to your PATH"
@echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment