forked from Lilly-Protocol/lily-contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck-wasm-sizes.sh
More file actions
executable file
·63 lines (49 loc) · 1.78 KB
/
Copy pathcheck-wasm-sizes.sh
File metadata and controls
executable file
·63 lines (49 loc) · 1.78 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
#!/usr/bin/env sh
set -eu
BASELINE_FILE="${BASELINE_FILE:-wasm-size-baseline.json}"
ARTIFACTS_DIR="${ARTIFACTS_DIR:-dist}"
WASM_DIR="${WASM_DIR:-target/wasm32v1-none/release}"
if [ ! -f "$BASELINE_FILE" ]; then
echo "Error: baseline file '$BASELINE_FILE' not found." >&2
exit 1
fi
packages="protocol identity wallet payments"
has_failure=0
printf "%-12s | %-12s | %-12s | %-12s | %-10s\n" "Contract" "Actual (B)" "Baseline (B)" "Max Limit" "Status"
printf -- "-------------+--------------+--------------+--------------+-----------\n"
for pkg in $packages; do
wasm_path=""
if [ -f "${ARTIFACTS_DIR}/${pkg}.wasm" ]; then
wasm_path="${ARTIFACTS_DIR}/${pkg}.wasm"
elif [ -f "${WASM_DIR}/${pkg}.wasm" ]; then
wasm_path="${WASM_DIR}/${pkg}.wasm"
fi
if [ -z "$wasm_path" ] || [ ! -f "$wasm_path" ]; then
printf "%-12s | %-12s | %-12s | %-12s | %-10s\n" "$pkg" "NOT FOUND" "-" "-" "FAIL"
has_failure=1
continue
fi
actual_size=$(wc -c < "$wasm_path" | tr -d ' ')
# Extract baseline and max limit from json
max_limit=$(grep -A 3 "\"$pkg\":" "$BASELINE_FILE" | grep '"max_limit_bytes":' | tr -dc '0-9')
baseline=$(grep -A 3 "\"$pkg\":" "$BASELINE_FILE" | grep '"baseline_bytes":' | tr -dc '0-9')
if [ -z "$max_limit" ]; then
max_limit=131072
fi
if [ -z "$baseline" ]; then
baseline=65536
fi
if [ "$actual_size" -gt "$max_limit" ]; then
status="EXCEEDED"
has_failure=1
else
status="OK"
fi
printf "%-12s | %-12s | %-12s | %-12s | %-10s\n" "$pkg" "$actual_size" "$baseline" "$max_limit" "$status"
done
printf -- "-------------+--------------+--------------+--------------+-----------\n"
if [ "$has_failure" -ne 0 ]; then
echo "Error: Wasm size regression gate failed." >&2
exit 1
fi
echo "All Wasm artifacts are within size thresholds."