-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathMakefile
More file actions
274 lines (232 loc) · 12.6 KB
/
Makefile
File metadata and controls
274 lines (232 loc) · 12.6 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
ifeq ($(OS),Windows_NT)
UNAME := Windows
else
UNAME := $(shell uname)
endif
EXPLORER_UI_DIR ?= crates/explorer/ui/src
EXPLORER_UI_DIST ?= crates/explorer/ui/dist
SNOS_OUTPUT ?= tests/snos/snos/build/
FIXTURES_DIR ?= tests/fixtures
DB_FIXTURES_DIR ?= $(FIXTURES_DIR)/db
SNOS_DB_TAR ?= $(DB_FIXTURES_DIR)/snos.tar.gz
SNOS_DB_DIR := $(DB_FIXTURES_DIR)/snos
COMPATIBILITY_DB_TAR ?= $(DB_FIXTURES_DIR)/1_6_0.tar.gz
COMPATIBILITY_DB_DIR ?= $(DB_FIXTURES_DIR)/1_6_0
SPAWN_AND_MOVE_DB := $(DB_FIXTURES_DIR)/spawn_and_move
SIMPLE_DB := $(DB_FIXTURES_DIR)/simple
CONTRACTS_CRATE := crates/contracts
CONTRACTS_DIR := $(CONTRACTS_CRATE)/contracts
CONTRACTS_BUILD_DIR := $(CONTRACTS_CRATE)/build
AMDSEV_DIR := misc/AMDSEV
VRF_DIR := $(CONTRACTS_DIR)/vrf
AVNU_DIR := $(CONTRACTS_DIR)/avnu/contracts
OPENZEPPELIN_DIR := $(CONTRACTS_DIR)/openzeppelin
VRF_TEST_DIR := tests/vrf/contracts
# The scarb version required by the AVNU contracts (no .tool-versions in that directory)
AVNU_SCARB_VERSION := 2.11.4
# The scarb version required by the OpenZeppelin presets package.
OPENZEPPELIN_SCARB_VERSION := 2.11.4
# The scarb version required by the main contracts.
SCARB_VERSION := $(shell awk '$$1 == "scarb" { print $$2 }' $(CONTRACTS_DIR)/.tool-versions 2>/dev/null)
# The scarb version required by VRF contracts, if specified in its .tool-versions.
VRF_SCARB_VERSION := $(shell if [ -f $(VRF_DIR)/.tool-versions ]; then awk '$$1 == "scarb" { print $$2 }' $(VRF_DIR)/.tool-versions; fi)
# The scarb version required by the test VRF contracts.
VRF_TEST_SCARB_VERSION := $(shell if [ -f $(VRF_TEST_DIR)/.tool-versions ]; then awk '$$1 == "scarb" { print $$2 }' $(VRF_TEST_DIR)/.tool-versions; fi)
# `make contracts` only compiles the VRF test contracts, and that succeeds with the
# same scarb used by the main VRF workspace. Keeping the build path on 2.12.2 avoids
# installing an extra 2.13.1 toolchain in CI, which was exhausting disk space.
VRF_TEST_BUILD_SCARB_VERSION := $(VRF_SCARB_VERSION)
# All scarb versions needed for `make contracts`.
SCARB_REQUIRED_VERSIONS := $(sort $(SCARB_VERSION) $(AVNU_SCARB_VERSION) $(OPENZEPPELIN_SCARB_VERSION) $(VRF_SCARB_VERSION) $(VRF_TEST_BUILD_SCARB_VERSION))
.DEFAULT_GOAL := all
.SILENT: clean
.PHONY: all usage help check-llvm native-deps native-deps-macos native-deps-linux native-deps-windows build-explorer contracts tee-sev-snp clean deps install-scarb fixtures snos-artifacts db-compat-artifacts generate-db-fixtures install-pyenv
all: fixtures build-explorer
@echo "All build artifacts generated successfully."
usage help:
@echo "Usage:"
@echo " deps: Install all required dependencies for building Katana with all features (incl. tests)."
@echo " snos-deps: Install SNOS test dependencies (pyenv, Python 3.9.15)."
@echo " build-explorer: Build the explorer."
@echo " contracts: Build the contracts."
@echo " tee-sev-snp: Build AMD SEV-SNP TEE VM components (prompts y/N to build katana unless KATANA_BINARY is set)."
@echo " fixtures: Prepare tests artifacts (including test database)."
@echo " snos-artifacts: Prepare SNOS tests artifacts."
@echo " db-compat-artifacts: Prepare database compatibility test artifacts."
@echo " generate-db-fixtures: Generate spawn-and-move and simple DB fixtures (requires scarb + sozo)."
@echo " native-deps-macos: Install cairo-native dependencies for macOS."
@echo " native-deps-linux: Install cairo-native dependencies for Linux."
@echo " native-deps-windows: Install cairo-native dependencies for Windows."
@echo " check-llvm: Check if LLVM is properly configured."
@echo " clean: Clean up generated files and artifacts."
@echo " help: Show this help message."
deps: install-scarb native-deps snos-deps
@echo "All dependencies installed successfully."
install-scarb:
@command -v asdf >/dev/null 2>&1 || { echo "Error: asdf is required but not installed."; exit 1; }
@asdf plugin list 2>/dev/null | grep -qx scarb || { \
echo "Adding asdf scarb plugin..."; \
asdf plugin add scarb || { echo "Failed to add asdf scarb plugin!"; exit 1; }; \
}
@for version in $(SCARB_REQUIRED_VERSIONS); do \
if asdf where scarb "$$version" >/dev/null 2>&1; then \
echo "scarb $$version is already installed."; \
else \
echo "Installing scarb $$version..."; \
asdf install scarb "$$version" || { echo "Failed to install scarb $$version!"; exit 1; }; \
echo "scarb $$version installed successfully."; \
fi; \
done
snos-artifacts: $(SNOS_OUTPUT)
@echo "SNOS test artifacts prepared successfully."
db-compat-artifacts: $(COMPATIBILITY_DB_DIR)
@echo "Database compatibility test artifacts prepared successfully."
fixtures: $(SNOS_DB_DIR) $(SNOS_OUTPUT) $(COMPATIBILITY_DB_DIR) $(SPAWN_AND_MOVE_DB) $(SIMPLE_DB) contracts
@echo "All test fixtures prepared successfully."
build-explorer:
@which bun >/dev/null 2>&1 || { echo "Error: bun is required but not installed. Please install bun first."; exit 1; }
@$(MAKE) $(EXPLORER_UI_DIST)
contracts: install-scarb
@mkdir -p $(CONTRACTS_BUILD_DIR)
@echo "Building main contracts..."
@cd $(CONTRACTS_DIR) && asdf exec scarb build || { echo "Main contracts build failed!"; exit 1; }
@find $(CONTRACTS_DIR)/target/dev -maxdepth 1 -type f -exec cp {} $(CONTRACTS_BUILD_DIR) \;
@echo "Building VRF contracts..."
@cd $(VRF_DIR) && asdf exec scarb build || { echo "VRF contracts build failed!"; exit 1; }
@find $(VRF_DIR)/target/dev -maxdepth 1 -type f -exec cp {} $(CONTRACTS_BUILD_DIR) \;
@echo "Building AVNU contracts..."
@cd $(AVNU_DIR) && ASDF_SCARB_VERSION=$(AVNU_SCARB_VERSION) asdf exec scarb build || { echo "AVNU contracts build failed!"; exit 1; }
@find $(AVNU_DIR)/target/dev -maxdepth 1 -type f -exec cp {} $(CONTRACTS_BUILD_DIR) \;
@echo "Building OpenZeppelin account preset..."
@if [ ! -f $(OPENZEPPELIN_DIR)/packages/presets/Scarb.toml ]; then \
git submodule update --init --recursive --force $(OPENZEPPELIN_DIR) || { echo "OpenZeppelin submodule init failed!"; exit 1; }; \
fi
@cd $(OPENZEPPELIN_DIR) && ASDF_SCARB_VERSION=$(OPENZEPPELIN_SCARB_VERSION) asdf exec scarb build -p openzeppelin_presets || { echo "OpenZeppelin account preset build failed!"; exit 1; }
@cp $(OPENZEPPELIN_DIR)/target/dev/openzeppelin_presets_AccountUpgradeable.contract_class.json $(CONTRACTS_BUILD_DIR) || { echo "OpenZeppelin account preset artifact copy failed!"; exit 1; }
@echo "Building test VRF contracts..."
@cd $(VRF_TEST_DIR) && ASDF_SCARB_VERSION=$(VRF_TEST_BUILD_SCARB_VERSION) asdf exec scarb build || { echo "Test VRF contracts build failed!"; exit 1; }
@mkdir -p tests/vrf/build
@find $(VRF_TEST_DIR)/target/dev -maxdepth 1 -type f -exec cp {} tests/vrf/build \;
tee-sev-snp:
@echo "Building AMD SEV-SNP TEE VM components..."
@if [ -n "$(KATANA_BINARY)" ]; then \
echo "Using katana binary: $(KATANA_BINARY)"; \
$(AMDSEV_DIR)/build.sh --katana "$(KATANA_BINARY)"; \
elif [ ! -t 0 ]; then \
echo "Error: non-interactive run requires KATANA_BINARY."; \
echo "Example: make tee-sev-snp KATANA_BINARY=/path/to/katana"; \
exit 1; \
else \
$(AMDSEV_DIR)/build.sh; \
fi
$(EXPLORER_UI_DIR):
@echo "Initializing Explorer UI submodule..."
@git submodule update --init --recursive --force crates/explorer/ui
$(EXPLORER_UI_DIST): $(EXPLORER_UI_DIR)
@echo "Building Explorer..."
@cd crates/explorer/ui && \
bun install && \
bun run build || { echo "Explorer build failed!"; exit 1; }
@echo "Explorer build complete."
$(SNOS_OUTPUT): $(SNOS_DB_DIR)
@echo "Initializing submodules..."
@git submodule update --init --recursive
@echo "Setting up SNOS tests..."
@cd tests/snos/snos && \
PIP_DEFAULT_TIMEOUT=120 PIP_RETRIES=5 . ./setup-scripts/setup-cairo.sh && \
. ./setup-scripts/setup-tests.sh || { echo "SNOS setup failed\!"; exit 1; }
$(SNOS_DB_DIR): $(SNOS_DB_TAR)
@echo "Extracting SNOS test database..."
@cd $(DB_FIXTURES_DIR) && \
tar -xzf snos.tar.gz || { echo "Failed to extract SNOS test database\!"; exit 1; }
@echo "SNOS test database extracted successfully."
$(COMPATIBILITY_DB_DIR): $(COMPATIBILITY_DB_TAR)
@echo "Extracting backward compatibility test database..."
@cd $(DB_FIXTURES_DIR) && \
tar -xzf $(notdir $(COMPATIBILITY_DB_TAR)) && \
mv katana_db $(notdir $(COMPATIBILITY_DB_DIR)) || { echo "Failed to extract backward compatibility test database\!"; exit 1; }
@echo "Backward compatibility database extracted successfully."
$(SPAWN_AND_MOVE_DB): $(SPAWN_AND_MOVE_DB).tar.gz
@echo "Extracting Dojo example spawn-and-move test database..."
@tar -xzf $< -C $(DB_FIXTURES_DIR) || { echo "Failed to extract spawn-and-move test database\!"; exit 1; }
@echo "Example Dojo spawn-and-move database extracted successfully."
$(SIMPLE_DB): $(SIMPLE_DB).tar.gz
@echo "Extracting Dojo example simple test database..."
@tar -xzf $< -C $(DB_FIXTURES_DIR) || { echo "Failed to extract spawn-and-move test database\!"; exit 1; }
@echo "Example Dojo simple database extracted successfully."
generate-db-fixtures:
@echo "Building generate_migration_db binary..."
cargo build --bin generate_migration_db --features node -p katana-utils
@echo "Generating spawn-and-move database fixture..."
./target/debug/generate_migration_db --example spawn-and-move --output /tmp/spawn_and_move.tar.gz
@echo "Generating simple database fixture..."
./target/debug/generate_migration_db --example simple --output /tmp/simple.tar.gz
@echo "Extracting spawn-and-move fixture..."
@mkdir -p $(DB_FIXTURES_DIR)
@cd $(DB_FIXTURES_DIR) && tar -xzf /tmp/spawn_and_move.tar.gz
@echo "Extracting simple fixture..."
@cd $(DB_FIXTURES_DIR) && tar -xzf /tmp/simple.tar.gz
@echo "DB fixtures generated successfully."
check-llvm:
ifndef MLIR_SYS_190_PREFIX
$(error Could not find a suitable LLVM 19 toolchain (mlir), please set MLIR_SYS_190_PREFIX env pointing to the LLVM 19 dir)
endif
ifndef TABLEGEN_190_PREFIX
$(error Could not find a suitable LLVM 19 toolchain (tablegen), please set TABLEGEN_190_PREFIX env pointing to the LLVM 19 dir)
endif
@echo "LLVM is correctly set at $(MLIR_SYS_190_PREFIX)."
native-deps:
ifeq ($(UNAME), Darwin)
native-deps: native-deps-macos
else ifeq ($(UNAME), Linux)
native-deps: native-deps-linux
else ifeq ($(UNAME), Windows)
native-deps: native-deps-windows
endif
@echo "Run \`source scripts/cairo-native.env.sh\` to setup the needed environment variables for cairo-native."
native-deps-macos:
@echo "Installing LLVM dependencies for macOS..."
-brew install llvm@19 --quiet
@echo "macOS dependencies installed successfully."
native-deps-linux:
@echo "Installing LLVM dependencies for Linux..."
sudo apt-get install -y llvm-19 llvm-19-dev llvm-19-runtime clang-19 clang-tools-19 lld-19 libpolly-19-dev libmlir-19-dev mlir-19-tools
@echo "Linux dependencies installed successfully."
native-deps-windows:
@echo "Installing LLVM dependencies for Windows..."
@where choco >nul 2>&1 || { echo "Error: Chocolatey is required but not installed. Please install Chocolatey first: https://chocolatey.org/install"; exit 1; }
choco install llvm --version 19.1.7 -y
@echo "Windows dependencies installed successfully."
install-pyenv:
@if command -v pyenv >/dev/null 2>&1; then \
echo "pyenv is already installed."; \
else \
echo "Installing pyenv..."; \
curl https://pyenv.run | bash || { echo "Failed to install pyenv!"; exit 1; }; \
echo "pyenv installed successfully."; \
echo "NOTE: Add the following to your shell profile (~/.bashrc or ~/.zshrc):"; \
echo ' export PYENV_ROOT="$$HOME/.pyenv"'; \
echo ' command -v pyenv >/dev/null || export PATH="$$PYENV_ROOT/bin:$$PATH"'; \
echo ' eval "$$(pyenv init -)"'; \
fi
snos-deps:
ifeq ($(UNAME), Darwin)
snos-deps: snos-deps-macos
else ifeq ($(UNAME), Linux)
snos-deps: snos-deps-linux
endif
snos-deps-linux: install-pyenv
@echo "Installing Python build dependencies for Linux..."
sudo apt-get update
sudo apt-get install -y make build-essential libssl-dev libgmp-dev libbz2-dev libreadline-dev libsqlite3-dev liblzma-dev zlib1g-dev
@echo "Linux SNOS dependencies installed successfully."
@echo "NOTE: You may need to restart your shell or run 'source ~/.bashrc' before using pyenv."
snos-deps-macos: install-pyenv
@echo "Installing Python build dependencies for macOS..."
-brew install openssl readline sqlite3 zlib --quiet
@echo "macOS SNOS dependencies installed successfully."
@echo "NOTE: You may need to restart your shell or run 'source ~/.zshrc' before using pyenv."
clean:
echo "Cleaning up generated files..."
-rm -rf $(SNOS_DB_DIR) $(COMPATIBILITY_DB_DIR) $(SPAWN_AND_MOVE_DB) $(SIMPLE_DB) $(SNOS_OUTPUT) $(EXPLORER_UI_DIST) $(CONTRACTS_BUILD_DIR)
echo "Clean complete."