2022-06-30 03:11:37 -07:00
GO = go # if using docker, should not need to be installed/linked
2020-09-30 16:28:36 +07:00
GOBIN = $( CURDIR) /build/bin
2022-06-30 03:11:37 -07:00
UNAME = $( shell uname) # Supported: Darwin, Linux
DOCKER := $( shell command -v docker 2> /dev/null)
2015-11-20 16:06:35 +02:00
2020-10-30 09:43:24 +01:00
GIT_COMMIT ?= $( shell git rev-list -1 HEAD)
2021-04-11 11:23:50 +07:00
GIT_BRANCH ?= $( shell git rev-parse --abbrev-ref HEAD)
2022-05-25 03:12:40 +02:00
GIT_TAG ?= $( shell git describe --tags '--match=v*' --dirty)
2022-06-30 03:11:37 -07:00
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)
2022-06-16 14:50:59 +00:00
DOCKER_TAG ?= thorax/erigon:latest
2022-01-23 10:05:31 +07:00
2022-06-30 03:11:37 -07:00
# 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
2022-01-31 16:59:49 +07:00
CGO_CFLAGS += -DMDBX_FORCE_ASSERTIONS= 1 # Enable MDBX's asserts by default in 'devel' branch and disable in 'stable'
2022-01-23 10:05:31 +07:00
CGO_CFLAGS := CGO_CFLAGS = " $( CGO_CFLAGS) "
DBG_CGO_CFLAGS += -DMDBX_DEBUG= 1
2022-04-22 02:15:23 +02:00
BUILD_TAGS = nosqlite,noboltdb
PACKAGE = github.com/ledgerwatch/erigon
2020-09-06 12:35:32 +01:00
2022-04-22 10:56:44 +07:00
GO_FLAGS += -trimpath -tags $( BUILD_TAGS) -buildvcs= false
2022-04-22 02:15:23 +02:00
GO_FLAGS += -ldflags " -X ${ PACKAGE } /params.GitCommit= ${ GIT_COMMIT } -X ${ PACKAGE } /params.GitBranch= ${ GIT_BRANCH } -X ${ PACKAGE } /params.GitTag= ${ GIT_TAG } "
GOBUILD = $( CGO_CFLAGS) $( GO) build $( GO_FLAGS)
GO_DBG_BUILD = $( DBG_CGO_CFLAGS) $( GO) build $( GO_FLAGS) -tags $( BUILD_TAGS) ,debug -gcflags= all = "-N -l" # see delve docs
2022-05-04 05:35:59 +02:00
GOTEST = GODEBUG = cgocheck = 0 $( GO) test $( GO_FLAGS) ./... -p 2
2021-04-19 17:54:56 +07:00
2022-02-24 16:10:46 +01:00
default : all
2020-08-21 14:38:11 +02:00
2021-04-19 17:54:56 +07:00
go-version :
2022-06-30 03:11:37 -07:00
@if [ $( shell $( GO) version | cut -c 16-17) -lt 18 ] ; then \
2022-04-22 10:56:44 +07:00
echo "minimum required Golang version is 1.18" ; \
2021-04-19 17:54:56 +07:00
exit 1 ; \
fi
2022-06-30 03:11:37 -07:00
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_docker_build_args git -submodules
DOCKER_BUILDKIT = 1 $( DOCKER) build -t ${ DOCKER_TAG } \
2022-05-21 11:21:35 +02:00
--build-arg " BUILD_DATE= $( shell date -Iseconds) " \
--build-arg VCS_REF = ${ GIT_COMMIT } \
--build-arg VERSION = ${ GIT_TAG } \
2022-06-30 03:11:37 -07:00
--build-arg UID = ${ DOCKER_UID } \
--build-arg GID = ${ DOCKER_GID } \
2022-05-21 11:21:35 +02:00
${ DOCKER_FLAGS } \
.
2020-08-21 14:38:11 +02:00
2021-07-19 15:40:09 +02:00
xdg_data_home := ~/.local/share
i f d e f X D G _ D A T A _ H O M E
xdg_data_home = $( XDG_DATA_HOME)
e n d i f
2022-06-30 03:11:37 -07:00
xdg_data_home_subdirs = $( xdg_data_home) /erigon $( xdg_data_home) /erigon-grafana $( xdg_data_home) /erigon-prometheus
docker-compose : validate_docker_build_args
mkdir -p $( xdg_data_home_subdirs)
2021-07-19 15:40:09 +02:00
docker-compose up
2019-05-27 14:51:49 +01:00
2021-04-29 21:29:58 +07:00
# 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
2021-06-20 03:30:12 +07:00
dbg :
2021-04-29 21:29:58 +07:00
$( GO_DBG_BUILD) -o $( GOBIN) / ./cmd/...
2022-02-24 16:10:46 +01:00
%.cmd : git -submodules
@# Note: $* is replaced by the command name
@echo " Building $* "
2022-03-04 01:47:09 +01:00
@cd ./cmd/$* && $( GOBUILD) -o $( GOBIN) /$*
2022-02-24 16:10:46 +01:00
@echo " Run \" $( GOBIN) / $* \" to launch $* . "
2021-05-31 17:20:56 +07:00
geth : erigon
2015-04-18 23:21:45 +02:00
2022-02-24 16:10:46 +01:00
erigon : go -version erigon .cmd
2022-02-22 19:17:50 +01:00
@rm -f $( GOBIN) /tg # Remove old binary to prevent confusion where users still use it because of the scripts
2021-05-08 11:45:40 +03:00
2022-02-24 16:10:46 +01:00
COMMANDS += cons
COMMANDS += devnettest
COMMANDS += downloader
COMMANDS += hack
COMMANDS += integration
2022-04-22 13:02:12 +02:00
COMMANDS += observer
2022-02-24 16:10:46 +01:00
COMMANDS += pics
COMMANDS += rpcdaemon
2022-06-10 16:18:43 +01:00
COMMANDS += rpcdaemon22
2022-02-24 16:10:46 +01:00
COMMANDS += rpctest
COMMANDS += sentry
COMMANDS += state
COMMANDS += txpool
# build each command using %.cmd rule
$(COMMANDS) : %: %.cmd
all : erigon $( COMMANDS )
2021-11-23 17:44:46 +01:00
2022-04-29 14:07:39 +07:00
db-tools : git -submodules
2021-06-20 03:30:12 +07:00
@echo "Building db-tools"
2021-12-15 16:07:57 +07:00
# hub.docker.com setup incorrect gitpath for git modules. Just remove it and re-init submodule.
rm -rf libmdbx
2022-01-19 14:54:56 +07:00
git submodule update --init --recursive --force libmdbx
2021-12-15 16:07:57 +07:00
2021-06-27 09:53:49 +07:00
cd libmdbx && MDBX_BUILD_TIMESTAMP = unknown make tools
2021-06-20 03:30:12 +07:00
cp libmdbx/mdbx_chk $( GOBIN)
cp libmdbx/mdbx_copy $( GOBIN)
cp libmdbx/mdbx_dump $( GOBIN)
cp libmdbx/mdbx_drop $( GOBIN)
cp libmdbx/mdbx_load $( GOBIN)
cp libmdbx/mdbx_stat $( GOBIN)
2021-06-11 20:31:37 +07:00
@echo " Run \" $( GOBIN) /mdbx_stat -h\" to get info about mdbx db file. "
2020-10-08 14:11:36 +07:00
2021-06-18 10:35:11 +07:00
test :
2022-05-04 05:35:59 +02:00
$( GOTEST) --timeout 30s
test-integration :
$( GOTEST) --timeout 30m -tags $( BUILD_TAGS) ,integration
2020-06-12 16:31:21 +07:00
2021-04-27 14:48:59 +07:00
lint :
2021-06-04 19:26:15 +07:00
@./build/bin/golangci-lint run --config ./.golangci.yml
2019-05-27 14:51:49 +01:00
2021-06-18 10:35:11 +07:00
lintci :
2021-03-30 02:17:19 +03:00
@echo "--> Running linter for code"
2021-06-04 19:26:15 +07:00
@./build/bin/golangci-lint run --config ./.golangci.yml
2019-11-05 09:12:49 +01:00
2019-05-27 14:51:49 +01:00
lintci-deps :
2019-11-06 15:34:35 +03:00
rm -f ./build/bin/golangci-lint
2022-05-26 12:27:44 +07:00
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b ./build/bin v1.46.2
2018-04-18 00:53:50 +02:00
2016-05-25 14:07:57 +02:00
clean :
2021-12-22 11:18:35 +07:00
go clean -cache
2020-10-28 10:18:10 +07:00
rm -fr build/*
2021-06-20 03:30:12 +07:00
cd libmdbx/ && make clean
2016-05-25 14:07:57 +02:00
2017-02-26 23:52:10 +01:00
# 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 :
2020-10-02 10:56:13 +07:00
# Notice! If you adding new binary - add it also to cmd/hack/binary-deps/main.go file
$( GOBUILD) -o $( GOBIN) /go-bindata github.com/kevinburke/go-bindata/go-bindata
$( GOBUILD) -o $( GOBIN) /gencodec github.com/fjl/gencodec
$( GOBUILD) -o $( GOBIN) /codecgen github.com/ugorji/go/codec/codecgen
$( GOBUILD) -o $( GOBIN) /abigen ./cmd/abigen
PATH = $( GOBIN) :$( PATH) go generate ./common
PATH = $( GOBIN) :$( PATH) go generate ./core/types
2021-06-26 01:13:40 +07:00
PATH = $( GOBIN) :$( PATH) go generate ./consensus/aura/...
2022-05-30 17:08:49 +07:00
#PATH=$(GOBIN):$(PATH) go generate ./eth/ethconfig/...
2018-01-08 13:15:57 +01:00
@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'
2017-02-26 23:52:10 +01:00
2019-05-27 14:51:49 +01:00
bindings :
2020-10-02 10:56:13 +07:00
PATH = $( GOBIN) :$( PATH) go generate ./tests/contracts/
PATH = $( GOBIN) :$( PATH) go generate ./core/state/contracts/
2020-09-03 10:51:19 +03:00
2020-04-29 17:51:07 +07:00
prometheus :
2020-08-01 22:05:48 +07:00
docker-compose up prometheus grafana
2020-06-05 19:46:34 +03:00
escape :
2020-06-15 19:39:34 +03:00
cd $( path) && go test -gcflags "-m -m" -run none -bench= BenchmarkJumpdest* -benchmem -memprofile mem.out
2022-01-19 14:54:56 +07:00
git-submodules :
2022-04-29 14:07:39 +07:00
@[ -d ".git" ] || ( echo "Not a git repository" && exit 1)
2022-02-22 19:17:50 +01:00
@echo "Updating git submodules"
@# Dockerhub using ./hooks/post-checkout to set submodules, so this line will fail on Dockerhub
2022-06-30 03:11:37 -07:00
@# these lines will also fail if ran as root in a non-root user' s checked out repository
@git submodule sync --quiet --recursive || true
2022-02-22 19:17:50 +01:00
@git submodule update --quiet --init --recursive --force || true
2022-06-30 03:11:37 -07:00
# 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
ERIGON_USER_XDG_DATA_HOME ?= ~$( ERIGON_USER) /.local/share
# create "erigon" user
user_linux :
i f d e f D O C K E R
sudo groupadd -f docker
e n d i f
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
i f d e f D O C K E R
sudo usermod -aG docker $( ERIGON_USER)
e n d i f
sudo -u $( ERIGON_USER) mkdir -p ~$( ERIGON_USER_XDG_DATA_HOME)
# create "erigon" user
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 ~$( ERIGON_USER_XDG_DATA_HOME)