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