github.com/ledgerwatch/erigon-lib@v1.0.0/Makefile (about)

     1  GOBINREL = build/bin
     2  GOBIN = $(CURDIR)/$(GOBINREL)
     3  BUILD_TAGS = nosqlite,noboltdb,disable_libutp
     4  GOBUILD = env GO111MODULE=on go build -trimpath -tags $(BUILD_TAGS)
     5  GOTEST = go test -trimpath -tags $(BUILD_TAGS)
     6  GOTEST_NOFUZZ = go test -trimpath --tags=$(BUILD_TAGS),nofuzz
     7  OS = $(shell uname -s)
     8  ARCH = $(shell uname -m)
     9  
    10  ifeq ($(OS),Darwin)
    11  PROTOC_OS := osx
    12  ifeq ($(ARCH),arm64)
    13  ARCH = aarch_64
    14  endif
    15  endif
    16  ifeq ($(OS),Linux)
    17  PROTOC_OS = linux
    18  endif
    19  
    20  PROTOC_INCLUDE = build/include/google
    21  
    22  
    23  default: gen
    24  
    25  gen: grpc mocks
    26  
    27  $(GOBINREL):
    28  	mkdir -p "$(GOBIN)"
    29  
    30  $(GOBINREL)/protoc: | $(GOBINREL)
    31  	$(eval PROTOC_TMP := $(shell mktemp -d))
    32  	curl -sSL https://github.com/protocolbuffers/protobuf/releases/download/v24.2/protoc-24.2-$(PROTOC_OS)-$(ARCH).zip -o "$(PROTOC_TMP)/protoc.zip"
    33  	cd "$(PROTOC_TMP)" && unzip protoc.zip
    34  	cp "$(PROTOC_TMP)/bin/protoc" "$(GOBIN)"
    35  	mkdir -p "$(PROTOC_INCLUDE)"
    36  	cp -R "$(PROTOC_TMP)/include/google/" "$(PROTOC_INCLUDE)"
    37  	rm -rf "$(PROTOC_TMP)"
    38  
    39  # 'protoc-gen-go' tool generates proto messages
    40  $(GOBINREL)/protoc-gen-go: | $(GOBINREL)
    41  	$(GOBUILD) -o "$(GOBIN)/protoc-gen-go" google.golang.org/protobuf/cmd/protoc-gen-go
    42  
    43  # 'protoc-gen-go-grpc' tool generates grpc services
    44  $(GOBINREL)/protoc-gen-go-grpc: | $(GOBINREL)
    45  	$(GOBUILD) -o "$(GOBIN)/protoc-gen-go-grpc" google.golang.org/grpc/cmd/protoc-gen-go-grpc
    46  
    47  protoc-all: $(GOBINREL)/protoc $(PROTOC_INCLUDE) $(GOBINREL)/protoc-gen-go $(GOBINREL)/protoc-gen-go-grpc
    48  
    49  protoc-clean:
    50  	rm -f "$(GOBIN)/protoc"*
    51  	rm -rf "$(PROTOC_INCLUDE)"
    52  
    53  grpc: protoc-all
    54  	go mod vendor
    55  	PATH="$(GOBIN):$(PATH)" protoc --proto_path=vendor/github.com/ledgerwatch/interfaces --go_out=gointerfaces -I=$(PROTOC_INCLUDE) \
    56  		types/types.proto
    57  	PATH="$(GOBIN):$(PATH)" protoc --proto_path=vendor/github.com/ledgerwatch/interfaces --go_out=gointerfaces --go-grpc_out=gointerfaces -I=$(PROTOC_INCLUDE) \
    58  		--go_opt=Mtypes/types.proto=github.com/ledgerwatch/erigon-lib/gointerfaces/types \
    59  		--go-grpc_opt=Mtypes/types.proto=github.com/ledgerwatch/erigon-lib/gointerfaces/types \
    60  		p2psentry/sentry.proto p2psentinel/sentinel.proto \
    61  		remote/kv.proto remote/ethbackend.proto \
    62  		downloader/downloader.proto execution/execution.proto \
    63  		txpool/txpool.proto txpool/mining.proto
    64  	rm -rf vendor
    65  
    66  $(GOBINREL)/moq: | $(GOBINREL)
    67  	$(GOBUILD) -o "$(GOBIN)/moq" github.com/matryer/moq
    68  
    69  mocks: $(GOBINREL)/moq
    70  	rm -f gointerfaces/remote/mocks.go
    71  	rm -f gointerfaces/sentry/mocks.go
    72  	PATH="$(GOBIN):$(PATH)" go generate ./...
    73  
    74  lintci: $(GOBINREL)/golangci-lint
    75  	@"$(GOBIN)/golangci-lint" run --config ./.golangci.yml
    76  
    77  # force re-make golangci-lint
    78  lintci-deps: lintci-deps-clean $(GOBINREL)/golangci-lint
    79  lintci-deps-clean: golangci-lint-clean
    80  
    81  # download and build golangci-lint (https://golangci-lint.run)
    82  $(GOBINREL)/golangci-lint: | $(GOBINREL)
    83  	curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b "$(GOBIN)" v1.54.2
    84  
    85  golangci-lint-clean:
    86  	rm -f "$(GOBIN)/golangci-lint"
    87  
    88  lint-licenses-deps:
    89  	@./tools/licenses_check.sh --install-deps
    90  lint-licenses:
    91  	@./tools/licenses_check.sh
    92  
    93  lint-deps: lintci-deps lint-licenses-deps
    94  lint: lintci lint-licenses
    95  
    96  test:
    97  	$(GOTEST) --count 1 -p 2 ./...
    98  
    99  test-no-fuzz:
   100  	$(GOTEST_NOFUZZ) --count 1 -p 2 ./...