forked from lambdaclass/lambda_ethereum_consensus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
208 lines (153 loc) · 6.78 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
.PHONY: iex deps test spec-test lint clean compile-native compile-port fmt \
clean-vectors download-vectors uncompress-vectors proto \
spec-test-% spec-test spec-test-config-% spec-test-runner-% \
spec-test-mainnet-% spec-test-minimal-% spec-test-general-% \
clean-tests gen-spec compile-all
# Delete current file when command fails
.DELETE_ON_ERROR:
##### NATIVE COMPILATION #####
### NIF
default: help
#❓ help: @ Displays this message
help:
@grep -E '[a-zA-Z\.\-\%]+:.*?@ .*$$' $(firstword $(MAKEFILE_LIST))| tr -d '#' | awk 'BEGIN {FS = ":.*?@ "}; {printf "\033[32m%-30s\033[0m %s\n", $$1, $$2}'
# magic from sym_num https://elixirforum.com/t/where-is-erl-nif-h-header-file-required-for-nif/27142/5
ERLANG_INCLUDES := $(shell erl -eval 'io:format("~s", \
[lists:concat([code:root_dir(), "/erts-", erlang:system_info(version), "/include"])] \
)' -s init stop -noshell)
LIBP2P_DIR = native/libp2p_nif
OUTPUT_DIR = priv/native
# create directories if they don't exist
DIRS=$(OUTPUT_DIR)
$(info $(shell mkdir -p $(DIRS)))
GO_SOURCES := $(LIBP2P_DIR)/go_src/main.go
GO_ARCHIVES := $(patsubst %.go,%.a,$(GO_SOURCES))
GO_HEADERS := $(patsubst %.go,%.h,$(GO_SOURCES))
CFLAGS = -Wall -Werror
CFLAGS += -Wl,-undefined -Wl,dynamic_lookup -fPIC -shared
CFLAGS += -I$(ERLANG_INCLUDES)
$(LIBP2P_DIR)/go_src/%.a $(LIBP2P_DIR)/go_src/%.h: $(LIBP2P_DIR)/go_src/%.go
cd $(LIBP2P_DIR)/go_src; \
go build -buildmode=c-archive $*.go
$(OUTPUT_DIR)/libp2p_nif.so: $(GO_ARCHIVES) $(GO_HEADERS) $(LIBP2P_DIR)/libp2p.c $(LIBP2P_DIR)/go_src/utils.c
gcc $(CFLAGS) -I $(LIBP2P_DIR)/go_src -o $@ \
$(LIBP2P_DIR)/libp2p.c $(LIBP2P_DIR)/go_src/utils.c $(GO_ARCHIVES)
### PORT
PROTOBUF_EX_FILES := proto/libp2p.pb.ex
PROTOBUF_GO_FILES := native/libp2p_port/internal/proto/libp2p.pb.go
$(PROTOBUF_GO_FILES): proto/libp2p.proto
protoc --go_out=./native/libp2p_port $<
$(PROTOBUF_EX_FILES): proto/libp2p.proto
protoc --elixir_out=. $<
PORT_SOURCES := $(shell find native/libp2p_port -type f)
$(OUTPUT_DIR)/libp2p_port: $(PORT_SOURCES) $(PROTOBUF_GO_FILES)
cd native/libp2p_port; go build -o ../../$@
##### TARGETS #####
#💻 nix: @ Start a nix environment.
nix:
nix develop
#💻 nix-zsh: @ Start a nix environment using zsh as a console.
nix-zsh:
nix develop -c zsh
#🔄 deps: @ Install mix dependencies.
deps:
sh scripts/install_protos.sh
$(MAKE) proto
cd native/libp2p_port; \
go get && go install
mix deps.get
#📝 proto: @ Generate protobuf code
proto: $(PROTOBUF_EX_FILES) $(PROTOBUF_GO_FILES)
#🔨 compile-native: @ Compile C and Go artifacts.
compile-native: $(OUTPUT_DIR)/libp2p_nif.so $(OUTPUT_DIR)/libp2p_port
#🔨 compile-all: @ Compile the elixir project and its dependencies.
compile-all: compile-native $(PROTOBUF_EX_FILES)
mix compile
#🗑️ clean: @ Remove the build files.
clean:
-mix clean
-rm $(GO_ARCHIVES) $(GO_HEADERS) $(OUTPUT_DIR)/*
#📊 grafana-up: @ Start grafana server.
grafana-up:
cd metrics/ && docker compose up -d
#📊 grafana-down: @ Stop grafana server.
grafana-down:
cd metrics/ && docker compose down
#🗑️ grafana-clean: @ Remove the grafana data.
grafana-clean:
cd metrics/ && docker compose down -v
#▶️ start: @ Start application with Beacon API.
start: compile-all
iex -S mix phx.server
#▶️ iex: @ Runs an interactive terminal with the main supervisor setup.
iex: compile-all
iex -S mix
#▶️ checkpoint-sync: @ Run an interactive terminal using checkpoint sync.
checkpoint-sync: compile-all
iex -S mix run -- --checkpoint-sync https://sync-mainnet.beaconcha.in/
#▶️ sepolia: @ Run an interactive terminal using sepolia network
sepolia: compile-all
iex -S mix run -- --checkpoint-sync https://sepolia.beaconstate.info --network sepolia
#🔴 test: @ Run tests
test: compile-all
mix test --no-start --exclude spectest
##### SPEC TEST VECTORS #####
SPECTEST_VERSION := $(shell cat .spectest_version)
SPECTEST_CONFIGS = general minimal mainnet
SPECTEST_ROOTDIR = test/spec/vectors
SPECTEST_GENERATED_ROOTDIR = test/generated
VECTORS_DIR = $(SPECTEST_ROOTDIR)/tests
# create directory if it doesn't exist
$(info $(shell mkdir -p $(SPECTEST_ROOTDIR)))
SPECTEST_DIRS := $(patsubst %,$(SPECTEST_ROOTDIR)/tests/%,$(SPECTEST_CONFIGS))
SPECTEST_GENERATED := $(patsubst %,$(SPECTEST_GENERATED_ROOTDIR)/%,$(SPECTEST_CONFIGS))
SPECTEST_TARS := $(patsubst %,$(SPECTEST_ROOTDIR)/%_${SPECTEST_VERSION}.tar.gz,$(SPECTEST_CONFIGS))
$(SPECTEST_ROOTDIR)/%_${SPECTEST_VERSION}.tar.gz:
curl -L -o "$@" \
"https://github.com/ethereum/consensus-spec-tests/releases/download/${SPECTEST_VERSION}/$*.tar.gz"
$(VECTORS_DIR)/%: $(SPECTEST_ROOTDIR)/%_${SPECTEST_VERSION}.tar.gz
-rm -rf $@
tar -xzmf "$<" -C $(SPECTEST_ROOTDIR)
$(SPECTEST_GENERATED_ROOTDIR): $(VECTORS_DIR)/mainnet $(VECTORS_DIR)/minimal $(VECTORS_DIR)/general lib/spec/runners/*.ex lib/mix/tasks/generate_spec_tests.ex
mix generate_spec_tests
#⬇️ download-vectors: @ Download the spec test vectors files.
download-vectors: $(SPECTEST_TARS)
#🗑️ clean-vectors: @ Remove the downloaded spec test vectors.
clean-vectors:
-rm -rf $(SPECTEST_ROOTDIR)/tests
-rm $(SPECTEST_ROOTDIR)/*.tar.gz
#📝 gen-spec: @ Generate the spec tests.
gen-spec: $(SPECTEST_GENERATED_ROOTDIR)
#🗑️ clean-tests: @ Remove the generated spec tests.
clean-tests:
-rm -r test/generated
#🔴 spec-test: @ Run all spec tests
spec-test: compile-all $(PROTOBUF_EX_FILES) $(SPECTEST_GENERATED_ROOTDIR)
mix test --no-start test/generated/*/*/*
#🔴 spec-test-config-%: @ Run all spec tests for a specific config (e.g. mainnet)
spec-test-config-%: compile-all $(PROTOBUF_EX_FILES) $(SPECTEST_GENERATED_ROOTDIR)
mix test --no-start test/generated/$*/*/*
#🔴 spec-test-runner-%: @ Run all spec tests for a specific runner (e.g. epoch_processing)
spec-test-runner-%: compile-all $(PROTOBUF_EX_FILES) $(SPECTEST_GENERATED_ROOTDIR)
mix test --no-start test/generated/*/*/$*.exs
#🔴 spec-test-mainnet-%: @ Run spec tests for mainnet config, for the specified runner.
spec-test-mainnet-%: compile-all $(PROTOBUF_EX_FILES) $(SPECTEST_GENERATED_ROOTDIR)
mix test --no-start test/generated/mainnet/*/$*.exs
#🔴 spec-test-minimal-%: @ Run spec tests for minimal config, for the specified runner.
spec-test-minimal-%: compile-all $(PROTOBUF_EX_FILES) $(SPECTEST_GENERATED_ROOTDIR)
mix test --no-start test/generated/minimal/*/$*.exs
#🔴 spec-test-general-%: @ Run spec tests for general config, for the specified runner.
spec-test-general-%: compile-all $(PROTOBUF_EX_FILES) $(SPECTEST_GENERATED_ROOTDIR)
mix test --no-start test/generated/general/*/$*.exs
#✅ lint: @ Check formatting and linting.
lint:
mix format --check-formatted
mix credo --strict
#✅ fmt: @ Format all code (Go, rust and elixir).
fmt:
mix format
gofmt -l -w native/libp2p_nif/go_src
gofmt -l -w native/libp2p_port
cd native/snappy_nif; cargo fmt
cd native/ssz_nif; cargo fmt
cd native/bls_nif; cargo fmt