forked from erigontech/erigon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
333 lines (275 loc) · 12.8 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
333
GO ?= go # if using docker, should not need to be installed/linked
GOBINREL = build/bin
GOBIN = $(CURDIR)/$(GOBINREL)
UNAME = $(shell uname) # Supported: Darwin, Linux
DOCKER := $(shell command -v docker 2> /dev/null)
GIT_COMMIT ?= $(shell git rev-list -1 HEAD)
GIT_BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)
GIT_TAG ?= $(shell git describe --tags '--match=*.*.*' --abbrev=7 --dirty)
ERIGON_USER ?= erigon
# if using volume-mounting data dir, then must exist on host OS
DOCKER_UID ?= $(shell id -u)
DOCKER_GID ?= $(shell id -g)
DOCKER_TAG ?= erigontech/erigon:latest
# Variables below for building on host OS, and are ignored for docker
#
# Pipe error below to /dev/null since Makefile structure kind of expects
# Go to be available, but with docker it's not strictly necessary
CGO_CFLAGS := $(shell $(GO) env CGO_CFLAGS 2>/dev/null) # don't lose default
CGO_CFLAGS += -DMDBX_FORCE_ASSERTIONS=0 # Enable MDBX's asserts by default in 'main' branch and disable in releases
CGO_CFLAGS += -DMDBX_DISABLE_VALIDATION=0 # Can disable it on CI by separated PR which will measure perf impact.
#CGO_CFLAGS += -DMDBX_ENABLE_PROFGC=0 # Disabled by default, but may be useful for performance debugging
#CGO_CFLAGS += -DMDBX_ENABLE_PGOP_STAT=0 # Disabled by default, but may be useful for performance debugging
CGO_CFLAGS += -DMDBX_ENV_CHECKPID=0 # Erigon doesn't do fork() syscall
# If it is arm64 or aarch64, then we need to use portable version of blst. use or with stringw "arm64" and "aarch64" to support both
ifeq ($(shell uname -m), arm64)
CGO_CFLAGS += -D__BLST_PORTABLE__
endif
ifeq ($(shell uname -m), aarch64)
CGO_CFLAGS += -D__BLST_PORTABLE__
endif
CGO_CFLAGS += -Wno-unknown-warning-option -Wno-enum-int-mismatch -Wno-strict-prototypes -Wno-unused-but-set-variable -O3
CGO_LDFLAGS := $(shell $(GO) env CGO_LDFLAGS 2> /dev/null)
CGO_LDFLAGS += -O3 -g
ifeq ($(shell uname -s), Darwin)
ifeq ($(filter-out 13.%,$(shell sw_vers --productVersion)),)
CGO_LDFLAGS += -mmacosx-version-min=13.3
endif
endif
# about netgo see: https://github.com/golang/go/issues/30310#issuecomment-471669125 and https://github.com/golang/go/issues/57757
BUILD_TAGS = nosqlite,noboltdb
ifneq ($(shell "$(CURDIR)/turbo/silkworm/silkworm_compat_check.sh"),)
BUILD_TAGS := $(BUILD_TAGS),nosilkworm
endif
GOPRIVATE = github.com/erigontech/silkworm-go
PACKAGE = github.com/erigontech/erigon
GO_FLAGS += -trimpath -tags $(BUILD_TAGS) -buildvcs=false
GO_FLAGS += -ldflags "-X ${PACKAGE}/params.GitCommit=${GIT_COMMIT} -X ${PACKAGE}/params.GitBranch=${GIT_BRANCH} -X ${PACKAGE}/params.GitTag=${GIT_TAG}"
GOBUILD = CGO_CFLAGS="$(CGO_CFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" GOPRIVATE="$(GOPRIVATE)" $(GO) build $(GO_FLAGS)
GO_DBG_BUILD = CGO_CFLAGS="$(CGO_CFLAGS) -DMDBX_DEBUG=1" CGO_LDFLAGS="$(CGO_LDFLAGS)" GOPRIVATE="$(GOPRIVATE)" $(GO) build -tags $(BUILD_TAGS),debug -gcflags=all="-N -l" # see delve docs
GOTEST = CGO_CFLAGS="$(CGO_CFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" GOPRIVATE="$(GOPRIVATE)" GODEBUG=cgocheck=0 GOTRACEBACK=1 $(GO) test $(GO_FLAGS) ./... -p 2
default: all
## go-version: print and verify go version
go-version:
@if [ $(shell $(GO) version | cut -c 16-17) -lt 20 ]; then \
echo "minimum required Golang version is 1.20"; \
exit 1 ;\
fi
## validate_docker_build_args: ensure docker build args are valid
validate_docker_build_args:
@echo "Docker build args:"
@echo " DOCKER_UID: $(DOCKER_UID)"
@echo " DOCKER_GID: $(DOCKER_GID)\n"
@echo "Ensuring host OS user exists with specified UID/GID..."
@if [ "$(UNAME)" = "Darwin" ]; then \
dscl . list /Users UniqueID | grep "$(DOCKER_UID)"; \
elif [ "$(UNAME)" = "Linux" ]; then \
cat /etc/passwd | grep "$(DOCKER_UID):$(DOCKER_GID)"; \
fi
@echo "✔️ host OS user exists: $(shell id -nu $(DOCKER_UID))"
## docker: validate, update submodules and build with docker
docker: validate_docker_build_args git-submodules
DOCKER_BUILDKIT=1 $(DOCKER) build -t ${DOCKER_TAG} \
--build-arg "BUILD_DATE=$(shell date +"%Y-%m-%dT%H:%M:%S:%z")" \
--build-arg VCS_REF=${GIT_COMMIT} \
--build-arg VERSION=${GIT_TAG} \
--build-arg UID=${DOCKER_UID} \
--build-arg GID=${DOCKER_GID} \
${DOCKER_FLAGS} \
.
xdg_data_home := ~/.local/share
ifdef XDG_DATA_HOME
xdg_data_home = $(XDG_DATA_HOME)
endif
xdg_data_home_subdirs = $(xdg_data_home)/erigon $(xdg_data_home)/erigon-grafana $(xdg_data_home)/erigon-prometheus
## setup_xdg_data_home: TODO
setup_xdg_data_home:
mkdir -p $(xdg_data_home_subdirs)
ls -aln $(xdg_data_home) | grep -E "472.*0.*erigon-grafana" || chown -R 472:0 $(xdg_data_home)/erigon-grafana
@echo "✔️ xdg_data_home setup"
@ls -al $(xdg_data_home)
## docker-compose: validate build args, setup xdg data home, and run docker-compose up
docker-compose: validate_docker_build_args setup_xdg_data_home
docker compose up
## dbg debug build allows see C stack traces, run it with GOTRACEBACK=crash. You don't need debug build for C pit for profiling. To profile C code use SETCGOTRCKEBACK=1
dbg:
$(GO_DBG_BUILD) -o $(GOBIN)/ ./cmd/...
%.cmd:
@# Note: $* is replaced by the command name
@echo "Building $*"
@cd ./cmd/$* && $(GOBUILD) -o $(GOBIN)/$*
@echo "Run \"$(GOBIN)/$*\" to launch $*."
## geth: run erigon (TODO: remove?)
geth: erigon
## erigon: build erigon
erigon: go-version erigon.cmd
@rm -f $(GOBIN)/tg # Remove old binary to prevent confusion where users still use it because of the scripts
COMMANDS += devnet
COMMANDS += capcli
COMMANDS += downloader
COMMANDS += hack
COMMANDS += integration
COMMANDS += observer
COMMANDS += pics
COMMANDS += rpcdaemon
COMMANDS += rpctest
COMMANDS += sentry
COMMANDS += state
COMMANDS += txpool
COMMANDS += verkle
COMMANDS += evm
COMMANDS += sentinel
COMMANDS += caplin
COMMANDS += snapshots
COMMANDS += diag
# build each command using %.cmd rule
$(COMMANDS): %: %.cmd
## all: run erigon with all commands
all: erigon $(COMMANDS)
## db-tools: build db tools
db-tools:
@echo "Building db-tools"
go mod vendor
cd vendor/github.com/erigontech/mdbx-go && MDBX_BUILD_TIMESTAMP=unknown make tools
mkdir -p $(GOBIN)
cd vendor/github.com/erigontech/mdbx-go/mdbxdist && cp mdbx_chk $(GOBIN) && cp mdbx_copy $(GOBIN) && cp mdbx_dump $(GOBIN) && cp mdbx_drop $(GOBIN) && cp mdbx_load $(GOBIN) && cp mdbx_stat $(GOBIN)
rm -rf vendor
@echo "Run \"$(GOBIN)/mdbx_stat -h\" to get info about mdbx db file."
test-erigon-lib:
@cd erigon-lib && $(MAKE) test
test-erigon-ext:
@cd tests/erigon-ext-test && ./test.sh $(GIT_COMMIT)
## test: run unit tests with a 100s timeout
test: test-erigon-lib
$(GOTEST) --timeout 10m -coverprofile=coverage.out
## test-integration: run integration tests with a 30m timeout
test-integration: test-erigon-lib
$(GOTEST) --timeout 240m -tags $(BUILD_TAGS),integration
## lint-deps: install lint dependencies
lint-deps:
@cd erigon-lib && $(MAKE) lint-deps
## lintci: run golangci-lint linters
lintci:
@cd erigon-lib && $(MAKE) lintci
@./erigon-lib/tools/golangci_lint.sh
## lint: run all linters
lint:
@cd erigon-lib && $(MAKE) lint
@./erigon-lib/tools/golangci_lint.sh
@./erigon-lib/tools/mod_tidy_check.sh
## clean: cleans the go cache, build dir, libmdbx db dir
clean:
go clean -cache
rm -fr build/*
# The devtools target installs tools required for 'go generate'.
# You need to put $GOBIN (or $GOPATH/bin) in your PATH to use 'go generate'.
## devtools: installs dev tools (and checks for npm installation etc.)
devtools:
# Notice! If you adding new binary - add it also to tools.go file
$(GOBUILD) -o $(GOBIN)/gencodec github.com/fjl/gencodec
$(GOBUILD) -o $(GOBIN)/mockgen go.uber.org/mock/mockgen
$(GOBUILD) -o $(GOBIN)/abigen ./cmd/abigen
@type "npm" 2> /dev/null || echo 'Please install node.js and npm'
@type "solc" 2> /dev/null || echo 'Please install solc'
@type "protoc" 2> /dev/null || echo 'Please install protoc'
## mocks: generate test mocks
mocks: mocks-clean
@cd erigon-lib && $(MAKE) mocks
$(GOBUILD) -o $(GOBIN)/mockgen go.uber.org/mock/mockgen
PATH="$(GOBIN):$(PATH)" go generate -run "mockgen" ./...
## mocks-clean: cleans all generated test mocks
mocks-clean:
grep -r -l --exclude-dir="erigon-lib" --exclude-dir="tests" --exclude-dir="*$(GOBINREL)*" "^// Code generated by MockGen. DO NOT EDIT.$$" . | xargs rm -r
## solc: generate all solidity contracts
solc:
PATH="$(GOBIN):$(PATH)" go generate -run "solc" ./...
## abigen: generate abis using abigen
abigen:
$(GOBUILD) -o $(GOBIN)/abigen ./cmd/abigen
PATH="$(GOBIN):$(PATH)" go generate -run "abigen" ./...
## gencodec: generate marshalling code using gencodec
gencodec:
$(GOBUILD) -o $(GOBIN)/gencodec github.com/fjl/gencodec
PATH="$(GOBIN):$(PATH)" go generate -run "gencodec" ./...
## graphql: generate graphql code
graphql:
PATH=$(GOBIN):$(PATH) cd ./cmd/rpcdaemon/graphql && go run github.com/99designs/gqlgen .
## gen: generate all auto-generated code in the codebase
gen: mocks solc abigen gencodec graphql
@cd erigon-lib && $(MAKE) gen
## bindings: generate test contracts and core contracts
bindings:
PATH=$(GOBIN):$(PATH) go generate ./tests/contracts/
PATH=$(GOBIN):$(PATH) go generate ./core/state/contracts/
## prometheus: run prometheus and grafana with docker-compose
prometheus:
docker compose up prometheus grafana
## escape: run escape path={path} to check for memory leaks e.g. run escape path=cmd/erigon
escape:
cd $(path) && go test -gcflags "-m -m" -run none -bench=BenchmarkJumpdest* -benchmem -memprofile mem.out
## git-submodules: update git submodules
git-submodules:
@[ -d ".git" ] || (echo "Not a git repository" && exit 1)
@echo "Updating git submodules"
@# Dockerhub using ./hooks/post-checkout to set submodules, so this line will fail on Dockerhub
@# these lines will also fail if ran as root in a non-root user's checked out repository
@git submodule sync --quiet --recursive || true
@git submodule update --quiet --init --recursive --force || true
## install: copies binaries and libraries to DIST
DIST ?= $(CURDIR)/build/dist
.PHONY: install
install:
mkdir -p "$(DIST)"
cp -f "$$($(CURDIR)/turbo/silkworm/silkworm_lib_path.sh)" "$(DIST)"
cp -f "$(GOBIN)/"* "$(DIST)"
@echo "Copied files to $(DIST):"
@ls -al "$(DIST)"
PACKAGE_NAME := github.com/erigontech/erigon
GOLANG_CROSS_VERSION ?= v1.21.5
.PHONY: release-dry-run
release-dry-run: git-submodules
@docker run \
--rm \
--privileged \
-e CGO_ENABLED=1 \
-e GITHUB_TOKEN \
-e DOCKER_USERNAME \
-e DOCKER_PASSWORD \
-v /var/run/docker.sock:/var/run/docker.sock \
-v `pwd`:/go/src/$(PACKAGE_NAME) \
-w /go/src/$(PACKAGE_NAME) \
ghcr.io/goreleaser/goreleaser-cross:${GOLANG_CROSS_VERSION} \
--clean --skip=validate --skip=publish
# since DOCKER_UID, DOCKER_GID are default initialized to the current user uid/gid,
# we need separate envvars to facilitate creation of the erigon user on the host OS.
ERIGON_USER_UID ?= 3473
ERIGON_USER_GID ?= 3473
## user_linux: create "erigon" user (Linux)
user_linux:
ifdef DOCKER
sudo groupadd -f docker
endif
sudo addgroup --gid $(ERIGON_USER_GID) $(ERIGON_USER) 2> /dev/null || true
sudo adduser --disabled-password --gecos '' --uid $(ERIGON_USER_UID) --gid $(ERIGON_USER_GID) $(ERIGON_USER) 2> /dev/null || true
sudo mkhomedir_helper $(ERIGON_USER)
echo 'export PATH=$$PATH:/usr/local/go/bin' | sudo -u $(ERIGON_USER) tee /home/$(ERIGON_USER)/.bash_aliases >/dev/null
ifdef DOCKER
sudo usermod -aG docker $(ERIGON_USER)
endif
sudo -u $(ERIGON_USER) mkdir -p /home/$(ERIGON_USER)/.local/share
## user_macos: create "erigon" user (MacOS)
user_macos:
sudo dscl . -create /Users/$(ERIGON_USER)
sudo dscl . -create /Users/$(ERIGON_USER) UserShell /bin/bash
sudo dscl . -list /Users UniqueID | grep $(ERIGON_USER) | grep $(ERIGON_USER_UID) || sudo dscl . -create /Users/$(ERIGON_USER) UniqueID $(ERIGON_USER_UID)
sudo dscl . -create /Users/$(ERIGON_USER) PrimaryGroupID $(ERIGON_USER_GID)
sudo dscl . -create /Users/$(ERIGON_USER) NFSHomeDirectory /Users/$(ERIGON_USER)
sudo dscl . -append /Groups/admin GroupMembership $(ERIGON_USER)
sudo -u $(ERIGON_USER) mkdir -p /Users/$(ERIGON_USER)/.local/share
## automated-tests run automated tests (BUILD_ERIGON=0 to prevent erigon build with local image tag)
.PHONY: automated-tests
automated-tests:
./tests/automated-testing/run.sh
## help: print commands help
help : Makefile
@sed -n 's/^##//p' $<