-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
246 lines (207 loc) · 11.4 KB
/
Copy pathMakefile
File metadata and controls
246 lines (207 loc) · 11.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
###################################################
### Lumera Makefile
###################################################
# tools/paths
GO ?= go
BUF ?= buf
GOLANGCI_LINT ?= golangci-lint
BUILD_DIR ?= build
RELEASE_DIR ?= release
RELEASE_TARGETS ?= linux:amd64
GOPROXY ?= https://proxy.golang.org,direct
# Build tags for conditional compilation
BUILD_TAGS ?= ledger
module_version = $(strip $(shell EMSDK_QUIET=1 ${GO} list -m -f '{{.Version}}' $1 | tail -n 1))
GOFLAGS = "-trimpath"
WASMVM_VERSION := v3@v3.0.3
RELEASE_CGO_LDFLAGS ?= -Wl,-rpath,/usr/lib -Wl,--disable-new-dtags
COSMOS_PROTO_VERSION := $(call module_version,github.com/cosmos/cosmos-proto)
GOGOPROTO_VERSION := $(call module_version,github.com/cosmos/gogoproto)
GOLANGCI_LINT_VERSION := $(call module_version,github.com/golangci/golangci-lint/v2)
BUF_VERSION := $(call module_version,github.com/bufbuild/buf)
GRPC_GATEWAY_VERSION := $(call module_version,github.com/grpc-ecosystem/grpc-gateway)
GRPC_GATEWAY_V2_VERSION := $(call module_version,github.com/grpc-ecosystem/grpc-gateway/v2)
GO_TOOLS_VERSION := $(call module_version,golang.org/x/tools)
GRPC_VERSION := $(call module_version,google.golang.org/grpc)
PROTOBUF_VERSION := $(call module_version,google.golang.org/protobuf)
GOCACHE := $(shell ${GO} env GOCACHE)
GOMODCACHE := $(shell ${GO} env GOMODCACHE)
APP_NAME ?= $(strip $(shell awk -F': *' '/^name:/ {print $$2; exit}' config.yml))
APP_MAIN ?= $(strip $(shell awk 'BEGIN{in_build=0} /^build:/{in_build=1; next} in_build && /^[^[:space:]]/{exit} in_build && $$1=="main:"{print $$2; exit}' config.yml))
APP_BINARY ?= $(strip $(shell awk 'BEGIN{in_build=0} /^build:/{in_build=1; next} in_build && /^[^[:space:]]/{exit} in_build && $$1=="binary:"{print $$2; exit}' config.yml))
CHAIN_ID ?= $(strip $(shell awk -F': *' '/^[[:space:]]*chain_id:/ {print $$2; exit}' config.yml))
APP_TITLE ?= $(strip $(shell printf '%s' '$(APP_NAME)' | sed 's/^./\U&/'))
EMPTY :=
SPACE := $(EMPTY) $(EMPTY)
COMMA := ,
BUILD_TAGS_VERSION := $(subst $(SPACE),$(COMMA),$(strip $(BUILD_TAGS)))
GIT_HEAD_HASH ?= $(strip $(shell git rev-parse HEAD 2>/dev/null))
VERSION_TAG ?= $(strip $(shell tag_ref=$$(git for-each-ref --merged HEAD --sort=-creatordate --format='%(refname:strip=2)' refs/tags | head -n1); if [ -z "$$tag_ref" ]; then printf ''; else tag_name=$${tag_ref#v}; tag_commit=$$(git rev-list -n1 "$$tag_ref" 2>/dev/null); head_commit=$$(git rev-parse HEAD 2>/dev/null); if [ "$$tag_commit" = "$$head_commit" ]; then printf '%s' "$$tag_name"; else printf '%s-%s' "$$tag_name" "$$(git rev-parse --short=8 HEAD 2>/dev/null)"; fi; fi))
BUILD_LDFLAGS = \
-X github.com/cosmos/cosmos-sdk/version.Name=$(APP_TITLE) \
-X github.com/cosmos/cosmos-sdk/version.AppName=$(APP_NAME)d \
-X github.com/cosmos/cosmos-sdk/version.Version=$(VERSION_TAG) \
-X github.com/cosmos/cosmos-sdk/version.Commit=$(GIT_HEAD_HASH) \
-X github.com/cosmos/cosmos-sdk/version.BuildTags=$(BUILD_TAGS_VERSION)
TOOLS := \
github.com/bufbuild/buf/cmd/buf@$(BUF_VERSION) \
github.com/cosmos/gogoproto/protoc-gen-gocosmos@$(GOGOPROTO_VERSION) \
github.com/cosmos/gogoproto/protoc-gen-gogo@$(GOGOPROTO_VERSION) \
github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION) \
github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway@$(GRPC_GATEWAY_VERSION) \
github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2@$(GRPC_GATEWAY_V2_VERSION) \
golang.org/x/tools/cmd/goimports@$(GO_TOOLS_VERSION) \
google.golang.org/grpc/cmd/protoc-gen-go-grpc@$(GRPC_VERSION) \
google.golang.org/protobuf/cmd/protoc-gen-go@$(PROTOBUF_VERSION) \
golang.org/x/vuln/cmd/govulncheck@latest
-include Makefile.devnet
###################################################
### Build ###
###################################################
.PHONY: build build-debug build-proto build-claiming-faucet
.PHONY: clean-proto clean-cache install-tools openrpc release
install-tools:
@echo "Installing Go tooling..."
@for tool in $(TOOLS); do \
echo " $$tool"; \
EMSDK_QUIET=1 ${GO} install $$tool; \
done
clean-proto:
@echo "Cleaning up protobuf generated files..."
find x/ -type f \( -name "*.pb.go" -o -name "*.pb.gw.go" -o -name "*.pulsar.go" -o -name "swagger.yaml" -o -name "swagger.swagger.yaml" \) -print -exec rm -f {} +
find proto/ -type f \( -name "swagger.yaml" -o -name "swagger.swagger.yaml" -o -name "*.swagger.json" \) -print -exec rm -f {} +
rm -f docs/static/openapi.yml
clean-cache:
@echo "Cleaning Buf cache..."
${BUF} clean || true
rm -rf ~/.cache/buf || true
@echo "Cleaning Go build cache..."
${GO} clean -cache -modcache -i -r || true
rm -rf ${GOCACHE} ${GOMODCACHE} || true
PROTO_SRC := $(shell find proto -name "*.proto")
GO_SRC := $(shell find app -name "*.go") \
$(shell find ante -name "*.go") \
$(shell find cmd -name "*.go") \
$(shell find config -name "*.go") \
$(shell find x -name "*.go")
install: build
@echo "Installing $(APP_BINARY) to $(shell ${GO} env GOPATH)/bin/..."
@cp ${BUILD_DIR}/$(APP_BINARY) $(shell ${GO} env GOPATH)/bin/
build-proto: clean-proto $(PROTO_SRC)
@echo "Processing proto files..."
${BUF} generate --template proto/buf.gen.gogo.yaml --verbose
${BUF} generate --template proto/buf.gen.swagger.yaml --verbose
@$(MAKE) --no-print-directory build-openapi
build-openapi:
@echo "Generating vendor swagger from cosmos/evm protos..."
@rm -rf proto/vendor-swagger && mkdir -p proto/vendor-swagger
@EVM_PROTO_DIR=$$(${GO} list -m -f '{{.Dir}}' github.com/cosmos/evm)/proto && \
if [ -d "$$EVM_PROTO_DIR" ]; then \
${BUF} generate "$$EVM_PROTO_DIR" --template proto/buf.gen.swagger.yaml --output proto/vendor-swagger; \
fi
@echo "Merging swagger specs..."
${GO} run ./tools/openapigen -config tools/openapigen/config.toml -out docs/static/openapi.yml
OPENRPC_GENERATOR_INPUTS := \
$(filter-out %_test.go,$(wildcard tools/openrpcgen/*.go)) \
docs/openrpc/examples_overrides.json \
docs/openrpc/param_overrides.json \
docs/openrpc/type_overrides.json \
docs/openrpc/result_overrides.json
app/openrpc/openrpc.json.gz docs/openrpc.json: $(OPENRPC_GENERATOR_INPUTS)
@echo "Generating OpenRPC spec..."
@# Create a placeholder .gz so the //go:embed directive in spec.go is
@# satisfied during compilation of the generator (same Go module).
@test -f app/openrpc/openrpc.json.gz || echo '{}' | gzip > app/openrpc/openrpc.json.gz
${GO} run ./tools/openrpcgen -out docs/openrpc.json -examples docs/openrpc/examples_overrides.json -params docs/openrpc/param_overrides.json -types docs/openrpc/type_overrides.json -results docs/openrpc/result_overrides.json
gzip -c docs/openrpc.json > app/openrpc/openrpc.json.gz
@echo "OpenRPC spec written to docs/openrpc.json (embedded as app/openrpc/openrpc.json.gz)"
openrpc: app/openrpc/openrpc.json.gz
build: ${BUILD_DIR}/lumerad
go.sum: go.mod
@echo "Verifying and tidying go modules..."
GOPROXY=${GOPROXY} ${GO} mod verify
GOPROXY=${GOPROXY} ${GO} mod tidy
${BUILD_DIR}/lumerad: $(GO_SRC) app/openrpc/openrpc.json.gz go.sum Makefile
@echo "Building lumerad binary..."
@mkdir -p ${BUILD_DIR}
GOFLAGS=${GOFLAGS} ${GO} build -mod=readonly $(if $(strip $(BUILD_TAGS)),-tags "$(BUILD_TAGS)",) -ldflags '$(BUILD_LDFLAGS)' -o ${BUILD_DIR}/$(APP_BINARY) ./$(APP_MAIN)
chmod +x ${BUILD_DIR}/$(APP_BINARY)
@WASMVM_SO="$$(find $$(${GO} env GOPATH)/pkg/mod/github.com/!cosm!wasm/wasmvm/$(WASMVM_VERSION) -name 'libwasmvm.x86_64.so' -print -quit 2>/dev/null)"; \
if [ -n "$$WASMVM_SO" ]; then \
cp -f "$$WASMVM_SO" ${BUILD_DIR}/libwasmvm.x86_64.so; \
echo "Copied libwasmvm.x86_64.so from module cache"; \
else \
echo "Warning: libwasmvm.x86_64.so not found in module cache for wasmvm/$(WASMVM_VERSION)"; \
fi
build-claiming-faucet:
@echo "Building Claiming Faucet binary..."
@mkdir -p ${BUILD_DIR}
${GO} build -o ${BUILD_DIR}/claiming_faucet ./claiming_faucet/
chmod +x ${BUILD_DIR}/claiming_faucet
build-debug: ${BUILD_DIR}/debug/lumerad
${BUILD_DIR}/debug/lumerad: $(GO_SRC) app/openrpc/openrpc.json.gz go.sum Makefile
@echo "Building lumerad debug binary..."
@mkdir -p ${BUILD_DIR}
GOFLAGS=${GOFLAGS} ${GO} build -mod=readonly $(if $(strip $(BUILD_TAGS)),-tags "$(BUILD_TAGS)",) -gcflags="all=-N -l" -ldflags '$(BUILD_LDFLAGS)' -o ${BUILD_DIR}/$(APP_BINARY) ./$(APP_MAIN)
chmod +x ${BUILD_DIR}/$(APP_BINARY)
release: go.sum build-proto openrpc
@echo "Creating release artifacts..."
@mkdir -p ${RELEASE_DIR}
@rm -f ${RELEASE_DIR}/*.tar.gz ${RELEASE_DIR}/release_checksum
@for target in ${RELEASE_TARGETS}; do \
goos=$${target%:*}; \
goarch=$${target#*:}; \
outdir=$$(mktemp -d); \
echo "Building release target $$goos/$$goarch..."; \
CGO_LDFLAGS="${RELEASE_CGO_LDFLAGS}" GOFLAGS=${GOFLAGS} GOOS=$$goos GOARCH=$$goarch ${GO} build -mod=readonly $(if $(strip $(BUILD_TAGS)),-tags "$(BUILD_TAGS)",) -ldflags '$(BUILD_LDFLAGS)' -o $$outdir/${APP_BINARY} ./$(APP_MAIN); \
chmod +x $$outdir/${APP_BINARY}; \
mkdir -p $$outdir/scripts; \
cp scripts/evmigration-common.sh scripts/migrate-account.sh scripts/migrate-validator.sh scripts/migrate-multisig.sh $$outdir/scripts/; \
chmod +x $$outdir/scripts/migrate-account.sh $$outdir/scripts/migrate-validator.sh $$outdir/scripts/migrate-multisig.sh; \
tar -C $$outdir -czf ${RELEASE_DIR}/${APP_NAME}_$${goos}_$${goarch}.tar.gz ${APP_BINARY} scripts; \
rm -rf $$outdir; \
done
@(cd ${RELEASE_DIR} && sha256sum *.tar.gz > release_checksum)
@echo "Release created in [${RELEASE_DIR}/] directory."
###################################################
### Tests and Simulation ###
###################################################
.PHONY: unit-tests integration-tests system-tests simulation-tests simulation-bench all-tests lint vulncheck system-metrics-test
.PHONY: lint-scripts test-scripts
all-tests: unit-tests integration-tests system-tests simulation-tests
# Set NOCACHE=1 to force tests to run from scratch (disables Go test caching).
# Example: make unit-tests NOCACHE=1
NOCACHE_FLAG := $(if $(NOCACHE),-count=1)
lint-scripts:
@echo "Running shellcheck on scripts/ ..."
@shellcheck -x scripts/evmigration-common.sh scripts/migrate-account.sh scripts/migrate-validator.sh scripts/migrate-multisig.sh
test-scripts:
@echo "Running bats tests for scripts/ ..."
@bats tests/scripts/
lint: openrpc lint-scripts
@echo "Running linters..."
@${GOLANGCI_LINT} run ./... --timeout=5m
vulncheck:
@echo "Running govulncheck..."
@govulncheck ./...
unit-tests: openrpc
@echo "Running unit tests in x/..."
${GO} test ./x/... -v -coverprofile=coverage.out $(NOCACHE_FLAG)
integration-tests: openrpc
@echo "Running integration tests..."
${GO} test -tags=integration,test -p 4 ./tests/integration/... -v $(NOCACHE_FLAG)
system-tests: openrpc
@echo "Running system tests..."
${GO} test -tags=system,test ./tests/system/... -v $(NOCACHE_FLAG)
simulation-tests: openrpc
@echo "Running simulation tests..."
${GO} test -tags='simulation test' ./tests/simulation/ -v -timeout 30m $(NOCACHE_FLAG) -args -Enabled=true -NumBlocks=200 -BlockSize=50 -Commit=true
simulation-bench: openrpc
@echo "Running simulation benchmark..."
GOMAXPROCS=2 ${GO} test -tags='simulation test' -v -benchmem -run='^$$' -bench '^BenchmarkSimulation' -cpuprofile cpu.out ./tests/simulation/ -Commit=true
systemex-tests: openrpc
@echo "Running system tests..."
cd ./tests/systemtests/ && go test -tags=system_test -timeout 30m -v . $(NOCACHE_FLAG)
system-metrics-test:
@echo "Running supernode metrics system tests (E2E + staleness)..."
cd ./tests/systemtests/ && go test -tags=system_test -timeout 20m -v . -run 'TestSupernodeMetrics(E2E|StalenessAndRecovery)' $(NOCACHE_FLAG)