forked from LightDotSo/LightDotSo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
277 lines (211 loc) · 9.73 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
# Heavily inspired by Lighthouse: https://github.com/sigp/lighthouse/blob/693886b94176faa4cb450f024696cb69cda2fe58/Makefile
# Also from Reth: https://github.com/paradigmxyz/reth/blob/7da36e042125397af89b9b477f9292dc676e69f8/Makefile
# And from: https://github.com/Terrahop/react-native-rust-demo/blob/30a70fe16148c33ded2f3789b303a52ad5dd6b72/rust/Makefile
# Some: https://github.com/xmtp/libxmtp/blob/1491ccb6d3f9ae6ff7671435f0df81545044bb44/bindings_swift/Makefile
## Constants
WORKSPACE = lightdotso
NAME = libuniffi_lightwallet_core
STATIC_LIB_NAME = $(NAME).a
SHARED_LIB_NAME = $(NAME).so
ARCHS_IOS = x86_64-apple-ios aarch64-apple-ios-sim
ARCHS_IOS_ARM = aarch64-apple-ios
ARCHS_MAC = x86_64-apple-darwin aarch64-apple-darwin
SOLC_VERSION = 0.8.18
CRATES_DIR = "crates/core"
CARGO_PARAMS = --package lightwallet-core --crate-type=staticlib
TARGET_DIR = target
ifdef CI
ifeq ($(CI),true)
INSTALL_PARAMS = cargo-setup ci-setup
endif
else
ifeq ($(DOCKER),true)
INSTALL_PARAMS = cargo-setup docker-setup
else
INSTALL_PARAMS = ios-setup mac-setup
endif
endif
##@ Help
.PHONY: help
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "Usage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
##@ Install
install: $(INSTALL_PARAMS) ## Install all dependencies.
.PHONY: cargo-setup
cargo-setup: ## Install Cargo dependencies.
rustup toolchain install nightly
rustup component add rustfmt --toolchain nightly
.PHONY: ci-setup
ci-setup: solc-setup ## Install CI dependencies.
.PHONY: docker-setup
docker-setup: solc-setup ## Install docker dependencies.
.PHONY: ios-setup
ios-setup: ## Install iOS dependencies.
rustup target add $(ARCHS_IOS)
rustup target add $(ARCHS_IOS_ARM)
.PHONY: solc-setup
solc-setup: ## Install solc dependencies.
pip3 install solc-select || pip3 install solc-select --break-system-packages
solc-select install $(SOLC_VERSION)
solc-select use $(SOLC_VERSION)
.PHONY: mac-setup
mac-setup: ## Install macOS dependencies.
rustup target add $(ARCHS_MAC)
.PHONY: ruff-setup
ruff-setup: ## Install ruff dependencies.
brew install ruff
##@ Build
.PHONY: ios
ios: ## Build the project for iOS.
@make $(STATIC_LIB_NAME)
@make bindgen-swift
@make assemble-frameworks
@make xcframework
@make cp-xcframework-source
##@ Cargo Build
.PHONY: $(ARCHS_IOS) ## Build the project for iOS.
$(ARCHS_IOS): %:
cargo rustc $(CARGO_PARAMS) --target $@ --release
.PHONY: $(ARCHS_IOS_ARM) ## Build the project for iOS (Specific structure).
$(ARCHS_IOS_ARM): %:
cargo rustc $(CARGO_PARAMS) --target $@ --release
.PHONY: $(ARCHS_MAC) ## Build the project for macOS.
$(ARCHS_MAC): %:
cargo rustc $(CARGO_PARAMS) --target $@ --release
##@ Apple Build
.PHONY: $(STATIC_LIB_NAME)
$(STATIC_LIB_NAME): $(ARCHS_IOS) $(ARCHS_IOS_ARM) $(ARCHS_MAC) ## Build the universal binary for iOS and macOS.
rm -rf $(TARGET_DIR)/lipo_macos $(TARGET_DIR)/lipo_ios_simulator || echo "Skip removing $(STATIC_LIB_NAME)"
mkdir -p $(TARGET_DIR)/lipo_macos $(TARGET_DIR)/lipo_ios_simulator
lipo -create -output $(TARGET_DIR)/lipo_ios_simulator/$(STATIC_LIB_NAME) $(foreach arch,$(ARCHS_IOS),$(wildcard target/$(arch)/release/$(STATIC_LIB_NAME)))
lipo -create -output $(TARGET_DIR)/lipo_macos/$(STATIC_LIB_NAME) $(foreach arch,$(ARCHS_MAC),$(wildcard target/$(arch)/release/$(STATIC_LIB_NAME)))
.PHONY: bindgen-swift
bindgen-swift: ## Generate the Swift bindings.
rm -rf $(TARGET_DIR)/Generated || echo "Skip removing Generated"
mkdir -p $(TARGET_DIR)/Generated
cp -r $(CRATES_DIR)/src $(TARGET_DIR)/Generated/
find $(TARGET_DIR)/Generated -type f -name "*.swift" -delete
cargo uniffi-bindgen generate $(CRATES_DIR)/src/LightWalletCore.udl --language swift
sed -i '' 's/module\ LightWalletCoreFFI/framework\ module\ LightWalletCoreFFI/' $(CRATES_DIR)/src/LightWalletCoreFFI.modulemap
.PHONY: xcframework
xcframework: ## Build the xcframework for iOS and macOS.
rm -rf $(TARGET_DIR)/LightWalletCoreFFI.framework || echo "Skip removing framework"
xcodebuild -create-xcframework \
-library ./$(TARGET_DIR)/lipo_macos/$(STATIC_LIB_NAME) \
-headers ./$(TARGET_DIR)/Generated/ \
-library ./$(TARGET_DIR)/lipo_ios_simulator/$(STATIC_LIB_NAME) \
-headers ./$(TARGET_DIR)/Generated/ \
-output $(TARGET_DIR)/LightWalletCoreFFI.xcframework
.PHONY: cp-xcframework-source
cp-xcframework-source: ## Copy the xcframework to the iOS project.
cp -r $(TARGET_DIR)/LightWalletCoreFFI.xcframework ios
cp $(CRATES_DIR)/src/LightWalletCore.swift ios/LightWalletCore/Sources/Generated
##@ Old Overrides
.PHONY: assemble-frameworks
assemble-frameworks: # Temporary override for old build system
find . -type d -name LightWalletCoreFFI.framework -exec rm -rf {} \; || echo "rm failed"
cd target/x86_64-apple-ios/release && mkdir -p LightWalletCoreFFI.framework && cd LightWalletCoreFFI.framework && mkdir Headers Modules && cp ../../../../crates/core/src/LightWalletCoreFFI.modulemap ./Modules/module.modulemap && cp ../../../../crates/core/src/LightWalletCoreFFI.h ./Headers/LightWalletCoreFFI.h && cp ../$(STATIC_LIB_NAME) ./LightWalletCoreFFI
cd target/aarch64-apple-ios-sim/release && mkdir -p LightWalletCoreFFI.framework && cd LightWalletCoreFFI.framework && mkdir Headers Modules && cp ../../../../crates/core/src/LightWalletCoreFFI.modulemap ./Modules/module.modulemap && cp ../../../../crates/core/src/LightWalletCoreFFI.h ./Headers/LightWalletCoreFFI.h && cp ../$(STATIC_LIB_NAME) ./LightWalletCoreFFI
cd target/aarch64-apple-ios/release && mkdir -p LightWalletCoreFFI.framework && cd LightWalletCoreFFI.framework && mkdir Headers Modules && cp ../../../../crates/core/src/LightWalletCoreFFI.modulemap ./Modules/module.modulemap && cp ../../../../crates/core/src/LightWalletCoreFFI.h ./Headers/LightWalletCoreFFI.h && cp ../$(STATIC_LIB_NAME) ./LightWalletCoreFFI
.PHONY: xcframework
xcframework: # Temporary override for old build system
lipo -create target/x86_64-apple-ios/release/LightWalletCoreFFI.framework/LightWalletCoreFFI target/aarch64-apple-ios-sim/release/LightWalletCoreFFI.framework/LightWalletCoreFFI -output target/aarch64-apple-ios-sim/release/LightWalletCoreFFI.framework/LightWalletCoreFFI
rm -rf target/LightWalletCoreFFI.xcframework || echo "skip removing"
xcodebuild -create-xcframework -framework target/aarch64-apple-ios/release/LightWalletCoreFFI.framework -framework target/aarch64-apple-ios-sim/release/LightWalletCoreFFI.framework -output target/LightWalletCoreFFI.xcframework
##@ Cargo
.PHONY: cargo
cargo: cargo-setup ## Run cargo.
cargo build
.PHONY: cargo-clean
cargo-clean: cargo-setup ## Clean cargo.
cargo clean
.PHONY: cargo-fix
cargo-fmt: cargo-setup ## Fix cargo.
cargo +nightly fmt --all
##@ Contracts
contracts: contracts-size contracts-storage contracts-wagmi ## Runs all the contract generation scripts
.PHONY: contracts-size
contracts-size: ## Omits the current code size layout from the current contracts with foundry
./contracts/size.sh
.PHONY: contracts-storage
contracts-storage: ## Omits the current storage layout from the current contracts with foundry
./contracts/storage.sh
.PHONY: contracts-wagmi
contracts-wagmi: ## Copies over certain directory for wagmi generation
./contracts/wagmi.sh
.PHONY: contracts-snapshot
contracts-snapshot: ## Runs the snapshot generation script
forge snapshot
.PHONY: contracts-snapshot-check
contracts-snapshot-check: ## Runs the snapshot generation script w/ check
forge snapshot --check
.PHONY: contracts-slither
contracts-slither: ## Runs slither on the contracts
SOLC_VERSION=$(SOLC_VERSION) rye run slither contracts/src/ --config-file slither.config.json
.PHONY: contracts-slither-install
contracts-slither-install: ## Installs slither on the contracts w/ solc version
rye run solc-select install $(SOLC_VERSION)
.PHONY: contracts-halmos
contracts-halmos: ## Runs halmos on the contracts
rye run halmos
#@ autometrics
.PHONY: autometrics
autometrics: ## Run autometrics
am start localhost:3002
##@ Docker
.PHONY: docker
docker: ## Build the docker image.
docker build -t lightdotso .
.PHONY: docker-upgrade
docker-upgrade: ## Upgrade dependencies in the docker image.
./scripts/dockerfile_version_update.sh
##@ Docker-compose
.PHONY: docker-compose-up
docker-compose-up: ## Run the docker-compose.
docker-compose up
.PHONY: docker-compose-restart
docker-compose-restart: ## Restart the docker-compose.
docker-compose down --volumes && docker-compose up
##@ Prisma
.PHONY: cargo-generate
cargo-generate:
cargo generate
cargo fix --lib --allow-no-vcs -p lightdotso-prisma
cargo +nightly fmt
.PHONY: prisma
prisma: cargo-generate ## Add clippy ignore.
./scripts/add_recursive_flag.sh
./scripts/add_clippy_ignore.sh
##@ Ruff
.PHONY: ruff-fmt
ruff-fmt: ## Run ruff.
ruff format .
.PHONY: ruff-lint
ruff-lint: ## Run ruff.
ruff check .
##@ Rundler
.PHONY: rundler
rundler: ## Run rundler.
pnpm --filter @lightdotso/crates rundler
#@ anvil
.PHONY: anvil
anvil: ## Run anvil
anvil --block-time 3 --load-state anvil/state.json
#@ forge scripts
.PHONY: local-wallet-deploy
local-wallet-deploy: ## Deploy the contracts to local node
forge script contracts/script/LightWalletDeployer.s.sol -f http://localhost:8545 --broadcast
.PHONY: local-token-deploy
local-token-deploy: ## Deploy the mock token to local node
forge script contracts/script/test/ERC20Transfer.s.sol -f http://localhost:8545 --broadcast
#@ zellij
.PHONY: shell
shell: ## Run zellij
zellij --layout zellij.kdl a $(WORKSPACE) || zellij --layout zellij.kdl -s $(WORKSPACE)
##@ Test runs
.PHONY: test-anvil-run
test-anvil-run: ## Run the anvil for testing
anvil --block-time 3
.PHONY: test-indexer-run
test-indexer-run: ## Run the indexer test
cargo run --bin indexer -- --ws ws://localhost:8545 --rpc http://localhost:8545 --chain-id 31337