github.com/aakash4dev/cometbft@v0.38.2/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/aakash4dev/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: check build test install 72 .PHONY: all 73 74 include tests.mk 75 76 ############################################################################### 77 ### Build CometBFT ### 78 ############################################################################### 79 80 build: 81 CGO_ENABLED=$(CGO_ENABLED) go build $(BUILD_FLAGS) -tags '$(BUILD_TAGS)' -o $(OUTPUT) ./cmd/cometbft/ 82 .PHONY: build 83 84 install: 85 CGO_ENABLED=$(CGO_ENABLED) go install $(BUILD_FLAGS) -tags $(BUILD_TAGS) ./cmd/cometbft 86 .PHONY: install 87 88 ############################################################################### 89 ### Metrics ### 90 ############################################################################### 91 92 metrics: testdata-metrics 93 go generate -run="scripts/metricsgen" ./... 94 .PHONY: metrics 95 96 # By convention, the go tool ignores subdirectories of directories named 97 # 'testdata'. This command invokes the generate command on the folder directly 98 # to avoid this. 99 testdata-metrics: 100 ls ./scripts/metricsgen/testdata | xargs -I{} go generate -v -run="scripts/metricsgen" ./scripts/metricsgen/testdata/{} 101 .PHONY: testdata-metrics 102 103 ############################################################################### 104 ### Mocks ### 105 ############################################################################### 106 107 mockery: 108 go generate -run="./scripts/mockery_generate.sh" ./... 109 .PHONY: mockery 110 111 ############################################################################### 112 ### Protobuf ### 113 ############################################################################### 114 115 check-proto-deps: 116 ifeq (,$(shell which protoc-gen-gogofaster)) 117 @go install github.com/cosmos/gogoproto/protoc-gen-gogofaster@latest 118 endif 119 .PHONY: check-proto-deps 120 121 check-proto-format-deps: 122 ifeq (,$(shell which clang-format)) 123 $(error "clang-format is required for Protobuf formatting. See instructions for your platform on how to install it.") 124 endif 125 .PHONY: check-proto-format-deps 126 127 proto-gen: check-proto-deps 128 @echo "Generating Protobuf files" 129 @go run github.com/bufbuild/buf/cmd/buf generate 130 @mv ./proto/tendermint/abci/types.pb.go ./abci/types/ 131 .PHONY: proto-gen 132 133 # These targets are provided for convenience and are intended for local 134 # execution only. 135 proto-lint: check-proto-deps 136 @echo "Linting Protobuf files" 137 @go run github.com/bufbuild/buf/cmd/buf lint 138 .PHONY: proto-lint 139 140 proto-format: check-proto-format-deps 141 @echo "Formatting Protobuf files" 142 @find . -name '*.proto' -path "./proto/*" -exec clang-format -i {} \; 143 .PHONY: proto-format 144 145 proto-check-breaking: check-proto-deps 146 @echo "Checking for breaking changes in Protobuf files against local branch" 147 @echo "Note: This is only useful if your changes have not yet been committed." 148 @echo " Otherwise read up on buf's \"breaking\" command usage:" 149 @echo " https://docs.buf.build/breaking/usage" 150 @go run github.com/bufbuild/buf/cmd/buf breaking --against ".git" 151 .PHONY: proto-check-breaking 152 153 proto-check-breaking-ci: 154 @go run github.com/bufbuild/buf/cmd/buf breaking --against $(HTTPS_GIT)#branch=v0.34.x 155 .PHONY: proto-check-breaking-ci 156 157 ############################################################################### 158 ### Build ABCI ### 159 ############################################################################### 160 161 build_abci: 162 @go build -mod=readonly -i ./abci/cmd/... 163 .PHONY: build_abci 164 165 install_abci: 166 @go install -mod=readonly ./abci/cmd/... 167 .PHONY: install_abci 168 169 ############################################################################### 170 ### Distribution ### 171 ############################################################################### 172 173 # dist builds binaries for all platforms and packages them for distribution 174 # TODO add abci to these scripts 175 dist: 176 @BUILD_TAGS=$(BUILD_TAGS) sh -c "'$(CURDIR)/scripts/dist.sh'" 177 .PHONY: dist 178 179 go-mod-cache: go.sum 180 @echo "--> Download go modules to local cache" 181 @go mod download 182 .PHONY: go-mod-cache 183 184 go.sum: go.mod 185 @echo "--> Ensure dependencies have not been modified" 186 @go mod verify 187 @go mod tidy 188 189 draw_deps: 190 @# requires brew install graphviz or apt-get install graphviz 191 go get github.com/RobotsAndPencils/goviz 192 @goviz -i github.com/aakash4dev/cometbft/cmd/cometbft -d 3 | dot -Tpng -o dependency-graph.png 193 .PHONY: draw_deps 194 195 get_deps_bin_size: 196 @# Copy of build recipe with additional flags to perform binary size analysis 197 $(eval $(shell go build -work -a $(BUILD_FLAGS) -tags $(BUILD_TAGS) -o $(OUTPUT) ./cmd/cometbft/ 2>&1)) 198 @find $(WORK) -type f -name "*.a" | xargs -I{} du -hxs "{}" | sort -rh | sed -e s:${WORK}/::g > deps_bin_size.log 199 @echo "Results can be found here: $(CURDIR)/deps_bin_size.log" 200 .PHONY: get_deps_bin_size 201 202 ############################################################################### 203 ### Libs ### 204 ############################################################################### 205 206 # generates certificates for TLS testing in remotedb and RPC server 207 gen_certs: clean_certs 208 certstrap init --common-name "cometbft.com" --passphrase "" 209 certstrap request-cert --common-name "server" -ip "127.0.0.1" --passphrase "" 210 certstrap sign "server" --CA "cometbft.com" --passphrase "" 211 mv out/server.crt rpc/jsonrpc/server/test.crt 212 mv out/server.key rpc/jsonrpc/server/test.key 213 rm -rf out 214 .PHONY: gen_certs 215 216 # deletes generated certificates 217 clean_certs: 218 rm -f rpc/jsonrpc/server/test.crt 219 rm -f rpc/jsonrpc/server/test.key 220 .PHONY: clean_certs 221 222 ############################################################################### 223 ### Formatting, linting, and vetting ### 224 ############################################################################### 225 226 format: 227 find . -name '*.go' -type f -not -path "*.git*" -not -name '*.pb.go' -not -name '*pb_test.go' | xargs gofmt -w -s 228 find . -name '*.go' -type f -not -path "*.git*" -not -name '*.pb.go' -not -name '*pb_test.go' | xargs goimports -w -local github.com/aakash4dev/cometbft 229 .PHONY: format 230 231 lint: 232 @echo "--> Running linter" 233 @go run github.com/golangci/golangci-lint/cmd/golangci-lint@latest run 234 .PHONY: lint 235 236 vulncheck: 237 @go run golang.org/x/vuln/cmd/govulncheck@latest ./... 238 .PHONY: vulncheck 239 240 DESTINATION = ./index.html.md 241 242 243 ############################################################################### 244 ### Documentation ### 245 ############################################################################### 246 247 # Verify that important design docs have ToC entries. 248 check-docs-toc: 249 @./docs/presubmit.sh 250 .PHONY: check-docs-toc 251 252 ############################################################################### 253 ### Docker image ### 254 ############################################################################### 255 256 # On Linux, you may need to run `DOCKER_BUILDKIT=1 make build-docker` for this 257 # to work. 258 build-docker: 259 docker build \ 260 --label=cometbft \ 261 --tag="cometbft/cometbft" \ 262 -f DOCKER/Dockerfile . 263 .PHONY: build-docker 264 265 ############################################################################### 266 ### Local testnet using docker ### 267 ############################################################################### 268 269 # Build linux binary on other platforms 270 build-linux: 271 GOOS=$(GOOS) GOARCH=$(GOARCH) GOARM=$(GOARM) $(MAKE) build 272 .PHONY: build-linux 273 274 build-docker-localnode: 275 @cd networks/local && make 276 .PHONY: build-docker-localnode 277 278 # Runs `make build COMETBFT_BUILD_OPTIONS=cleveldb` from within an Amazon 279 # Linux (v2)-based Docker build container in order to build an Amazon 280 # Linux-compatible binary. Produces a compatible binary at ./build/cometbft 281 build_c-amazonlinux: 282 $(MAKE) -C ./DOCKER build_amazonlinux_buildimage 283 docker run --rm -it -v `pwd`:/cometbft cometbft/cometbft:build_c-amazonlinux 284 .PHONY: build_c-amazonlinux 285 286 # Run a 4-node testnet locally 287 localnet-start: localnet-stop build-docker-localnode 288 @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 289 docker-compose up 290 .PHONY: localnet-start 291 292 # Stop testnet 293 localnet-stop: 294 docker-compose down 295 .PHONY: localnet-stop 296 297 # Build hooks for dredd, to skip or add information on some steps 298 build-contract-tests-hooks: 299 ifeq ($(OS),Windows_NT) 300 go build -mod=readonly $(BUILD_FLAGS) -o build/contract_tests.exe ./cmd/contract_tests 301 else 302 go build -mod=readonly $(BUILD_FLAGS) -o build/contract_tests ./cmd/contract_tests 303 endif 304 .PHONY: build-contract-tests-hooks 305 306 # Run a nodejs tool to test endpoints against a localnet 307 # The command takes care of starting and stopping the network 308 # prerequisits: build-contract-tests-hooks build-linux 309 # the two build commands were not added to let this command run from generic containers or machines. 310 # The binaries should be built beforehand 311 contract-tests: 312 dredd 313 .PHONY: contract-tests 314 315 # Implements test splitting and running. This is pulled directly from 316 # the github action workflows for better local reproducibility. 317 318 GO_TEST_FILES != find $(CURDIR) -name "*_test.go" 319 320 # default to four splits by default 321 NUM_SPLIT ?= 4 322 323 $(BUILDDIR): 324 mkdir -p $@ 325 326 # The format statement filters out all packages that don't have tests. 327 # Note we need to check for both in-package tests (.TestGoFiles) and 328 # out-of-package tests (.XTestGoFiles). 329 $(BUILDDIR)/packages.txt:$(GO_TEST_FILES) $(BUILDDIR) 330 go list -f "{{ if (or .TestGoFiles .XTestGoFiles) }}{{ .ImportPath }}{{ end }}" ./... | sort > $@ 331 332 split-test-packages:$(BUILDDIR)/packages.txt 333 split -d -n l/$(NUM_SPLIT) $< $<. 334 test-group-%:split-test-packages 335 cat $(BUILDDIR)/packages.txt.$* | xargs go test -mod=readonly -timeout=15m -race -coverprofile=$(BUILDDIR)/$*.profile.out