forked from iotaledger/iota-rust-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
261 lines (215 loc) · 9.57 KB
/
Makefile
File metadata and controls
261 lines (215 loc) · 9.57 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
# Set the default target of this Makefile
.PHONY: all
all:: ci ## Default target, runs the CI process
.PHONY: check-features
check-features: ## Check feature flags for crates
$(MAKE) -C crates/iota-sdk-types check-features
$(MAKE) -C crates/iota-sdk-crypto check-features
.PHONY: check-fmt
check-fmt: ## Check code formatting
cargo +nightly fmt -- --check
.PHONY: fmt
fmt: ## Format code
cargo +nightly fmt
.PHONY: clippy
clippy: ## Run Clippy linter
cargo clippy --all-features --all-targets
.PHONY: test
test: ## Run unit tests
cargo nextest run --all-features -p iota-sdk-types -p iota-sdk-crypto
.PHONY: test-docs
test-docs: ## Run doc tests
cargo test --all-features --doc
.PHONY: build-docs
build-docs: ## Build docs
cargo doc --all-features --workspace --no-deps
package_%.json: crates/iota-sdk-transaction-builder/tests/%/Move.toml crates/iota-sdk-transaction-builder/tests/%/sources/*.move ## Generate JSON files for tests
cd crates/iota-sdk-transaction-builder/tests/$(*F) && iota move build --ignore-chain --dump-bytecode-as-base64 > ../../$@
.PHONY: test-with-localnet
test-with-localnet: package_test_example_v1.json package_test_example_v2.json ## Run tests with localnet
cargo nextest run -p iota-sdk-graphql-client -p iota-sdk-transaction-builder
.PHONY: wasm
wasm: ## Build WASM modules
$(MAKE) -C crates/iota-sdk wasm
$(MAKE) -C crates/iota-sdk-crypto wasm
$(MAKE) -C crates/iota-sdk-graphql-client wasm
$(MAKE) -C crates/iota-sdk-transaction-builder wasm
$(MAKE) -C crates/iota-sdk-types wasm
.PHONY: doc
doc: ## Generate documentation
RUSTDOCFLAGS="-Dwarnings --cfg=doc_cfg -Zunstable-options --generate-link-to-definition" RUSTC_BOOTSTRAP=1 cargo doc --all-features --no-deps
.PHONY: doc-open
doc-open: ## Generate and open documentation
RUSTDOCFLAGS="--cfg=doc_cfg -Zunstable-options --generate-link-to-definition" RUSTC_BOOTSTRAP=1 cargo doc --all-features --no-deps --open
.PHONY: is-dirty
is-dirty: ## Checks if repository is dirty
@(test -z "$$(git diff)" || (git diff && false)) && (test -z "$$(git status --porcelain)" || (git status --porcelain && false))
.PHONY: ci
ci: check-features check-fmt test wasm ## Run the full CI process
.PHONY: ci-full
ci-full: ci doc ## Run the full CI process and generate documentation
.PHONY: clean
clean: ## Clean build artifacts
cargo clean
.PHONY: clean-all
clean-all: clean ## Clean all generated files, including those ignored by Git. Force removal.
git clean -dXf
.PHONY: bindings
bindings: ## Build all bindings
@$(MAKE) go
@$(MAKE) kotlin
@$(MAKE) python
.PHONY: bindings-example
bindings-example: ## Run a specific example for all bindings. Usage: make bindings-example example
@$(MAKE) go-example $(word 2,$(MAKECMDGOALS))
@$(MAKE) kotlin-example $(word 2,$(MAKECMDGOALS))
@$(MAKE) python-example $(word 2,$(MAKECMDGOALS))
.PHONY: bindings-examples
bindings-examples: ## Run all bindings examples
@$(MAKE) go-examples
@$(MAKE) kotlin-examples
@$(MAKE) python-examples
.PHONY: bindings-examples-format-check
bindings-examples-format-check: ## Check format of all bindings examples
@$(MAKE) go-examples-format-check
@$(MAKE) kotlin-examples-format-check
@$(MAKE) python-examples-format-check
.PHONY: bindings-examples-format
bindings-examples-format: ## Format all bindings examples
@$(MAKE) go-examples-format
@$(MAKE) kotlin-examples-format
@$(MAKE) python-examples-format
# Build ffi crate and detect platform
define build_binding
cargo build -p iota-sdk-ffi --lib --release; \
case "$$(uname -s)" in \
Darwin) LIB_EXT=".dylib" ;; \
Linux) LIB_EXT=".so" ;; \
MINGW*|MSYS*|CYGWIN*|Windows_NT) LIB_EXT=".dll" ;; \
*) echo "Unsupported platform"; exit 1 ;; \
esac;
endef
.PHONY: go
go: ## Build Go bindings
@printf "Building Go bindings...\n"
@$(build_binding) \
uniffi-bindgen-go --library target/release/libiota_sdk_ffi$${LIB_EXT} --out-dir bindings/go --no-format --config bindings/go/uniffi.toml || exit $$?
@# TODO: For some reason only the .h file is renamed, not the .go file
@mv bindings/go/iota_sdk/iota_sdk_ffi.go bindings/go/iota_sdk/iota_sdk.go
@sed -i.bak "s/^package iota_sdk_ffi$$/package iota_sdk/" bindings/go/iota_sdk/iota_sdk.go && rm bindings/go/iota_sdk/iota_sdk.go.bak
.PHONY: kotlin
kotlin: ## Build Kotlin bindings
@printf "Building Kotlin bindings...\n"
@$(build_binding) \
cargo run --bin uniffi-bindgen -- generate --library "target/release/libiota_sdk_ffi$${LIB_EXT}" --language kotlin --out-dir bindings/kotlin/lib --no-format -c bindings/kotlin/uniffi.toml || exit $$?; \
cp target/release/libiota_sdk_ffi$${LIB_EXT} bindings/kotlin/lib/
@python3 bindings/kotlin/split_uniffi_interface.py --batch-size 500 || exit $$?
@mv bindings/kotlin/lib/iota_sdk/iota_sdk_ffi.kt bindings/kotlin/lib/iota_sdk/iota_sdk.kt
.PHONY: python
python: ## Build Python bindings
@printf "Building Python bindings...\n"
@$(build_binding) \
cargo run --bin uniffi-bindgen -- generate --library "target/release/libiota_sdk_ffi$${LIB_EXT}" --language python --out-dir bindings/python/lib --no-format || exit $$?; \
cp target/release/libiota_sdk_ffi$${LIB_EXT} bindings/python/lib/
@mv bindings/python/lib/iota_sdk_ffi.py bindings/python/lib/iota_sdk.py
.PHONY: go-example
go-example: ## Run a specific Go example. Usage: make go-example example
%:
@true
go-example:
@printf "\nRunning Go example \"$(word 2,$(MAKECMDGOALS))\"\n"
@cd bindings/go/examples; \
LD_LIBRARY_PATH="../../../target/release" CGO_LDFLAGS="-liota_sdk_ffi -L../../../target/release" go run $(word 2,$(MAKECMDGOALS))/main.go || exit $$?; \
cd -
.PHONY: go-examples
go-examples: ## Run all Go bindings examples
@for example in $$(find bindings/go/examples/* -type d -not -name release -exec basename {} \;); do \
$(MAKE) go-example "$$example" || exit $$?; \
done
.PHONY: go-examples-format-check
go-examples-format-check: ## Check format of all Go bindings examples
@test -z "$$(find bindings/go/examples -name "*.go" -exec gofmt -l {} \;)"
.PHONY: go-examples-format
go-examples-format: ## Format all Go bindings examples
@find bindings/go/examples -name "*.go" -exec gofmt -w {} \;
.PHONY: kotlin-example
kotlin-example: ## Run a specific Kotlin example. Usage: make kotlin-example example
%:
@true
kotlin-example:
@printf "\nRunning Kotlin example \"$(word 2,$(MAKECMDGOALS))\"\n"
@cd bindings/kotlin; \
./gradlew build clean || exit $$?; \
LD_LIBRARY_PATH=./lib ./gradlew example -Pexample=$(word 2,$(MAKECMDGOALS)) -q || exit $$?; \
cd -
.PHONY: kotlin-examples
kotlin-examples: ## Run all Kotlin bindings examples
@for example in $$(find bindings/kotlin/examples -name "*.kt" -not -path "*/release/*" -exec basename {} .kt \;); do \
$(MAKE) kotlin-example "$$example" || exit $$?; \
done
.PHONY: kotlin-examples-format-check
kotlin-examples-format-check: ## Check format of all Kotlin bindings examples
cd bindings/kotlin; \
./gradlew KtfmtCheck || exit $$?; \
cd -
.PHONY: kotlin-examples-format
kotlin-examples-format: ## Format all Kotlin bindings examples
cd bindings/kotlin; \
./gradlew KtfmtFormat; \
cd -
.PHONY: python-example
python-example: ## Run a specific Python example. Usage: make python-example example
%:
@true
python-example:
@printf "\nRunning Python example \"$(word 2,$(MAKECMDGOALS))\"\n"
@PYTHONPATH=bindings/python python3 bindings/python/examples/$(word 2,$(MAKECMDGOALS)).py|| exit $$?;
.PHONY: python-examples
python-examples: ## Run all Python bindings examples
@for example in $$(find bindings/python/examples -name "*.py" -not -path "*/release/*" -exec basename {} .py \;); do \
$(MAKE) python-example "$$example" || exit $$?; \
done
.PHONY: python-examples-format-check
python-examples-format-check: ## Check format of all Python bindings examples
@yapf --style google -d $$(find bindings/python/examples -name "*.py") --recursive
.PHONY: python-examples-format
python-examples-format: ## Format all Python bindings examples
@yapf --style google -i $$(find bindings/python/examples -name "*.py") --recursive
.PHONY: example
example: ## Run a specific Rust example. Usage: make example example
%:
@true
example:
@printf "\nRunning Rust example \"$(word 2,$(MAKECMDGOALS))\"\n"
@cargo run --example $(word 2,$(MAKECMDGOALS)) || exit $$?;
.PHONY: examples
examples: ## Run all Rust examples
@for example in $$(find crates/iota-sdk/examples -name "*.rs" -not -path "*/release/*" -exec basename {} .rs \;); do \
$(MAKE) example "$$example" || exit $$?; \
done
.PHONY: rust-release-example
rust-release-example: ## Run the Rust release example
@printf "\nRunning Rust release example\n"
@cd crates/iota-sdk/examples/release && cargo run || exit $$?
.PHONY: go-release-example
go-release-example: ## Run the Go release example
@printf "\nRunning Go release example\n"
@cd bindings/go/examples/release && go get github.com/iotaledger/iota-sdk-go && go run main.go || exit $$?
.PHONY: kotlin-release-example
kotlin-release-example: ## Run the Kotlin release example
@printf "\nRunning Kotlin release example\n"
@cd bindings/kotlin/examples/release && gradle run || exit $$?
.PHONY: python-release-example
python-release-example: ## Run the Python release example
@printf "\nRunning Python release example\n"
@cd bindings/python/examples/release && python3 -m venv .venv && . .venv/bin/activate && pip install --pre --upgrade -r requirements.txt && python example.py || exit $$?;
.PHONY: release-examples
release-examples: ## Run all release examples
@$(MAKE) rust-release-example
@$(MAKE) go-release-example
@$(MAKE) kotlin-release-example
@$(MAKE) python-release-example
.PHONY: help
help: ## Show this help
@printf "Available targets:\n"
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)