github.com/cosmos/cosmos-sdk@v0.50.10/Makefile (about) 1 #!/usr/bin/make -f 2 3 PACKAGES_NOSIMULATION=$(shell go list ./... | grep -v '/simulation') 4 PACKAGES_SIMTEST=$(shell go list ./... | grep '/simulation') 5 export VERSION := $(shell echo $(shell git describe --tags --always --match "v*") | sed 's/^v//') 6 export CMTVERSION := $(shell go list -m github.com/cometbft/cometbft | sed 's:.* ::') 7 export COMMIT := $(shell git log -1 --format='%H') 8 LEDGER_ENABLED ?= true 9 BINDIR ?= $(GOPATH)/bin 10 BUILDDIR ?= $(CURDIR)/build 11 SIMAPP = ./simapp 12 MOCKS_DIR = $(CURDIR)/tests/mocks 13 HTTPS_GIT := https://github.com/cosmos/cosmos-sdk.git 14 DOCKER := $(shell which docker) 15 PROJECT_NAME = $(shell git remote get-url origin | xargs basename -s .git) 16 17 # process build tags 18 build_tags = netgo 19 ifeq ($(LEDGER_ENABLED),true) 20 ifeq ($(OS),Windows_NT) 21 GCCEXE = $(shell where gcc.exe 2> NUL) 22 ifeq ($(GCCEXE),) 23 $(error gcc.exe not installed for ledger support, please install or set LEDGER_ENABLED=false) 24 else 25 build_tags += ledger 26 endif 27 else 28 UNAME_S = $(shell uname -s) 29 ifeq ($(UNAME_S),OpenBSD) 30 $(warning OpenBSD detected, disabling ledger support (https://github.com/cosmos/cosmos-sdk/issues/1988)) 31 else 32 GCC = $(shell command -v gcc 2> /dev/null) 33 ifeq ($(GCC),) 34 $(error gcc not installed for ledger support, please install or set LEDGER_ENABLED=false) 35 else 36 build_tags += ledger 37 endif 38 endif 39 endif 40 endif 41 42 ifeq (secp,$(findstring secp,$(COSMOS_BUILD_OPTIONS))) 43 build_tags += libsecp256k1_sdk 44 endif 45 46 ifeq (legacy,$(findstring legacy,$(COSMOS_BUILD_OPTIONS))) 47 build_tags += app_v1 48 endif 49 50 whitespace := 51 whitespace += $(whitespace) 52 comma := , 53 build_tags_comma_sep := $(subst $(whitespace),$(comma),$(build_tags)) 54 55 # process linker flags 56 57 ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=sim \ 58 -X github.com/cosmos/cosmos-sdk/version.AppName=simd \ 59 -X github.com/cosmos/cosmos-sdk/version.Version=$(VERSION) \ 60 -X github.com/cosmos/cosmos-sdk/version.Commit=$(COMMIT) \ 61 -X "github.com/cosmos/cosmos-sdk/version.BuildTags=$(build_tags_comma_sep)" \ 62 -X github.com/cometbft/cometbft/version.TMCoreSemVer=$(CMTVERSION) 63 64 # DB backend selection 65 ifeq (cleveldb,$(findstring cleveldb,$(COSMOS_BUILD_OPTIONS))) 66 build_tags += gcc 67 endif 68 ifeq (badgerdb,$(findstring badgerdb,$(COSMOS_BUILD_OPTIONS))) 69 build_tags += badgerdb 70 endif 71 # handle rocksdb 72 ifeq (rocksdb,$(findstring rocksdb,$(COSMOS_BUILD_OPTIONS))) 73 CGO_ENABLED=1 74 build_tags += rocksdb 75 endif 76 # handle boltdb 77 ifeq (boltdb,$(findstring boltdb,$(COSMOS_BUILD_OPTIONS))) 78 build_tags += boltdb 79 endif 80 81 ifeq (,$(findstring nostrip,$(COSMOS_BUILD_OPTIONS))) 82 ldflags += -w -s 83 endif 84 ldflags += $(LDFLAGS) 85 ldflags := $(strip $(ldflags)) 86 87 build_tags += $(BUILD_TAGS) 88 build_tags := $(strip $(build_tags)) 89 90 BUILD_FLAGS := -tags "$(build_tags)" -ldflags '$(ldflags)' 91 # check for nostrip option 92 ifeq (,$(findstring nostrip,$(COSMOS_BUILD_OPTIONS))) 93 BUILD_FLAGS += -trimpath 94 endif 95 96 # Check for debug option 97 ifeq (debug,$(findstring debug,$(COSMOS_BUILD_OPTIONS))) 98 BUILD_FLAGS += -gcflags "all=-N -l" 99 endif 100 101 all: tools build lint test vulncheck 102 103 # The below include contains the tools and runsim targets. 104 include contrib/devtools/Makefile 105 106 ############################################################################### 107 ### Build ### 108 ############################################################################### 109 110 BUILD_TARGETS := build install 111 112 build: BUILD_ARGS=-o $(BUILDDIR)/ 113 114 build-linux-amd64: 115 GOOS=linux GOARCH=amd64 LEDGER_ENABLED=false $(MAKE) build 116 117 build-linux-arm64: 118 GOOS=linux GOARCH=arm64 LEDGER_ENABLED=false $(MAKE) build 119 120 $(BUILD_TARGETS): go.sum $(BUILDDIR)/ 121 cd ${CURRENT_DIR}/simapp && go $@ -mod=readonly $(BUILD_FLAGS) $(BUILD_ARGS) ./... 122 123 $(BUILDDIR)/: 124 mkdir -p $(BUILDDIR)/ 125 126 cosmovisor: 127 $(MAKE) -C tools/cosmovisor cosmovisor 128 129 confix: 130 $(MAKE) -C tools/confix confix 131 132 hubl: 133 $(MAKE) -C tools/hubl hubl 134 135 .PHONY: build build-linux-amd64 build-linux-arm64 cosmovisor confix 136 137 138 mocks: $(MOCKS_DIR) 139 @go install github.com/golang/mock/mockgen@v1.6.0 140 sh ./scripts/mockgen.sh 141 .PHONY: mocks 142 143 144 vulncheck: $(BUILDDIR)/ 145 GOBIN=$(BUILDDIR) go install golang.org/x/vuln/cmd/govulncheck@latest 146 $(BUILDDIR)/govulncheck ./... 147 148 $(MOCKS_DIR): 149 mkdir -p $(MOCKS_DIR) 150 151 distclean: clean tools-clean 152 clean: 153 rm -rf \ 154 $(BUILDDIR)/ \ 155 artifacts/ \ 156 tmp-swagger-gen/ \ 157 .testnets 158 159 .PHONY: distclean clean 160 161 ############################################################################### 162 ### Tools & Dependencies ### 163 ############################################################################### 164 165 go.sum: go.mod 166 echo "Ensure dependencies have not been modified ..." >&2 167 go mod verify 168 go mod tidy 169 170 ############################################################################### 171 ### Documentation ### 172 ############################################################################### 173 174 godocs: 175 @echo "--> Wait a few seconds and visit http://localhost:6060/pkg/github.com/cosmos/cosmos-sdk/types" 176 go install golang.org/x/tools/cmd/godoc@latest 177 godoc -http=:6060 178 179 build-docs: 180 @cd docs && DOCS_DOMAIN=docs.cosmos.network sh ./build-all.sh 181 182 .PHONY: build-docs 183 184 ############################################################################### 185 ### Tests & Simulation ### 186 ############################################################################### 187 188 # make init-simapp initializes a single local node network 189 # it is useful for testing and development 190 # Usage: make install && make init-simapp && simd start 191 # Warning: make init-simapp will remove all data in simapp home directory 192 init-simapp: 193 ./scripts/init-simapp.sh 194 195 test: test-unit 196 test-e2e: 197 $(MAKE) -C tests test-e2e 198 test-e2e-cov: 199 $(MAKE) -C tests test-e2e-cov 200 test-integration: 201 $(MAKE) -C tests test-integration 202 test-integration-cov: 203 $(MAKE) -C tests test-integration-cov 204 test-all: test-unit test-e2e test-integration test-ledger-mock test-race 205 206 TEST_PACKAGES=./... 207 TEST_TARGETS := test-unit test-unit-amino test-unit-proto test-ledger-mock test-race test-ledger test-race 208 209 # Test runs-specific rules. To add a new test target, just add 210 # a new rule, customise ARGS or TEST_PACKAGES ad libitum, and 211 # append the new rule to the TEST_TARGETS list. 212 test-unit: test_tags += cgo ledger test_ledger_mock norace 213 test-unit-amino: test_tags += ledger test_ledger_mock test_amino norace 214 test-ledger: test_tags += cgo ledger norace 215 test-ledger-mock: test_tags += ledger test_ledger_mock norace 216 test-race: test_tags += cgo ledger test_ledger_mock 217 test-race: ARGS=-race 218 test-race: TEST_PACKAGES=$(PACKAGES_NOSIMULATION) 219 $(TEST_TARGETS): run-tests 220 221 # check-* compiles and collects tests without running them 222 # note: go test -c doesn't support multiple packages yet (https://github.com/golang/go/issues/15513) 223 CHECK_TEST_TARGETS := check-test-unit check-test-unit-amino 224 check-test-unit: test_tags += cgo ledger test_ledger_mock norace 225 check-test-unit-amino: test_tags += ledger test_ledger_mock test_amino norace 226 $(CHECK_TEST_TARGETS): EXTRA_ARGS=-run=none 227 $(CHECK_TEST_TARGETS): run-tests 228 229 ARGS += -tags "$(test_tags)" 230 SUB_MODULES = $(shell find . -type f -name 'go.mod' -print0 | xargs -0 -n1 dirname | sort) 231 CURRENT_DIR = $(shell pwd) 232 run-tests: 233 ifneq (,$(shell which tparse 2>/dev/null)) 234 @echo "Starting unit tests"; \ 235 finalec=0; \ 236 for module in $(SUB_MODULES); do \ 237 cd ${CURRENT_DIR}/$$module; \ 238 echo "Running unit tests for $$(grep '^module' go.mod)"; \ 239 go test -mod=readonly -json $(ARGS) $(TEST_PACKAGES) ./... | tparse; \ 240 ec=$$?; \ 241 if [ "$$ec" -ne '0' ]; then finalec=$$ec; fi; \ 242 done; \ 243 exit $$finalec 244 else 245 @echo "Starting unit tests"; \ 246 finalec=0; \ 247 for module in $(SUB_MODULES); do \ 248 cd ${CURRENT_DIR}/$$module; \ 249 echo "Running unit tests for $$(grep '^module' go.mod)"; \ 250 go test -mod=readonly $(ARGS) $(TEST_PACKAGES) ./... ; \ 251 ec=$$?; \ 252 if [ "$$ec" -ne '0' ]; then finalec=$$ec; fi; \ 253 done; \ 254 exit $$finalec 255 endif 256 257 .PHONY: run-tests test test-all $(TEST_TARGETS) 258 259 test-sim-nondeterminism: 260 @echo "Running non-determinism test..." 261 @cd ${CURRENT_DIR}/simapp && go test -mod=readonly -run TestAppStateDeterminism -Enabled=true \ 262 -NumBlocks=100 -BlockSize=200 -Commit=true -Period=0 -v -timeout 24h 263 264 # Requires an exported plugin. See store/streaming/README.md for documentation. 265 # 266 # example: 267 # export COSMOS_SDK_ABCI_V1=<path-to-plugin-binary> 268 # make test-sim-nondeterminism-streaming 269 # 270 # Using the built-in examples: 271 # export COSMOS_SDK_ABCI_V1=<path-to-sdk>/store/streaming/abci/examples/file/file 272 # make test-sim-nondeterminism-streaming 273 test-sim-nondeterminism-streaming: 274 @echo "Running non-determinism-streaming test..." 275 @cd ${CURRENT_DIR}/simapp && go test -mod=readonly -run TestAppStateDeterminism -Enabled=true \ 276 -NumBlocks=100 -BlockSize=200 -Commit=true -Period=0 -v -timeout 24h -EnableStreaming=true 277 278 test-sim-custom-genesis-fast: 279 @echo "Running custom genesis simulation..." 280 @echo "By default, ${HOME}/.simapp/config/genesis.json will be used." 281 @cd ${CURRENT_DIR}/simapp && go test -mod=readonly -run TestFullAppSimulation -Genesis=${HOME}/.simapp/config/genesis.json \ 282 -Enabled=true -NumBlocks=100 -BlockSize=200 -Commit=true -Seed=99 -Period=5 -SigverifyTx=false -v -timeout 24h 283 284 test-sim-import-export: runsim 285 @echo "Running application import/export simulation. This may take several minutes..." 286 @cd ${CURRENT_DIR}/simapp && $(BINDIR)/runsim -Jobs=4 -SimAppPkg=. -ExitOnFail 50 5 TestAppImportExport 287 288 test-sim-after-import: runsim 289 @echo "Running application simulation-after-import. This may take several minutes..." 290 @cd ${CURRENT_DIR}/simapp && $(BINDIR)/runsim -Jobs=4 -SimAppPkg=. -ExitOnFail 50 5 TestAppSimulationAfterImport 291 292 test-sim-custom-genesis-multi-seed: runsim 293 @echo "Running multi-seed custom genesis simulation..." 294 @echo "By default, ${HOME}/.simapp/config/genesis.json will be used." 295 @cd ${CURRENT_DIR}/simapp && $(BINDIR)/runsim -Genesis=${HOME}/.simapp/config/genesis.json -SigverifyTx=false -SimAppPkg=. -ExitOnFail 400 5 TestFullAppSimulation 296 297 test-sim-multi-seed-long: runsim 298 @echo "Running long multi-seed application simulation. This may take awhile!" 299 @cd ${CURRENT_DIR}/simapp && $(BINDIR)/runsim -Jobs=4 -SimAppPkg=. -ExitOnFail 500 50 TestFullAppSimulation 300 301 test-sim-multi-seed-short: runsim 302 @echo "Running short multi-seed application simulation. This may take awhile!" 303 @cd ${CURRENT_DIR}/simapp && $(BINDIR)/runsim -Jobs=4 -SimAppPkg=. -ExitOnFail 50 10 TestFullAppSimulation 304 305 test-sim-benchmark-invariants: 306 @echo "Running simulation invariant benchmarks..." 307 cd ${CURRENT_DIR}/simapp && @go test -mod=readonly -benchmem -bench=BenchmarkInvariants -run=^$ \ 308 -Enabled=true -NumBlocks=1000 -BlockSize=200 \ 309 -Period=1 -Commit=true -Seed=57 -v -timeout 24h 310 311 .PHONY: \ 312 test-sim-nondeterminism \ 313 test-sim-nondeterminism-streaming \ 314 test-sim-custom-genesis-fast \ 315 test-sim-import-export \ 316 test-sim-after-import \ 317 test-sim-custom-genesis-multi-seed \ 318 test-sim-multi-seed-short \ 319 test-sim-multi-seed-long \ 320 test-sim-benchmark-invariants 321 322 SIM_NUM_BLOCKS ?= 500 323 SIM_BLOCK_SIZE ?= 200 324 SIM_COMMIT ?= true 325 326 test-sim-benchmark: 327 @echo "Running application benchmark for numBlocks=$(SIM_NUM_BLOCKS), blockSize=$(SIM_BLOCK_SIZE). This may take awhile!" 328 @cd ${CURRENT_DIR}/simapp && go test -mod=readonly -run=^$$ $(.) -bench ^BenchmarkFullAppSimulation$$ \ 329 -Enabled=true -NumBlocks=$(SIM_NUM_BLOCKS) -BlockSize=$(SIM_BLOCK_SIZE) -Commit=$(SIM_COMMIT) -timeout 24h 330 331 # Requires an exported plugin. See store/streaming/README.md for documentation. 332 # 333 # example: 334 # export COSMOS_SDK_ABCI_V1=<path-to-plugin-binary> 335 # make test-sim-benchmark-streaming 336 # 337 # Using the built-in examples: 338 # export COSMOS_SDK_ABCI_V1=<path-to-sdk>/store/streaming/abci/examples/file/file 339 # make test-sim-benchmark-streaming 340 test-sim-benchmark-streaming: 341 @echo "Running application benchmark for numBlocks=$(SIM_NUM_BLOCKS), blockSize=$(SIM_BLOCK_SIZE). This may take awhile!" 342 @cd ${CURRENT_DIR}/simapp && go test -mod=readonly -run=^$$ $(.) -bench ^BenchmarkFullAppSimulation$$ \ 343 -Enabled=true -NumBlocks=$(SIM_NUM_BLOCKS) -BlockSize=$(SIM_BLOCK_SIZE) -Commit=$(SIM_COMMIT) -timeout 24h -EnableStreaming=true 344 345 test-sim-profile: 346 @echo "Running application benchmark for numBlocks=$(SIM_NUM_BLOCKS), blockSize=$(SIM_BLOCK_SIZE). This may take awhile!" 347 @cd ${CURRENT_DIR}/simapp && go test -mod=readonly -benchmem -run=^$$ $(.) -bench ^BenchmarkFullAppSimulation$$ \ 348 -Enabled=true -NumBlocks=$(SIM_NUM_BLOCKS) -BlockSize=$(SIM_BLOCK_SIZE) -Commit=$(SIM_COMMIT) -timeout 24h -cpuprofile cpu.out -memprofile mem.out 349 350 # Requires an exported plugin. See store/streaming/README.md for documentation. 351 # 352 # example: 353 # export COSMOS_SDK_ABCI_V1=<path-to-plugin-binary> 354 # make test-sim-profile-streaming 355 # 356 # Using the built-in examples: 357 # export COSMOS_SDK_ABCI_V1=<path-to-sdk>/store/streaming/abci/examples/file/file 358 # make test-sim-profile-streaming 359 test-sim-profile-streaming: 360 @echo "Running application benchmark for numBlocks=$(SIM_NUM_BLOCKS), blockSize=$(SIM_BLOCK_SIZE). This may take awhile!" 361 @cd ${CURRENT_DIR}/simapp && go test -mod=readonly -benchmem -run=^$$ $(.) -bench ^BenchmarkFullAppSimulation$$ \ 362 -Enabled=true -NumBlocks=$(SIM_NUM_BLOCKS) -BlockSize=$(SIM_BLOCK_SIZE) -Commit=$(SIM_COMMIT) -timeout 24h -cpuprofile cpu.out -memprofile mem.out -EnableStreaming=true 363 364 .PHONY: test-sim-profile test-sim-benchmark 365 366 benchmark: 367 @go test -mod=readonly -bench=. $(PACKAGES_NOSIMULATION) 368 .PHONY: benchmark 369 370 ############################################################################### 371 ### Linting ### 372 ############################################################################### 373 374 golangci_version=v1.51.2 375 376 lint-install: 377 @echo "--> Installing golangci-lint $(golangci_version)" 378 @go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(golangci_version) 379 380 lint: 381 @echo "--> Running linter" 382 $(MAKE) lint-install 383 @./scripts/go-lint-all.bash --timeout=15m 384 385 lint-fix: 386 @echo "--> Running linter" 387 $(MAKE) lint-install 388 @./scripts/go-lint-all.bash --fix 389 390 .PHONY: lint lint-fix 391 392 ############################################################################### 393 ### Protobuf ### 394 ############################################################################### 395 396 protoVer=0.14.0 397 protoImageName=ghcr.io/cosmos/proto-builder:$(protoVer) 398 protoImage=$(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace $(protoImageName) 399 400 proto-all: proto-format proto-lint proto-gen 401 402 proto-gen: 403 @echo "Generating Protobuf files" 404 @$(protoImage) sh ./scripts/protocgen.sh 405 406 proto-swagger-gen: 407 @echo "Generating Protobuf Swagger" 408 @$(protoImage) sh ./scripts/protoc-swagger-gen.sh 409 410 proto-format: 411 @$(protoImage) find ./ -name "*.proto" -exec clang-format -i {} \; 412 413 proto-lint: 414 @$(protoImage) buf lint --error-format=json 415 416 proto-check-breaking: 417 @$(protoImage) buf breaking --against $(HTTPS_GIT)#branch=main 418 419 CMT_URL = https://raw.githubusercontent.com/cometbft/cometbft/v0.38.0/proto/tendermint 420 421 CMT_CRYPTO_TYPES = proto/tendermint/crypto 422 CMT_ABCI_TYPES = proto/tendermint/abci 423 CMT_TYPES = proto/tendermint/types 424 CMT_VERSION = proto/tendermint/version 425 CMT_LIBS = proto/tendermint/libs/bits 426 CMT_P2P = proto/tendermint/p2p 427 428 proto-update-deps: 429 @echo "Updating Protobuf dependencies" 430 431 @mkdir -p $(CMT_ABCI_TYPES) 432 @curl -sSL $(CMT_URL)/abci/types.proto > $(CMT_ABCI_TYPES)/types.proto 433 434 @mkdir -p $(CMT_VERSION) 435 @curl -sSL $(CMT_URL)/version/types.proto > $(CMT_VERSION)/types.proto 436 437 @mkdir -p $(CMT_TYPES) 438 @curl -sSL $(CMT_URL)/types/types.proto > $(CMT_TYPES)/types.proto 439 @curl -sSL $(CMT_URL)/types/evidence.proto > $(CMT_TYPES)/evidence.proto 440 @curl -sSL $(CMT_URL)/types/params.proto > $(CMT_TYPES)/params.proto 441 @curl -sSL $(CMT_URL)/types/validator.proto > $(CMT_TYPES)/validator.proto 442 @curl -sSL $(CMT_URL)/types/block.proto > $(CMT_TYPES)/block.proto 443 444 @mkdir -p $(CMT_CRYPTO_TYPES) 445 @curl -sSL $(CMT_URL)/crypto/proof.proto > $(CMT_CRYPTO_TYPES)/proof.proto 446 @curl -sSL $(CMT_URL)/crypto/keys.proto > $(CMT_CRYPTO_TYPES)/keys.proto 447 448 @mkdir -p $(CMT_LIBS) 449 @curl -sSL $(CMT_URL)/libs/bits/types.proto > $(CMT_LIBS)/types.proto 450 451 @mkdir -p $(CMT_P2P) 452 @curl -sSL $(CMT_URL)/p2p/types.proto > $(CMT_P2P)/types.proto 453 454 $(DOCKER) run --rm -v $(CURDIR)/proto:/workspace --workdir /workspace $(protoImageName) buf mod update 455 456 .PHONY: proto-all proto-gen proto-swagger-gen proto-format proto-lint proto-check-breaking proto-update-deps 457 458 ############################################################################### 459 ### Localnet ### 460 ############################################################################### 461 462 localnet-build-env: 463 $(MAKE) -C contrib/images simd-env 464 localnet-build-dlv: 465 $(MAKE) -C contrib/images simd-dlv 466 467 localnet-build-nodes: 468 $(DOCKER) run --rm -v $(CURDIR)/.testnets:/data cosmossdk/simd \ 469 testnet init-files --v 4 -o /data --starting-ip-address 192.168.10.2 --keyring-backend=test 470 docker compose up -d 471 472 localnet-stop: 473 docker compose down 474 475 # localnet-start will run a 4-node testnet locally. The nodes are 476 # based off the docker images in: ./contrib/images/simd-env 477 localnet-start: localnet-stop localnet-build-env localnet-build-nodes 478 479 # localnet-debug will run a 4-node testnet locally in debug mode 480 # you can read more about the debug mode here: ./contrib/images/simd-dlv/README.md 481 localnet-debug: localnet-stop localnet-build-dlv localnet-build-nodes 482 483 .PHONY: localnet-start localnet-stop localnet-debug localnet-build-env localnet-build-dlv localnet-build-nodes