-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMakefile
More file actions
321 lines (261 loc) · 11.2 KB
/
Makefile
File metadata and controls
321 lines (261 loc) · 11.2 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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
#!/usr/bin/make -f
BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
COMMIT := $(shell git log -1 --format='%H')
ifeq (,$(VERSION))
VERSION := $(shell git describe --exact-match 2>/dev/null)
ifeq (,$(VERSION))
VERSION := $(BRANCH)-$(COMMIT)
endif
endif
LEDGER_ENABLED ?= true
TM_VERSION := $(shell go list -m github.com/cometbft/cometbft | sed 's:.* ::')
BUILDDIR ?= $(CURDIR)/build
GO_SYSTEM_VERSION = $(shell go version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f1-2)
REQUIRE_GO_VERSION = 1.23
export GO111MODULE = on
###############################################################################
### Build Tags ###
###############################################################################
build_tags = netgo
ifeq ($(LEDGER_ENABLED),true)
ifeq ($(OS),Windows_NT)
GCCEXE = $(shell where gcc.exe 2> NUL)
ifeq ($(GCCEXE),)
$(error gcc.exe not installed for ledger support, please install or set LEDGER_ENABLED=false)
else
build_tags += ledger
endif
else
UNAME_S = $(shell uname -s)
ifeq ($(UNAME_S),OpenBSD)
$(warning OpenBSD detected, disabling ledger support (https://github.com/cosmos/cosmos-sdk/issues/1988))
else
GCC = $(shell command -v gcc 2> /dev/null)
ifeq ($(GCC),)
$(error gcc not installed for ledger support, please install or set LEDGER_ENABLED=false)
else
build_tags += ledger
endif
endif
endif
endif
build_tags += $(BUILD_TAGS)
build_tags := $(strip $(build_tags))
whitespace :=
whitespace := $(whitespace) $(whitespace)
comma := ,
build_tags_comma_sep := $(subst $(whitespace),$(comma),$(build_tags))
###############################################################################
### Linker Flags ###
###############################################################################
ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=structs \
-X github.com/cosmos/cosmos-sdk/version.AppName=structsd \
-X github.com/cosmos/cosmos-sdk/version.Version=$(VERSION) \
-X github.com/cosmos/cosmos-sdk/version.Commit=$(COMMIT) \
-X "github.com/cosmos/cosmos-sdk/version.BuildTags=$(build_tags_comma_sep)" \
-X github.com/cometbft/cometbft/version.TMCoreSemVer=$(TM_VERSION)
ifeq ($(LINK_STATICALLY),true)
ldflags += -linkmode=external -extldflags "-Wl,-z,muldefs -static"
endif
ldflags += -w -s
ldflags += $(LDFLAGS)
ldflags := $(strip $(ldflags))
BUILD_FLAGS := -tags "$(build_tags)" -ldflags '$(ldflags)' -trimpath
###############################################################################
### Help ###
###############################################################################
.DEFAULT_GOAL := help
help:
@echo "Structs Chain Makefile"
@echo ""
@echo "Usage: make [target]"
@echo ""
@echo "Build:"
@echo " build Build structsd for current platform"
@echo " install Install structsd to GOPATH/bin"
@echo " build-all Build for all supported platforms"
@echo " build-linux-amd64 Cross-compile for linux/amd64"
@echo " build-linux-arm64 Cross-compile for linux/arm64"
@echo " build-darwin-amd64 Cross-compile for darwin/amd64 (Intel Mac)"
@echo " build-darwin-arm64 Cross-compile for darwin/arm64 (Apple Silicon)"
@echo " build-windows-amd64 Cross-compile for windows/amd64"
@echo " clean Remove build artifacts"
@echo ""
@echo "Proto:"
@echo " proto-all Format, lint, and generate all proto outputs"
@echo " proto-gen Generate Go protobuf files (gogo + pulsar)"
@echo " proto-gen-ts Generate TypeScript proto bindings"
@echo " proto-swagger Generate OpenAPI/Swagger spec"
@echo " proto-format Format .proto files"
@echo " proto-lint Lint .proto files"
@echo ""
@echo "Test:"
@echo " test Run all tests"
@echo " test-unit Run unit tests with timeout"
@echo " test-race Run tests with race detector"
@echo " test-cover Run tests with coverage report"
@echo " test-integration Run integration test script"
@echo ""
@echo "Lint:"
@echo " lint Run golangci-lint"
@echo " lint-fix Run golangci-lint with auto-fix"
@echo " format Format Go source files"
@echo ""
@echo "Dev:"
@echo " serve Start chain via Ignite CLI"
@echo " serve-reset Start chain via Ignite CLI (reset state)"
@echo " serve-reset-verbose Start chain via Ignite CLI (reset + verbose)"
@echo ""
@echo "Release:"
@echo " release-dry-run Test release locally (no publish)"
@echo " release Create a release (requires GITHUB_TOKEN)"
@echo ""
@echo "Misc:"
@echo " go.sum Verify and tidy Go dependencies"
###############################################################################
### Build ###
###############################################################################
check_version:
ifneq ($(shell [ "$(GO_SYSTEM_VERSION)" \< "$(REQUIRE_GO_VERSION)" ] && echo true),)
@echo "ERROR: Go version $(REQUIRE_GO_VERSION)+ is required (found $(GO_SYSTEM_VERSION))"
@exit 1
endif
all: build lint test
build: check_version go.sum
@mkdir -p $(BUILDDIR)
go build -mod=readonly $(BUILD_FLAGS) -o $(BUILDDIR)/structsd ./cmd/structsd
@echo "Built: $(BUILDDIR)/structsd"
install: check_version go.sum
go install -mod=readonly $(BUILD_FLAGS) ./cmd/structsd
@echo "Installed: structsd"
clean:
rm -rf $(BUILDDIR)/
###############################################################################
### Cross-Compilation ###
###############################################################################
PLATFORMS := linux/amd64 linux/arm64 darwin/amd64 darwin/arm64 windows/amd64
build-all: $(foreach p,$(PLATFORMS),build-$(subst /,-,$(p)))
@echo "All platform builds complete. Artifacts in $(BUILDDIR)/"
define BUILD_PLATFORM
build-$(subst /,-,$(1)): check_version go.sum
@echo "Building structsd for $(1)..."
@mkdir -p $(BUILDDIR)
CGO_ENABLED=0 GOOS=$(word 1,$(subst /, ,$(1))) GOARCH=$(word 2,$(subst /, ,$(1))) \
go build -mod=readonly $(BUILD_FLAGS) \
-o $(BUILDDIR)/structsd-$(subst /,-,$(1))$(if $(findstring windows,$(1)),.exe) \
./cmd/structsd
@echo "Built: $(BUILDDIR)/structsd-$(subst /,-,$(1))$(if $(findstring windows,$(1)),.exe)"
endef
$(foreach p,$(PLATFORMS),$(eval $(call BUILD_PLATFORM,$(p))))
###############################################################################
### Dependencies ###
###############################################################################
go.sum: go.mod
@echo "--> Verifying dependencies"
go mod verify
go mod tidy
@echo "--> Downloading dependencies"
go mod download
###############################################################################
### Protobuf ###
###############################################################################
proto-all: proto-format proto-lint proto-gen proto-gen-ts
@echo "Proto generation complete."
proto-gen:
@echo "--> Generating Go protobuf files (gogo)..."
buf generate --template proto/buf.gen.gogo.yaml
@echo "--> Generating Go protobuf files (pulsar)..."
buf generate --template proto/buf.gen.pulsar.yaml
proto-gen-ts:
@echo "--> Generating TypeScript proto bindings..."
buf generate --template proto/buf.gen.ts.yaml
proto-swagger:
@echo "--> Generating OpenAPI/Swagger spec..."
buf generate --template proto/buf.gen.swagger.yaml
proto-format:
@echo "--> Formatting proto files..."
buf format -w
proto-lint:
@echo "--> Linting proto files..."
buf lint
.PHONY: proto-all proto-gen proto-gen-ts proto-swagger proto-format proto-lint
###############################################################################
### Tests ###
###############################################################################
TEST_PACKAGES := ./...
test:
@echo "--> Running all tests"
go test -mod=readonly $(TEST_PACKAGES)
test-unit:
@echo "--> Running unit tests"
go test -mod=readonly -timeout=5m -tags='norace' $(TEST_PACKAGES)
test-race:
@echo "--> Running tests with race detector"
go test -mod=readonly -timeout=5m -race $(TEST_PACKAGES)
test-cover:
@echo "--> Running tests with coverage"
go test -mod=readonly -timeout=5m -tags='norace' \
-coverprofile=coverage.txt -covermode=atomic $(TEST_PACKAGES)
@echo "Coverage report: coverage.txt"
test-integration:
@echo "--> Running integration tests"
bash tests/test_chain.sh
.PHONY: test test-unit test-race test-cover test-integration
###############################################################################
### Linting & Format ###
###############################################################################
golangci_version = v2.1.6
lint:
@echo "--> Running linter"
@go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(golangci_version)
golangci-lint run --timeout=10m
lint-fix:
@echo "--> Running linter with auto-fix"
@go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(golangci_version)
golangci-lint run --fix --issues-exit-code=0
format:
@echo "--> Formatting Go source files"
@go install mvdan.cc/gofumpt@latest
find . -name '*.go' -type f \
-not -path "./vendor/*" \
-not -path "./.git/*" \
-not -name "*.pb.go" \
-not -name "*.pb.gw.go" \
-not -name "*.pulsar.go" \
| xargs gofumpt -w -l
.PHONY: lint lint-fix format
###############################################################################
### Local Development ###
###############################################################################
serve:
ignite chain serve
serve-reset:
ignite chain serve --reset-once
serve-reset-verbose:
ignite chain serve --reset-once --verbose
.PHONY: serve serve-reset serve-reset-verbose
###############################################################################
### Release ###
###############################################################################
release-dry-run:
@echo "--> Running release dry run..."
TM_VERSION=$(TM_VERSION) goreleaser release --snapshot --clean
@echo "Dry run complete. Artifacts in dist/"
ifdef GITHUB_TOKEN
release:
@echo "--> Creating release..."
TM_VERSION=$(TM_VERSION) goreleaser release --clean
else
release:
@echo "Error: GITHUB_TOKEN is not set."
@echo "Usage: GITHUB_TOKEN=<token> make release"
@echo ""
@echo "Or push a tag to trigger the GitHub Actions release workflow:"
@echo " git tag v1.0.0 && git push origin v1.0.0"
@exit 1
endif
.PHONY: release release-dry-run
###############################################################################
### Phony Targets ###
###############################################################################
.PHONY: all build install clean check_version help go.sum build-all