github.com/badrootd/nibiru-cometbft@v0.37.5-0.20240307173500-2a75559eee9b/Makefile (about) 1 PACKAGES=$(shell go list ./...) 2 BUILDDIR?=$(CURDIR)/build 3 OUTPUT?=$(BUILDDIR)/cometbft 4 5 BUILD_TAGS?=cometbft 6 7 COMMIT_HASH := $(shell git rev-parse --short HEAD) 8 LD_FLAGS = -X github.com/cometbft/cometbft/version.TMGitCommitHash=$(COMMIT_HASH) 9 BUILD_FLAGS = -mod=readonly -ldflags "$(LD_FLAGS)" 10 HTTPS_GIT := https://github.com/cometbft/cometbft.git 11 CGO_ENABLED ?= 0 12 13 # handle nostrip 14 ifeq (,$(findstring nostrip,$(COMETBFT_BUILD_OPTIONS))) 15 BUILD_FLAGS += -trimpath 16 LD_FLAGS += -s -w 17 endif 18 19 # handle race 20 ifeq (race,$(findstring race,$(COMETBFT_BUILD_OPTIONS))) 21 CGO_ENABLED=1 22 BUILD_FLAGS += -race 23 endif 24 25 # handle cleveldb 26 ifeq (cleveldb,$(findstring cleveldb,$(COMETBFT_BUILD_OPTIONS))) 27 CGO_ENABLED=1 28 BUILD_TAGS += cleveldb 29 endif 30 31 # handle badgerdb 32 ifeq (badgerdb,$(findstring badgerdb,$(COMETBFT_BUILD_OPTIONS))) 33 BUILD_TAGS += badgerdb 34 endif 35 36 # handle rocksdb 37 ifeq (rocksdb,$(findstring rocksdb,$(COMETBFT_BUILD_OPTIONS))) 38 CGO_ENABLED=1 39 BUILD_TAGS += rocksdb 40 endif 41 42 # handle boltdb 43 ifeq (boltdb,$(findstring boltdb,$(COMETBFT_BUILD_OPTIONS))) 44 BUILD_TAGS += boltdb 45 endif 46 47 # allow users to pass additional flags via the conventional LDFLAGS variable 48 LD_FLAGS += $(LDFLAGS) 49 50 # Process Docker environment varible TARGETPLATFORM 51 # in order to build binary with correspondent ARCH 52 # by default will always build for linux/amd64 53 TARGETPLATFORM ?= 54 GOOS ?= linux 55 GOARCH ?= amd64 56 GOARM ?= 57 58 ifeq (linux/arm,$(findstring linux/arm,$(TARGETPLATFORM))) 59 GOOS=linux 60 GOARCH=arm 61 GOARM=7 62 endif 63 64 ifeq (linux/arm/v6,$(findstring linux/arm/v6,$(TARGETPLATFORM))) 65 GOOS=linux 66 GOARCH=arm 67 GOARM=6 68 endif 69 70 ifeq (linux/arm64,$(findstring linux/arm64,$(TARGETPLATFORM))) 71 GOOS=linux 72 GOARCH=arm64 73 GOARM=7 74 endif 75 76 ifeq (linux/386,$(findstring linux/386,$(TARGETPLATFORM))) 77 GOOS=linux 78 GOARCH=386 79 endif 80 81 ifeq (linux/amd64,$(findstring linux/amd64,$(TARGETPLATFORM))) 82 GOOS=linux 83 GOARCH=amd64 84 endif 85 86 ifeq (linux/mips,$(findstring linux/mips,$(TARGETPLATFORM))) 87 GOOS=linux 88 GOARCH=mips 89 endif 90 91 ifeq (linux/mipsle,$(findstring linux/mipsle,$(TARGETPLATFORM))) 92 GOOS=linux 93 GOARCH=mipsle 94 endif 95 96 ifeq (linux/mips64,$(findstring linux/mips64,$(TARGETPLATFORM))) 97 GOOS=linux 98 GOARCH=mips64 99 endif 100 101 ifeq (linux/mips64le,$(findstring linux/mips64le,$(TARGETPLATFORM))) 102 GOOS=linux 103 GOARCH=mips64le 104 endif 105 106 ifeq (linux/riscv64,$(findstring linux/riscv64,$(TARGETPLATFORM))) 107 GOOS=linux 108 GOARCH=riscv64 109 endif 110 111 all: check build test install 112 .PHONY: all 113 114 include tests.mk 115 116 ############################################################################### 117 ### Build CometBFT ### 118 ############################################################################### 119 120 build: 121 CGO_ENABLED=$(CGO_ENABLED) go build $(BUILD_FLAGS) -tags '$(BUILD_TAGS)' -o $(OUTPUT) ./cmd/cometbft/ 122 .PHONY: build 123 124 install: 125 CGO_ENABLED=$(CGO_ENABLED) go install $(BUILD_FLAGS) -tags $(BUILD_TAGS) ./cmd/cometbft 126 .PHONY: install 127 128 ############################################################################### 129 ### Metrics ### 130 ############################################################################### 131 132 metrics: testdata-metrics 133 go generate -run="scripts/metricsgen" ./... 134 .PHONY: metrics 135 136 # By convention, the go tool ignores subdirectories of directories named 137 # 'testdata'. This command invokes the generate command on the folder directly 138 # to avoid this. 139 testdata-metrics: 140 ls ./scripts/metricsgen/testdata | xargs -I{} go generate -v -run="scripts/metricsgen" ./scripts/metricsgen/testdata/{} 141 .PHONY: testdata-metrics 142 143 ############################################################################### 144 ### Mocks ### 145 ############################################################################### 146 147 mockery: 148 go generate -run="./scripts/mockery_generate.sh" ./... 149 .PHONY: mockery 150 151 ############################################################################### 152 ### Protobuf ### 153 ############################################################################### 154 155 check-proto-deps: 156 ifeq (,$(shell which protoc-gen-gogofaster)) 157 @go install github.com/cosmos/gogoproto/protoc-gen-gogofaster@latest 158 endif 159 .PHONY: check-proto-deps 160 161 check-proto-format-deps: 162 ifeq (,$(shell which clang-format)) 163 $(error "clang-format is required for Protobuf formatting. See instructions for your platform on how to install it.") 164 endif 165 .PHONY: check-proto-format-deps 166 167 proto-gen: check-proto-deps 168 @echo "Generating Protobuf files" 169 @go run github.com/bufbuild/buf/cmd/buf generate 170 @mv ./proto/tendermint/abci/types.pb.go ./abci/types/ 171 @cp ./proto/tendermint/rpc/grpc/types.pb.go ./rpc/grpc 172 .PHONY: proto-gen 173 174 # These targets are provided for convenience and are intended for local 175 # execution only. 176 proto-lint: check-proto-deps 177 @echo "Linting Protobuf files" 178 @go run github.com/bufbuild/buf/cmd/buf lint 179 .PHONY: proto-lint 180 181 proto-format: check-proto-format-deps 182 @echo "Formatting Protobuf files" 183 @find . -name '*.proto' -path "./proto/*" -exec clang-format -i {} \; 184 .PHONY: proto-format 185 186 proto-check-breaking: check-proto-deps 187 @echo "Checking for breaking changes in Protobuf files against local branch" 188 @echo "Note: This is only useful if your changes have not yet been committed." 189 @echo " Otherwise read up on buf's \"breaking\" command usage:" 190 @echo " https://docs.buf.build/breaking/usage" 191 @go run github.com/bufbuild/buf/cmd/buf breaking --against ".git" 192 .PHONY: proto-check-breaking 193 194 proto-check-breaking-ci: 195 @go run github.com/bufbuild/buf/cmd/buf breaking --against $(HTTPS_GIT)#branch=v0.34.x 196 .PHONY: proto-check-breaking-ci 197 198 ############################################################################### 199 ### Build ABCI ### 200 ############################################################################### 201 202 build_abci: 203 @go build -mod=readonly -i ./abci/cmd/... 204 .PHONY: build_abci 205 206 install_abci: 207 @go install -mod=readonly ./abci/cmd/... 208 .PHONY: install_abci 209 210 ############################################################################### 211 ### Distribution ### 212 ############################################################################### 213 214 # dist builds binaries for all platforms and packages them for distribution 215 # TODO add abci to these scripts 216 dist: 217 @BUILD_TAGS=$(BUILD_TAGS) sh -c "'$(CURDIR)/scripts/dist.sh'" 218 .PHONY: dist 219 220 go-mod-cache: go.sum 221 @echo "--> Download go modules to local cache" 222 @go mod download 223 .PHONY: go-mod-cache 224 225 go.sum: go.mod 226 @echo "--> Ensure dependencies have not been modified" 227 @go mod verify 228 @go mod tidy 229 230 draw_deps: 231 @# requires brew install graphviz or apt-get install graphviz 232 go get github.com/RobotsAndPencils/goviz 233 @goviz -i github.com/cometbft/cometbft/cmd/cometbft -d 3 | dot -Tpng -o dependency-graph.png 234 .PHONY: draw_deps 235 236 get_deps_bin_size: 237 @# Copy of build recipe with additional flags to perform binary size analysis 238 $(eval $(shell go build -work -a $(BUILD_FLAGS) -tags $(BUILD_TAGS) -o $(OUTPUT) ./cmd/cometbft/ 2>&1)) 239 @find $(WORK) -type f -name "*.a" | xargs -I{} du -hxs "{}" | sort -rh | sed -e s:${WORK}/::g > deps_bin_size.log 240 @echo "Results can be found here: $(CURDIR)/deps_bin_size.log" 241 .PHONY: get_deps_bin_size 242 243 ############################################################################### 244 ### Libs ### 245 ############################################################################### 246 247 # generates certificates for TLS testing in remotedb and RPC server 248 gen_certs: clean_certs 249 certstrap init --common-name "cometbft.com" --passphrase "" 250 certstrap request-cert --common-name "server" -ip "127.0.0.1" --passphrase "" 251 certstrap sign "server" --CA "cometbft.com" --passphrase "" 252 mv out/server.crt rpc/jsonrpc/server/test.crt 253 mv out/server.key rpc/jsonrpc/server/test.key 254 rm -rf out 255 .PHONY: gen_certs 256 257 # deletes generated certificates 258 clean_certs: 259 rm -f rpc/jsonrpc/server/test.crt 260 rm -f rpc/jsonrpc/server/test.key 261 .PHONY: clean_certs 262 263 ############################################################################### 264 ### Formatting, linting, and vetting ### 265 ############################################################################### 266 267 format: 268 find . -name '*.go' -type f -not -path "*.git*" -not -name '*.pb.go' -not -name '*pb_test.go' | xargs gofmt -w -s 269 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 270 .PHONY: format 271 272 lint: 273 @echo "--> Running linter" 274 @go run github.com/golangci/golangci-lint/cmd/golangci-lint run 275 .PHONY: lint 276 277 vulncheck: 278 @go run golang.org/x/vuln/cmd/govulncheck@latest ./... 279 .PHONY: vulncheck 280 281 DESTINATION = ./index.html.md 282 283 284 ############################################################################### 285 ### Documentation ### 286 ############################################################################### 287 288 # Verify that important design docs have ToC entries. 289 check-docs-toc: 290 @./docs/presubmit.sh 291 .PHONY: check-docs-toc 292 293 ############################################################################### 294 ### Docker image ### 295 ############################################################################### 296 297 # On Linux, you may need to run `DOCKER_BUILDKIT=1 make build-docker` for this 298 # to work. 299 build-docker: 300 docker build \ 301 --label=cometbft \ 302 --tag="cometbft/cometbft" \ 303 -f DOCKER/Dockerfile . 304 .PHONY: build-docker 305 306 ############################################################################### 307 ### Local testnet using docker ### 308 ############################################################################### 309 310 # Build linux binary on other platforms 311 build-linux: 312 GOOS=$(GOOS) GOARCH=$(GOARCH) GOARM=$(GOARM) $(MAKE) build 313 .PHONY: build-linux 314 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 # 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 # Stop testnet 334 localnet-stop: 335 docker-compose down 336 .PHONY: localnet-stop 337 338 # 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 # 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=5m -race -coverprofile=$(BUILDDIR)/$*.profile.out