32 lines
1.4 KiB
Bash
Executable file
32 lines
1.4 KiB
Bash
Executable file
#!/bin/sh
|
|
# Check the Android libraries `zig build android` produced will load on a device.
|
|
#
|
|
# android/audit-libs.sh [zig-out/android]
|
|
#
|
|
# libtally.so is linked against nothing (design 6.2): no libc, no NDK. So every symbol it
|
|
# references has to be one it defines, it may not have a TLS segment (only Bionic can
|
|
# satisfy `__tls_get_addr`), and it may not name a library it needs. Each of those
|
|
# links on a desktop and fails in `dlopen` on a phone, before any code here runs - which
|
|
# is how the first build failed, and why this runs on every build rather than once.
|
|
set -eu
|
|
|
|
dir="${1:-zig-out/android}"
|
|
fail=0
|
|
for abi in arm64-v8a x86_64 armeabi-v7a; do
|
|
lib="$dir/$abi/libtally.so"
|
|
if [ ! -f "$lib" ]; then
|
|
echo "$abi: missing $lib"
|
|
fail=1
|
|
continue
|
|
fi
|
|
undefined="$(readelf --dyn-syms -W "$lib" | awk '$7 == "UND" && $8 != ""' | wc -l)"
|
|
tls="$(readelf -l -W "$lib" | grep -c ' TLS ' || true)"
|
|
needed="$(readelf -d "$lib" | grep -c NEEDED || true)"
|
|
exports="$(readelf --dyn-syms -W "$lib" | grep -c 'Java_dev_lerch_tally_TallyEngine_' || true)"
|
|
printf '%-12s undefined=%s tls=%s needed=%s jni-exports=%s\n' "$abi" "$undefined" "$tls" "$needed" "$exports"
|
|
if [ "$undefined" -ne 0 ] || [ "$tls" -ne 0 ] || [ "$needed" -ne 0 ] || [ "$exports" -eq 0 ]; then
|
|
fail=1
|
|
fi
|
|
done
|
|
[ "$fail" -eq 0 ] && echo "all Android libraries are self-contained"
|
|
exit "$fail"
|