Skip to content

Commit 9e80e08

Browse files
committed
chore: add 16KB alignment check script and CI hook
1 parent 9e03cbf commit 9e80e08

3 files changed

Lines changed: 86 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ on:
33
push:
44
branches:
55
- main
6+
- master
67
pull_request:
78
branches:
89
- main
10+
- master
911
merge_group:
1012
types:
1113
- checks_requested
@@ -115,6 +117,9 @@ jobs:
115117
run: |
116118
yarn turbo run build:android --cache-dir="${{ env.TURBO_CACHE_DIR }}"
117119
120+
- name: Verify 16KB page alignment
121+
run: bash scripts/check-16kb.sh
122+
118123
build-ios:
119124
runs-on: macos-latest
120125

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"typecheck": "tsc",
4040
"lint": "eslint \"**/*.{js,ts,tsx}\"",
4141
"release": "release-it --only-version",
42+
"check:16kb": "cd example/android && ./gradlew :app:assembleRelease && cd ../.. && bash scripts/check-16kb.sh",
4243
"test": "jest"
4344
},
4445
"keywords": [

scripts/check-16kb.sh

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
readelf_cmd=""
5+
if [ "${GITHUB_ACTIONS:-}" = "true" ]; then
6+
if command -v llvm-readelf >/dev/null 2>&1; then
7+
readelf_cmd="llvm-readelf"
8+
elif command -v readelf >/dev/null 2>&1; then
9+
readelf_cmd="readelf"
10+
elif command -v greadelf >/dev/null 2>&1; then
11+
readelf_cmd="greadelf"
12+
fi
13+
else
14+
find_readelf() {
15+
local candidates=(
16+
llvm-readelf
17+
readelf
18+
greadelf
19+
/opt/homebrew/opt/llvm/bin/llvm-readelf
20+
/usr/local/opt/llvm/bin/llvm-readelf
21+
/opt/homebrew/bin/greadelf
22+
/usr/local/bin/greadelf
23+
)
24+
for candidate in "${candidates[@]}"; do
25+
if command -v "$candidate" >/dev/null 2>&1; then
26+
echo "$candidate"
27+
return 0
28+
fi
29+
if [ -x "$candidate" ]; then
30+
echo "$candidate"
31+
return 0
32+
fi
33+
done
34+
return 1
35+
}
36+
readelf_cmd="$(find_readelf || true)"
37+
fi
38+
if [ -z "$readelf_cmd" ]; then
39+
echo "ERROR: neither llvm-readelf, readelf, nor greadelf found in PATH" >&2
40+
if [ "${GITHUB_ACTIONS:-}" != "true" ]; then
41+
echo "Tip: brew install llvm (llvm-readelf) or binutils (greadelf), or export PATH to include them." >&2
42+
fi
43+
exit 1
44+
fi
45+
46+
files=()
47+
if command -v rg >/dev/null 2>&1; then
48+
rg_load_align() { rg -n "LOAD|Align"; }
49+
while IFS= read -r line; do
50+
[ -n "$line" ] && files+=("$line")
51+
done < <(rg --files -g "libfilehash-native.so" android/build example/android/build || true)
52+
else
53+
rg_load_align() { grep -n -E "LOAD|Align"; }
54+
while IFS= read -r line; do
55+
[ -n "$line" ] && files+=("$line")
56+
done < <(find android/build example/android/build -name "libfilehash-native.so" 2>/dev/null || true)
57+
fi
58+
59+
if [ "${#files[@]}" -eq 0 ]; then
60+
echo "ERROR: no libfilehash-native.so found; build Android first" >&2
61+
exit 1
62+
fi
63+
64+
for so in "${files[@]}"; do
65+
if ! "$readelf_cmd" -l "$so" | awk '
66+
$1=="LOAD" { load=1; if ($NF!="0x4000") bad=1 }
67+
END { if (!load) exit 2; exit bad }
68+
'; then
69+
status=$?
70+
if [ "$status" -eq 2 ]; then
71+
echo "ERROR: no LOAD segments found for $so" >&2
72+
else
73+
echo "ERROR: expected 16KB alignment (0x4000) for $so" >&2
74+
fi
75+
"$readelf_cmd" -l "$so" | rg_load_align || true
76+
exit 1
77+
fi
78+
done
79+
80+
echo "OK: 16KB alignment verified"

0 commit comments

Comments
 (0)