-
Notifications
You must be signed in to change notification settings - Fork 14
/
Makefile
332 lines (266 loc) · 10.7 KB
/
Makefile
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
322
323
324
325
326
327
328
329
330
331
332
#!/usr/bin/make -f
COMMIT ?= $(shell git log -1 --format='%H')
# Specify a tag only if it has a specific tag, otherwise choose a branch name and concatenate the commit hash.
ifeq (,$(VERSION))
BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
VERSION := $(shell echo $(shell git describe --tags) | sed 's/^v//')
SHORT_COMMIT := $(shell git log -1 --format='%h')
ifneq (, $(findstring $(SHORT_COMMIT),$(VERSION)))
VERSION = $(subst /,_,$(BRANCH))-$(COMMIT)
endif
endif
PACKAGES_SIMTEST=$(shell go list ./... | grep '/simulation')
SDK_PACK := $(shell go list -m github.com/Finschia/finschia-sdk | sed 's/ /\@/g')
GO_VERSION := $(shell cat go.mod | grep -E 'go [0-9].[0-9]+' | cut -d ' ' -f 2)
OCVERSION := $(shell go list -m github.com/Finschia/ostracon | sed 's:.* v::')
WASMVM_VERSION=$(shell go list -m github.com/Finschia/wasmvm | awk '{print $$2}')
HEIGHLINER_VERSION=v1.5.3
DOCKER := $(shell which docker)
LEDGER_ENABLED ?= true
BUILDDIR ?= $(CURDIR)/build
ARCH ?= amd64
TARGET_PLATFORM = linux/amd64
TEMPDIR ?= $(CURDIR)/temp
export GO111MODULE = on
OS_NAME := $(shell uname -s | tr A-Z a-z)
ifeq ($(ARCH), arm64)
TARGET_PLATFORM = linux/arm64
endif
# process build tags
build_tags = netgo
ifeq ($(LEDGER_ENABLED),true)
build_tags += ledger
endif
ifeq ($(LINK_STATICALLY),true)
build_tags += static_wasm muslc
endif
build_tags += $(BUILD_TAGS)
build_tags := $(strip $(build_tags))
whitespace :=
whitespace += $(whitespace)
comma := ,
build_tags_comma_sep := $(subst $(whitespace),$(comma),$(build_tags))
# process linker flags
ldflags = -X github.com/Finschia/finschia-sdk/version.Name=finschia \
-X github.com/Finschia/finschia-sdk/version.AppName=fnsad \
-X github.com/Finschia/finschia-sdk/version.Version=$(VERSION) \
-X github.com/Finschia/finschia-sdk/version.Commit=$(COMMIT) \
-X github.com/Finschia/finschia-sdk/types.DBBackend=goleveldb \
-X "github.com/Finschia/finschia-sdk/version.BuildTags=$(build_tags_comma_sep)" \
-X github.com/Finschia/ostracon/version.OCCoreSemVer=$(OCVERSION) \
-linkmode=external \
-w -s
ldflags += $(LDFLAGS)
ldflags := $(strip $(ldflags))
BUILD_FLAGS := -tags "$(build_tags)" -ldflags '$(ldflags)'
ifeq ($(LINK_STATICALLY),true)
CGO_CFLAGS := -I$(TEMPDIR)/include
CGO_LDFLAGS := -L$(TEMPDIR)/lib
ifeq ($(OS_NAME),darwin)
CGO_LDFLAGS += -lz -lbz2
else
CGO_LDFLAGS += -static -lwasmvm_muslc -lm
endif
endif
###############################################################################
### Documentation ###
###############################################################################
all: install lint test
$(TEMPDIR)/:
mkdir -p $(TEMPDIR)/
wasmvmlib: $(TEMPDIR)/
ifeq ($(LINK_STATICALLY),true)
@mkdir -p $(TEMPDIR)/lib
ifeq (",$(wildcard $(TEMPDIR)/lib/libwasmvm*.a)")
ifeq ($(OS_NAME),darwin)
curl -L https://github.com/Finschia/wasmvm/releases/download/$(WASMVM_VERSION)/libwasmvmstatic_darwin.a -o $(TEMPDIR)/lib/libwasmvmstatic_darwin.a
else
ifeq ($(ARCH),amd64)
wget https://github.com/Finschia/wasmvm/releases/download/$(WASMVM_VERSION)/libwasmvm_muslc.x86_64.a -O $(TEMPDIR)/lib/libwasmvm_muslc.a
else
wget https://github.com/Finschia/wasmvm/releases/download/$(WASMVM_VERSION)/libwasmvm_muslc.aarch64.a -O $(TEMPDIR)/lib/libwasmvm_muslc.a
endif
endif
endif
endif
# command for make build and make install
build: BUILDARGS=-o $(BUILDDIR)/
build install: go.sum $(BUILDDIR)/ wasmvmlib
CGO_ENABLED=1 CGO_CFLAGS="$(CGO_CFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" go $@ -mod=readonly $(BUILD_FLAGS) $(BUILDARGS) ./...
# ensure build directory exists
$(BUILDDIR)/:
mkdir -p $(BUILDDIR)/
go.sum: go.mod
@echo "--> Ensure dependencies have not been modified"
@go mod verify
clean:
rm -rf $(BUILDDIR)/ $(TEMPDIR)/
distclean: clean
rm -rf vendor/
build-reproducible: go.sum
mkdir -p $(BUILDDIR)
$(DOCKER) buildx create --name finschiabuilder || true
$(DOCKER) buildx use finschiabuilder
$(DOCKER) buildx build \
--build-arg GO_VERSION=$(GO_VERSION) \
--build-arg GIT_VERSION=$(VERSION) \
--build-arg GIT_COMMIT=$(COMMIT) \
--build-arg OST_VERSION=$(OST_VERSION) \
--build-arg RUNNER_IMAGE=alpine:3.18 \
--platform $(TARGET_PLATFORM) \
-t finschia/finschianode:local-$(ARCH) \
--load \
-f Dockerfile .
$(DOCKER) rm -f finschiabinary || true
$(DOCKER) create -ti --name finschiabinary finschia/finschianode:local-$(ARCH)
$(DOCKER) cp finschiabinary:/usr/bin/fnsad $(BUILDDIR)/fnsad-linux-$(ARCH)
$(DOCKER) rm -f finschiabinary
go-mod-cache: go.sum
@echo "--> Download go modules to local cache"
@go mod download
get-heighliner:
git clone --branch $(HEIGHLINER_VERSION) https://github.com/strangelove-ventures/heighliner.git $(TEMPDIR)/heighliner
cd $(TEMPDIR)/heighliner && go install
local-image:
ifeq (,$(shell which heighliner))
echo 'heighliner' binary not found. Consider running `make get-heighliner`
else
heighliner build -c finschia --local --dockerfile cosmos --build-target "wget https://github.com/Finschia/wasmvm/releases/download/$(WASMVM_VERSION)/libwasmvm_muslc.aarch64.a -O /lib/libwasmvm.aarch64.a && make install" --binaries "/go/bin/fnsad"
endif
.PHONY: all build install clean wasmvmlib build-reproducible get-heighliner local-image
###############################################################################
### Tests & Simulation ###
###############################################################################
include sims.mk
test: test-unit
test-all: test-race test-cover
test-unit:
@VERSION=$(VERSION) go test -mod=readonly -tags='ledger test_ledger_mock' ./...
test-race:
@VERSION=$(VERSION) go test -mod=readonly -race -tags='ledger test_ledger_mock' ./...
test-cover:
@go test -mod=readonly -timeout 30m -race -coverprofile=coverage.txt -covermode=atomic -tags='ledger test_ledger_mock' ./...
benchmark:
@go test -mod=readonly -bench=. ./...
test-integration: build
@go test -mod=readonly -p 4 `go list ./cli_test/...` $(CLI_TEST_BUILD_FLAGS) -v
test-integration-multi-node: docker-build
@go test -mod=readonly -p 4 `go list ./cli_test/...` $(CLI_MULTI_BUILD_FLAGS) -v
test-upgrade-name:
@sh contrib/check-upgrade-name.sh
test-e2e-ibc:
cd interchaintest && go test -v ./...
.PHONY: test test-all test-unit test-race test-cover benchmark test-integration test-integration-multi-node test-e2e-ibc
###############################################################################
### Docker ###
###############################################################################
RUNNER_BASE_IMAGE_ALPINE := alpine:3.18
docker-build:
@DOCKER_BUILDKIT=1 docker build \
-t finschia/finschianode:local \
-t finschia/finschianode:local-distroless \
--build-arg GO_VERSION=$(GO_VERSION) \
--build-arg RUNNER_IMAGE=$(RUNNER_BASE_IMAGE_ALPINE) \
--build-arg GIT_VERSION=$(VERSION) \
--build-arg GIT_COMMIT=$(COMMIT) \
--build-arg OST_VERSION=$(OST_VERSION) \
--platform=$(TARGET_PLATFORM) \
-f Dockerfile .
.PHONY: docker-build
###############################################################################
### Linting ###
###############################################################################
lint: golangci-lint
golangci-lint run --out-format=tab
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" | xargs gofmt -d -s
golangci-lint:
@go install github.com/golangci/golangci-lint/cmd/[email protected]
format: golangci-lint
golangci-lint run ./... --fix
.PHONY: lint format
###############################################################################
### Localnet ###
###############################################################################
localnet-docker-build:
@DOCKER_BUILDKIT=1 docker build \
-t finschia/finschianode:localnet \
--build-arg GO_VERSION=$(GO_VERSION) \
--build-arg RUNNER_IMAGE=$(RUNNER_BASE_IMAGE_ALPINE) \
--build-arg GIT_VERSION=$(VERSION) \
--build-arg GIT_COMMIT=$(COMMIT) \
--build-arg OST_VERSION=$(OST_VERSION) \
--platform=$(TARGET_PLATFORM) \
-f networks/local/finschianode/Dockerfile .
# Run a 4-node testnet locally
localnet-start: localnet-stop localnet-docker-build localnet-build-nodes
localnet-build-nodes:
docker run --rm -v $(CURDIR)/mytestnet:/data finschia/finschianode:localnet \
testnet init-files --v 4 -o /data --starting-ip-address 192.168.10.2 --keyring-backend=test
docker-compose up -d
# Stop testnet
localnet-stop:
docker-compose down
.PHONY: localnet-docker-build localnet-start localnet-build-nodes localnet-stop
###############################################################################
### Proto ###
###############################################################################
proto-swagger-gen:
@echo "Generating Protobuf Swagger"
./scripts/generate-docs.sh
statik -src=client/docs/swagger-ui -dest=client/docs -f -m
.PHONY: proto-swagger-gen
###############################################################################
### Release ###
###############################################################################
GORELEASER_IMAGE := goreleaser/goreleaser-cross:v$(GO_VERSION)
PACKAGE_NAME := github.com/Finschia/finschia
ifdef GITHUB_TOKEN
release:
docker run \
--rm \
--platform linux/amd64 \
-e GITHUB_TOKEN=$(GITHUB_TOKEN) \
-e WASMVM_VERSION=$(WASMVM_VERSION) \
-e OST_VERSION=$(OST_VERSION) \
-v /var/run/docker.sock:/var/run/docker.sock \
-v `pwd`:/go/src/$(PACKAGE_NAME) \
-w /go/src/$(PACKAGE_NAME) \
$(GORELEASER_IMAGE) \
release \
--clean \
--release-notes ./RELEASE_NOTE.md
else
release:
@echo "Error: GITHUB_TOKEN is not defined. Please define it before running 'make release'."
endif
release-dry-run:
docker run \
--rm \
--platform linux/amd64 \
-e WASMVM_VERSION=$(WASMVM_VERSION) \
-e OST_VERSION=$(OST_VERSION) \
-v /var/run/docker.sock:/var/run/docker.sock \
-v `pwd`:/go/src/$(PACKAGE_NAME) \
-w /go/src/$(PACKAGE_NAME) \
$(GORELEASER_IMAGE) \
release \
--clean \
--release-notes ./RELEASE_NOTE.md \
--skip=publish
release-snapshot:
docker run \
--rm \
--platform linux/amd64 \
-e WASMVM_VERSION=$(WASMVM_VERSION) \
-e OST_VERSION=$(OST_VERSION) \
-v /var/run/docker.sock:/var/run/docker.sock \
-v `pwd`:/go/src/$(PACKAGE_NAME) \
-w /go/src/$(PACKAGE_NAME) \
$(GORELEASER_IMAGE) \
release \
--clean \
--release-notes ./RELEASE_NOTE.md \
--snapshot \
--skip=validate \
--skip=publish
.PHONY: release release-dry-run release-snapshot