github.com/KYVENetwork/cometbft/v38@v38.0.3/Makefile (about) 1 include common.mk 2 3 PACKAGES=$(shell go list ./...) 4 BUILDDIR?=$(CURDIR)/build 5 OUTPUT?=$(BUILDDIR)/cometbft 6 7 HTTPS_GIT := https://github.com/cometbft/cometbft.git 8 CGO_ENABLED ?= 0 9 10 # Process Docker environment varible TARGETPLATFORM 11 # in order to build binary with correspondent ARCH 12 # by default will always build for linux/amd64 13 TARGETPLATFORM ?= 14 GOOS ?= linux 15 GOARCH ?= amd64 16 GOARM ?= 17 18 ifeq (linux/arm,$(findstring linux/arm,$(TARGETPLATFORM))) 19 GOOS=linux 20 GOARCH=arm 21 GOARM=7 22 endif 23 24 ifeq (linux/arm/v6,$(findstring linux/arm/v6,$(TARGETPLATFORM))) 25 GOOS=linux 26 GOARCH=arm 27 GOARM=6 28 endif 29 30 ifeq (linux/arm64,$(findstring linux/arm64,$(TARGETPLATFORM))) 31 GOOS=linux 32 GOARCH=arm64 33 GOARM=7 34 endif 35 36 ifeq (linux/386,$(findstring linux/386,$(TARGETPLATFORM))) 37 GOOS=linux 38 GOARCH=386 39 endif 40 41 ifeq (linux/amd64,$(findstring linux/amd64,$(TARGETPLATFORM))) 42 GOOS=linux 43 GOARCH=amd64 44 endif 45 46 ifeq (linux/mips,$(findstring linux/mips,$(TARGETPLATFORM))) 47 GOOS=linux 48 GOARCH=mips 49 endif 50 51 ifeq (linux/mipsle,$(findstring linux/mipsle,$(TARGETPLATFORM))) 52 GOOS=linux 53 GOARCH=mipsle 54 endif 55 56 ifeq (linux/mips64,$(findstring linux/mips64,$(TARGETPLATFORM))) 57 GOOS=linux 58 GOARCH=mips64 59 endif 60 61 ifeq (linux/mips64le,$(findstring linux/mips64le,$(TARGETPLATFORM))) 62 GOOS=linux 63 GOARCH=mips64le 64 endif 65 66 ifeq (linux/riscv64,$(findstring linux/riscv64,$(TARGETPLATFORM))) 67 GOOS=linux 68 GOARCH=riscv64 69 endif 70 71 #? all: Run target check, build, test and install 72 all: check build test install 73 .PHONY: all 74 75 include tests.mk 76 77 ############################################################################### 78 ### Build CometBFT ### 79 ############################################################################### 80 81 #? build: Build CometBFT 82 build: 83 CGO_ENABLED=$(CGO_ENABLED) go build $(BUILD_FLAGS) -tags '$(BUILD_TAGS)' -o $(OUTPUT) ./cmd/cometbft/ 84 .PHONY: build 85 86 #? install: Install CometBFT to GOBIN 87 install: 88 CGO_ENABLED=$(CGO_ENABLED) go install $(BUILD_FLAGS) -tags $(BUILD_TAGS) ./cmd/cometbft 89 .PHONY: install 90 91 ############################################################################### 92 ### Metrics ### 93 ############################################################################### 94 95 #? metrics: Generate metrics 96 metrics: testdata-metrics 97 go generate -run="scripts/metricsgen" ./... 98 .PHONY: metrics 99 100 # By convention, the go tool ignores subdirectories of directories named 101 # 'testdata'. This command invokes the generate command on the folder directly 102 # to avoid this. 103 #? testdata-metrics: Generate test data for metrics 104 testdata-metrics: 105 ls ./scripts/metricsgen/testdata | xargs -I{} go generate -v -run="scripts/metricsgen" ./scripts/metricsgen/testdata/{} 106 .PHONY: testdata-metrics 107 108 ############################################################################### 109 ### Mocks ### 110 ############################################################################### 111 112 #? mockery: Generate test mocks 113 mockery: 114 go generate -run="./scripts/mockery_generate.sh" ./... 115 .PHONY: mockery 116 117 ############################################################################### 118 ### Protobuf ### 119 ############################################################################### 120 121 #? check-proto-deps: Check protobuf deps 122 check-proto-deps: 123 ifeq (,$(shell which protoc-gen-gogofaster)) 124 @go install github.com/cosmos/gogoproto/protoc-gen-gogofaster@latest 125 endif 126 .PHONY: check-proto-deps 127 128 #? check-proto-format-deps: Check protobuf format deps 129 check-proto-format-deps: 130 ifeq (,$(shell which clang-format)) 131 $(error "clang-format is required for Protobuf formatting. See instructions for your platform on how to install it.") 132 endif 133 .PHONY: check-proto-format-deps 134 135 #? proto-gen: Generate protobuf files 136 proto-gen: check-proto-deps 137 @echo "Generating Protobuf files" 138 @go run github.com/bufbuild/buf/cmd/buf generate 139 @mv ./proto/cometbft/v38/abci/types.pb.go ./abci/types/ 140 @cp ./proto/cometbft/v38/rpc/grpc/types.pb.go ./rpc/grpc 141 .PHONY: proto-gen 142 143 # These targets are provided for convenience and are intended for local 144 # execution only. 145 #? proto-lint: Lint protobuf files 146 proto-lint: check-proto-deps 147 @echo "Linting Protobuf files" 148 @go run github.com/bufbuild/buf/cmd/buf lint 149 .PHONY: proto-lint 150 151 #? proto-format: Format protobuf files 152 proto-format: check-proto-format-deps 153 @echo "Formatting Protobuf files" 154 @find . -name '*.proto' -path "./proto/*" -exec clang-format -i {} \; 155 .PHONY: proto-format 156 157 #? proto-check-breaking: Check for breaking changes in Protobuf files against local branch. This is only useful if your changes have not yet been committed 158 proto-check-breaking: check-proto-deps 159 @echo "Checking for breaking changes in Protobuf files against local branch" 160 @echo "Note: This is only useful if your changes have not yet been committed." 161 @echo " Otherwise read up on buf's \"breaking\" command usage:" 162 @echo " https://docs.buf.build/breaking/usage" 163 @go run github.com/bufbuild/buf/cmd/buf breaking --against ".git" 164 .PHONY: proto-check-breaking 165 166 proto-check-breaking-ci: 167 @go run github.com/bufbuild/buf/cmd/buf breaking --against $(HTTPS_GIT)#branch=v0.34.x 168 .PHONY: proto-check-breaking-ci 169 170 ############################################################################### 171 ### Build ABCI ### 172 ############################################################################### 173 174 #? build_abci: Build abci 175 build_abci: 176 @go build -mod=readonly -i ./abci/cmd/... 177 .PHONY: build_abci 178 179 #? install_abci: Install abci 180 install_abci: 181 @go install -mod=readonly ./abci/cmd/... 182 .PHONY: install_abci 183 184 ############################################################################### 185 ### Distribution ### 186 ############################################################################### 187 188 # dist builds binaries for all platforms and packages them for distribution 189 # TODO add abci to these scripts 190 #? dist: Build binaries for all platforms and package them for distribution 191 dist: 192 @BUILD_TAGS=$(BUILD_TAGS) sh -c "'$(CURDIR)/scripts/dist.sh'" 193 .PHONY: dist 194 195 #? go-mod-cache: Download go modules to local cache 196 go-mod-cache: go.sum 197 @echo "--> Download go modules to local cache" 198 @go mod download 199 .PHONY: go-mod-cache 200 201 #? go.sum: Ensure dependencies have not been modified 202 go.sum: go.mod 203 @echo "--> Ensure dependencies have not been modified" 204 @go mod verify 205 @go mod tidy 206 207 #? draw_deps: Generate deps graph 208 draw_deps: 209 @# requires brew install graphviz or apt-get install graphviz 210 go get github.com/RobotsAndPencils/goviz 211 @goviz -i github.com/KYVENetwork/cometbft/v38/cmd/cometbft -d 3 | dot -Tpng -o dependency-graph.png 212 .PHONY: draw_deps 213 214 get_deps_bin_size: 215 @# Copy of build recipe with additional flags to perform binary size analysis 216 $(eval $(shell go build -work -a $(BUILD_FLAGS) -tags $(BUILD_TAGS) -o $(OUTPUT) ./cmd/cometbft/ 2>&1)) 217 @find $(WORK) -type f -name "*.a" | xargs -I{} du -hxs "{}" | sort -rh | sed -e s:${WORK}/::g > deps_bin_size.log 218 @echo "Results can be found here: $(CURDIR)/deps_bin_size.log" 219 .PHONY: get_deps_bin_size 220 221 ############################################################################### 222 ### Libs ### 223 ############################################################################### 224 225 #? gen_certs: Generate certificates for TLS testing in remotedb and RPC server 226 gen_certs: clean_certs 227 certstrap init --common-name "cometbft.com" --passphrase "" 228 certstrap request-cert --common-name "server" -ip "127.0.0.1" --passphrase "" 229 certstrap sign "server" --CA "cometbft.com" --passphrase "" 230 mv out/server.crt rpc/jsonrpc/server/test.crt 231 mv out/server.key rpc/jsonrpc/server/test.key 232 rm -rf out 233 .PHONY: gen_certs 234 235 #? clean_certs: Delete generated certificates 236 clean_certs: 237 rm -f rpc/jsonrpc/server/test.crt 238 rm -f rpc/jsonrpc/server/test.key 239 .PHONY: clean_certs 240 241 ############################################################################### 242 ### Formatting, linting, and vetting ### 243 ############################################################################### 244 245 format: 246 find . -name '*.go' -type f -not -path "*.git*" -not -name '*.pb.go' -not -name '*pb_test.go' | xargs gofmt -w -s 247 find . -name '*.go' -type f -not -path "*.git*" -not -name '*.pb.go' -not -name '*pb_test.go' | xargs goimports -w -local github.com/cometbft/cometbft 248 .PHONY: format 249 250 #? lint: Run latest golangci-lint linter 251 lint: 252 @echo "--> Running linter" 253 @go run github.com/golangci/golangci-lint/cmd/golangci-lint@latest run 254 .PHONY: lint 255 256 # https://github.com/KYVENetwork/cometbft/v38/pull/1925#issuecomment-1875127862 257 # Revisit using lint-format after CometBFT v1 release and/or after 2024-06-01. 258 #lint-format: 259 # @go run github.com/golangci/golangci-lint/cmd/golangci-lint@latest run --fix 260 # @go run mvdan.cc/gofumpt -l -w ./.. 261 #.PHONY: lint-format 262 263 #? vulncheck: Run latest govulncheck 264 vulncheck: 265 @go run golang.org/x/vuln/cmd/govulncheck@latest ./... 266 .PHONY: vulncheck 267 268 #? lint-typo: Run codespell to check typos 269 lint-typo: 270 which codespell || pip3 install codespell 271 @codespell 272 .PHONY: lint-typo 273 274 #? lint-typo: Run codespell to auto fix typos 275 lint-fix-typo: 276 @codespell -w 277 .PHONY: lint-fix-typo 278 279 DESTINATION = ./index.html.md 280 281 282 ############################################################################### 283 ### Documentation ### 284 ############################################################################### 285 286 #? check-docs-toc: Verify that important design docs have ToC entries. 287 check-docs-toc: 288 @./docs/presubmit.sh 289 .PHONY: check-docs-toc 290 291 ############################################################################### 292 ### Docker image ### 293 ############################################################################### 294 295 # On Linux, you may need to run `DOCKER_BUILDKIT=1 make build-docker` for this 296 # to work. 297 #? build-docker: Build docker image cometbft/cometbft 298 build-docker: 299 docker build \ 300 --label=cometbft \ 301 --tag="cometbft/cometbft" \ 302 -f DOCKER/Dockerfile . 303 .PHONY: build-docker 304 305 ############################################################################### 306 ### Local testnet using docker ### 307 ############################################################################### 308 309 #? build-linux: Build linux binary on other platforms 310 build-linux: 311 GOOS=$(GOOS) GOARCH=$(GOARCH) GOARM=$(GOARM) $(MAKE) build 312 .PHONY: build-linux 313 314 #? build-docker-localnode: Build the "localnode" docker image 315 build-docker-localnode: 316 @cd networks/local && make 317 .PHONY: build-docker-localnode 318 319 # Runs `make build COMETBFT_BUILD_OPTIONS=cleveldb` from within an Amazon 320 # Linux (v2)-based Docker build container in order to build an Amazon 321 # Linux-compatible binary. Produces a compatible binary at ./build/cometbft 322 build_c-amazonlinux: 323 $(MAKE) -C ./DOCKER build_amazonlinux_buildimage 324 docker run --rm -it -v `pwd`:/cometbft cometbft/cometbft:build_c-amazonlinux 325 .PHONY: build_c-amazonlinux 326 327 #? localnet-start: Run a 4-node testnet locally 328 localnet-start: localnet-stop build-docker-localnode 329 @if ! [ -f build/node0/config/genesis.json ]; then docker run --rm -v $(CURDIR)/build:/cometbft:Z cometbft/localnode testnet --config /etc/cometbft/config-template.toml --o . --starting-ip-address 192.167.10.2; fi 330 docker-compose up 331 .PHONY: localnet-start 332 333 #? localnet-stop: Stop testnet 334 localnet-stop: 335 docker-compose down 336 .PHONY: localnet-stop 337 338 #? build-contract-tests-hooks: Build hooks for dredd, to skip or add information on some steps 339 build-contract-tests-hooks: 340 ifeq ($(OS),Windows_NT) 341 go build -mod=readonly $(BUILD_FLAGS) -o build/contract_tests.exe ./cmd/contract_tests 342 else 343 go build -mod=readonly $(BUILD_FLAGS) -o build/contract_tests ./cmd/contract_tests 344 endif 345 .PHONY: build-contract-tests-hooks 346 347 #? contract-tests: Run a nodejs tool to test endpoints against a localnet 348 # The command takes care of starting and stopping the network 349 # prerequisits: build-contract-tests-hooks build-linux 350 # the two build commands were not added to let this command run from generic containers or machines. 351 # The binaries should be built beforehand 352 contract-tests: 353 dredd 354 .PHONY: contract-tests 355 356 # Implements test splitting and running. This is pulled directly from 357 # the github action workflows for better local reproducibility. 358 359 GO_TEST_FILES != find $(CURDIR) -name "*_test.go" 360 361 # default to four splits by default 362 NUM_SPLIT ?= 4 363 364 $(BUILDDIR): 365 mkdir -p $@ 366 367 # The format statement filters out all packages that don't have tests. 368 # Note we need to check for both in-package tests (.TestGoFiles) and 369 # out-of-package tests (.XTestGoFiles). 370 $(BUILDDIR)/packages.txt:$(GO_TEST_FILES) $(BUILDDIR) 371 go list -f "{{ if (or .TestGoFiles .XTestGoFiles) }}{{ .ImportPath }}{{ end }}" ./... | sort > $@ 372 373 split-test-packages:$(BUILDDIR)/packages.txt 374 split -d -n l/$(NUM_SPLIT) $< $<. 375 test-group-%:split-test-packages 376 cat $(BUILDDIR)/packages.txt.$* | xargs go test -mod=readonly -timeout=15m -race -coverprofile=$(BUILDDIR)/$*.profile.out 377 378 #? help: Get more info on make commands. 379 help: Makefile 380 @echo " Choose a command run in comebft:" 381 @sed -n 's/^#?//p' $< | column -t -s ':' | sort | sed -e 's/^/ /' 382 .PHONY: help