-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
317 lines (281 loc) · 13.5 KB
/
Copy pathMakefile
File metadata and controls
317 lines (281 loc) · 13.5 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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
.PHONY: build clean do-docs do-docs-ci do-lint do-lint-ci test test-feat test-all all help check release coverage coverage-check coverage-ci coverage-setup audit docs developer node-harness node-harness-lint build-wasm test-wasm build-wasi test-wasi
# Project name
PROJ_NAME := node-rs
# Build configuration
release ?=
ifdef release
release_flag := --release
target := release
else
release_flag :=
target := debug
endif
# Default target
default: build
# Build everything
all: clean build test
# Just check compilation without building
check:
cargo check
# Build the project
build:
cargo build $(release_flag)
# Clean build artifacts
clean:
cargo clean
rm -rf target/
rm -rf build/
# Generate documentation without dependencies and open it
do-docs:
cargo doc --no-deps --document-private-items --all-features --open
# Generate documentation without opening it (for CI)
do-docs-ci:
cargo doc --no-deps --document-private-items --all-features
# Lint code
do-lint: do-docs-ci node-harness-lint
cargo clippy --fix --allow-staged --allow-dirty --all-targets --all-features -- -D warnings
cargo fmt
# Lint code for CI (check only, no fixes)
do-lint-ci: node-harness-lint
cargo check --all-targets --all-features
cargo fmt --all -- --check
cargo clippy --all-targets --all-features -- -D warnings
# Test crate packages features
test-feat:
cargo test -p keetanetwork-crypto --no-default-features --features std,signature
cargo test -p keetanetwork-crypto --no-default-features --features std,encryption
cargo test -p keetanetwork-crypto --no-default-features --features std,der
cargo test -p keetanetwork-account --no-default-features --features std,der
cargo test -p keetanetwork-account --no-default-features --features std,rasn
cargo test -p keetanetwork-crypto --no-default-features --features std
cargo check -p keetanetwork-crypto --no-default-features
cargo check -p keetanetwork-crypto --no-default-features --features signature
cargo check -p keetanetwork-crypto --no-default-features --features encryption
cargo check -p keetanetwork-crypto --no-default-features --features signature,encryption,rasn
cargo test -p keetanetwork-x509 --no-default-features --features std,der
cargo test -p keetanetwork-x509 --no-default-features --features std,rasn
cargo test -p keetanetwork-x509 --no-default-features --features std,der,serde
cargo test -p keetanetwork-x509 --no-default-features --features std,rasn,serde
cargo test -p keetanetwork-asn1 --no-default-features --features std,der
cargo test -p keetanetwork-asn1 --no-default-features --features std,rasn
cargo test -p keetanetwork-asn1 --no-default-features --features std,der,serde
cargo test -p keetanetwork-asn1 --no-default-features --features std,rasn,serde
cargo test -p keetanetwork-block --no-default-features --features std,der
cargo test -p keetanetwork-block --no-default-features --features std,rasn
cargo test -p keetanetwork-block --no-default-features --features std,der,rasn
cargo test -p keetanetwork-crypto -p keetanetwork-x509 --all-features
# no_std builds (cargo check, since test harness needs std).
cargo check -p keetanetwork-error --no-default-features
cargo check -p keetanetwork-error --no-default-features --features alloc
cargo check -p keetanetwork-asn1 --no-default-features --features alloc,rasn
cargo check -p keetanetwork-asn1 --no-default-features --features alloc,der
cargo check -p keetanetwork-asn1 --no-default-features --features alloc,rasn,der
cargo check -p keetanetwork-x509 --no-default-features --features alloc,rasn
cargo check -p keetanetwork-x509 --no-default-features --features alloc,der
cargo check -p keetanetwork-x509 --no-default-features --features alloc,rasn,serde
cargo check -p keetanetwork-x509 --no-default-features --features alloc,der,serde
cargo check -p keetanetwork-account --no-default-features --features alloc,rasn
cargo check -p keetanetwork-account --no-default-features --features alloc,der
cargo check -p keetanetwork-block --no-default-features --features alloc,rasn
cargo check -p keetanetwork-block --no-default-features --features alloc,der
cargo check -p keetanetwork-block --no-default-features --features alloc,rasn,der
cargo clippy -p keetanetwork-client --no-default-features -- -D warnings
# Browser wasm build: no_std orchestrator with the relaxed (!Send) traits.
cargo build -p keetanetwork-client --no-default-features --target wasm32-unknown-unknown
cargo build -p keetanetwork-client --no-default-features --features wasm --target wasm32-unknown-unknown
build-wasm:
wasm-pack build keetanetwork-client-wasm --target web --out-dir pkg
WASI_CRATE := keetanetwork-client-wasi
WASI_P1_WASM := target/wasm32-wasip1/debug/keetanetwork_client_wasi.wasm
WASI_P2_WASM := target/wasm32-wasip2/debug/keetanetwork_client_wasi.wasm
WASI_P1_WASM_RELEASE := target/wasm32-wasip1/release/keetanetwork_client_wasi.wasm
build-wasi:
cargo build -p $(WASI_CRATE) --target wasm32-wasip1 --features p1
cargo build -p $(WASI_CRATE) --target wasm32-wasip2 --features p2
# Reference implementation harness (required by compatibility/e2e tests)
HARNESS_DIR := keetanetwork-utils/node-harness
HARNESS_SOURCES := $(wildcard $(HARNESS_DIR)/src/*.ts) $(HARNESS_DIR)/tsconfig.json
$(HARNESS_DIR)/node_modules/.package-lock.json: $(HARNESS_DIR)/package-lock.json
cd $(HARNESS_DIR) && npm ci
$(HARNESS_DIR)/dist/e2e-node.js: $(HARNESS_DIR)/node_modules/.package-lock.json $(HARNESS_SOURCES)
cd $(HARNESS_DIR) && npm run build
node-harness: $(HARNESS_DIR)/dist/e2e-node.js
node-harness-lint: node-harness
cd $(HARNESS_DIR) && npm run lint
# Run tests with host system's default target
test: node-harness
# Use a shell script to unset CARGO_BUILD_TARGET and run tests
sh -c 'unset CARGO_BUILD_TARGET; cargo test --all-features --workspace'
test-all: test test-feat
# Browser end-to-end test
WASM_TEST_DIR := keetanetwork-client-wasm/tests
test-wasm: node-harness build-wasm
wasm-pack test --node keetanetwork-client-wasm
cd $(WASM_TEST_DIR) && npm ci
cd $(WASM_TEST_DIR) && npx playwright install --with-deps chromium
cd $(WASM_TEST_DIR) && npx playwright test
test-wasi: node-harness
cargo build -p $(WASI_CRATE) --target wasm32-wasip1 --features p1 --release
cargo build -p $(WASI_CRATE) --target wasm32-wasip2 --features p2
WASI_P1_MODULE=$(CURDIR)/$(WASI_P1_WASM_RELEASE) \
WASI_P2_COMPONENT=$(CURDIR)/$(WASI_P2_WASM) \
cargo test --manifest-path $(WASI_CRATE)/host-tests/Cargo.toml -- --include-ignored
# Set up coverage tools (internal helper target)
coverage-setup:
# Install cargo-llvm-cov if not present (quiet)
@cargo install cargo-llvm-cov --quiet || true
# Install llvm-tools-preview component (force, no prompts)
@rustup component add llvm-tools-preview 2>/dev/null || true
# Generate code coverage report
coverage: coverage-setup
# Clean previous coverage data
@cargo llvm-cov clean --workspace || true
# Generate HTML coverage report
cargo llvm-cov --all-features --workspace --html --ignore-filename-regex 'build\.rs'
# Generate LCOV coverage report (reusing the same coverage data)
cargo llvm-cov report --lcov --output-path coverage.lcov --ignore-filename-regex 'build\.rs'
# Open HTML report in browser (macOS) if it exists
@if [ -f target/llvm-cov/html/index.html ]; then \
open target/llvm-cov/html/index.html; \
else \
echo "HTML report not found at target/llvm-cov/html/index.html"; \
echo "Trying alternative location..."; \
find target -name "index.html" -path "*/llvm-cov/*" 2>/dev/null | head -1 | xargs open || echo "No HTML report found"; \
fi
# Check coverage percentage and fail if below threshold
coverage-check: coverage-setup
# Generate coverage and check threshold
@echo "Generating coverage report..."
@cargo llvm-cov --all-features --workspace --summary-only > coverage_summary.txt 2>&1
@COVERAGE=$$(grep "TOTAL" coverage_summary.txt | grep -oE '[0-9]+\.[0-9]+%' | tail -1 | sed 's/%//'); \
THRESHOLD=90.0; \
if [ -z "$$COVERAGE" ]; then \
echo "ERROR: Could not extract total coverage percentage"; \
cat coverage_summary.txt; \
rm -f coverage_summary.txt; \
exit 1; \
fi; \
echo "Current coverage: $${COVERAGE}%"; \
echo "Minimum threshold: $${THRESHOLD}%"; \
if [ $$(echo "$${COVERAGE} < $${THRESHOLD}" | bc -l) -eq 1 ]; then \
echo "FAIL: Coverage $${COVERAGE}% is below threshold $${THRESHOLD}%"; \
rm -f coverage_summary.txt; \
exit 1; \
else \
echo "PASS: Coverage $${COVERAGE}% meets threshold $${THRESHOLD}%"; \
rm -f coverage_summary.txt; \
fi
# Generate coverage report for CI (LCOV format for SonarCloud)
coverage-ci: coverage-setup
# Generate LCOV coverage report for CI/SonarCloud
cargo llvm-cov --all-features --workspace --lcov --output-path coverage.lcov
# Run security audit
audit:
cargo audit
# Generate and open documentation
docs:
cargo doc --no-deps --document-private-items --all-features --open
# Developer setup - install Rust and set up development environment
developer:
@echo "Setting up development environment..."
@if command -v rustc > /dev/null 2>&1; then \
echo "Rust is already installed (version: $$(rustc --version))"; \
else \
echo "Installing Rust via rustup (automated)..."; \
if [ -f scripts/rustup-init.sh ]; then \
chmod +x scripts/rustup-init.sh; \
./scripts/rustup-init.sh -y --default-toolchain stable; \
echo "Rust installed! Sourcing environment..."; \
. "$$HOME/.cargo/env" 2>/dev/null || true; \
else \
echo "ERROR: scripts/rustup-init.sh not found in project root."; \
echo " Please download it from: https://sh.rustup.rs/"; \
exit 1; \
fi; \
fi
@echo "Setting up development tools..."
@if command -v rustc > /dev/null 2>&1; then \
echo "Rust version: $$(rustc --version)"; \
echo "Cargo version: $$(cargo --version)"; \
echo "Installing development tools..."; \
$(MAKE) coverage-setup; \
cargo install cargo-audit --locked --quiet || echo "WARNING: cargo-audit installation failed or already installed"; \
echo "Installing script dependencies..."; \
if ! command -v jq > /dev/null 2>&1; then \
echo "Installing jq..."; \
if command -v brew > /dev/null 2>&1; then \
brew install jq; \
else \
echo "WARNING: Please install jq manually: https://stedolan.github.io/jq/download/"; \
fi; \
else \
echo "jq is already installed"; \
fi; \
if ! command -v curl > /dev/null 2>&1; then \
echo "Installing curl..."; \
if command -v brew > /dev/null 2>&1; then \
brew install curl; \
else \
echo "WARNING: Please install curl manually"; \
fi; \
else \
echo "curl is already installed"; \
fi; \
echo "Running initial build and test..."; \
$(MAKE) check; \
$(MAKE) test; \
echo ""; \
echo "Development environment setup complete!"; \
else \
echo "WARNING: Rust installation completed but not available in current shell."; \
echo "Please restart your shell or run:"; \
echo " source $$HOME/.cargo/env"; \
echo " make developer"; \
fi
$(MAKE) help
# Publish packages and create release
# Optionally restrict to specific crates: make release PKG="keetanetwork-asn1"
# Bypass the clean-tree check (and cargo publish dirty guard): make release DIRTY=1
# Skip the test suite (lints still run): make release SKIP_TESTS=1
release:
@echo "Running release script..."
@./scripts/release.sh $(filter-out $@,$(MAKECMDGOALS)) $(if $(DIRTY),--allow-dirty) $(if $(SKIP_TESTS),--skip-tests) $(PKG)
# Allow flags to be passed as fake targets
--%:
@:
# Help information
help:
@echo "Makefile"
@echo "=================================="
@echo "Developer commands:"
@echo " make - Build in debug mode"
@echo " make help - Show this help message"
@echo " make developer - Set up development environment (install Rust, tools, etc.)"
@echo " make build - Build in debug mode"
@echo " make build release=1 - Build in release mode"
@echo " make clean - Clean build artifacts"
@echo " make check - Check compilation without building"
@echo " make do-docs - Generate and open documentation"
@echo " make do-lint - Lint code with clippy and format (with fixes)"
@echo " make test - Run tests (includes all crypto feature combinations)"
@echo " make test-feat - Run crypto crate tests with specific features"
@echo " make test-all - Run all tests including feature tests"
@echo " make build-wasi - Build the WASI P1 core module and P2 component (debug)"
@echo " make test-wasi - Build WASI artifacts (release P1) and run the host tests (P1 flat ABI + P2 networked over wasi:http)"
@echo " make audit - Run security audit"
@echo " make docs - Generate and open documentation"
@echo " make coverage - Generate code coverage report (HTML + LCOV)"
@echo " make coverage-check - Check coverage percentage and fail if below threshold"
@echo " make all - Clean, build, and test"
@echo ""
@echo "CI Commands:"
@echo " make do-lint-ci - Lint code for CI (check only, no fixes)"
@echo " make do-docs-ci - Generate documentation without opening it"
@echo " make coverage-ci - Generate LCOV coverage report for CI/SonarCloud"
@echo ""
@echo "Release Commands:"
@echo " make release - Publish all packages to crates.io and create signed release tag"
@echo " make release PKG=\"crate-a crate-b\" - Publish only the named crates (skips workspace tag)"
@echo " make release DIRTY=1 - Allow publishing with a dirty working tree"
@echo " make release SKIP_TESTS=1 - Skip the test suite (lints still run)"
@echo " make release --dry-run - Preview the release without publishing"