109/109 host tests pass; tests/cross_compile.sh's first real tuple
(`android | examples/ffi-objc-call-10-os-gate.sx`) compiles
through `sx build --target android` without finding any
`@objc_msgSend` / `@sel_registerName` symbols in the output —
the `inline if OS == .ios { #objc_call(...) }` arm is stripped
at sx compile time before emit_llvm runs, so the Android
toolchain (Bionic + libGLESv3 / NDK linker) doesn't see the
Obj-C runtime references that would otherwise be undefined.
Host (macOS): the example prints "host stripped both" — the iOS
arm is stripped (we're not iOS) AND the Android arm is stripped
(we're not Android), confirming `inline if OS == { case }`
symmetric strip-and-render works around `#objc_call` sites.
The example carries a 3-line `android_main` trampoline so the
NDK linker's `-u ANativeActivity_onCreate` / entry-point
discovery is satisfied — pattern shared with chess + the other
android examples.
81 lines
2.4 KiB
Bash
Executable File
81 lines
2.4 KiB
Bash
Executable File
#!/bin/bash
|
|
# Cross-compile regression runner.
|
|
#
|
|
# For each (target, example) tuple, runs `./sx build --target <t> <example>`
|
|
# and asserts (a) exit 0 and (b) the expected output file was produced.
|
|
# Compile correctness only — these examples can't be executed on the host
|
|
# (iOS Obj-C runtime / Android NDK).
|
|
#
|
|
# Tuple list starts empty and grows as Phase 0 / 1 / 2 / 3 of the FFI plan
|
|
# add cross-only examples. Skips with a warning (still exits 0) when the
|
|
# required toolchain isn't installed, so contributors without the iOS SDK
|
|
# or Android NDK aren't blocked.
|
|
#
|
|
# Usage: ./tests/cross_compile.sh
|
|
|
|
set -uo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
ROOT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
|
|
SX="$ROOT_DIR/zig-out/bin/sx"
|
|
TMP_DIR="${TMPDIR:-/tmp}/sx-cross-compile"
|
|
mkdir -p "$TMP_DIR"
|
|
|
|
# Tuple format: "<target>|<example_path>"
|
|
# Add entries as cross-only examples land. Verifies the example
|
|
# compiles cleanly for the target's NDK / SDK without needing the
|
|
# host to actually run it.
|
|
TUPLES=(
|
|
"android|examples/ffi-objc-call-10-os-gate.sx"
|
|
)
|
|
|
|
PASS=0
|
|
FAIL=0
|
|
SKIP=0
|
|
|
|
toolchain_available() {
|
|
local target="$1"
|
|
case "$target" in
|
|
ios|ios-sim)
|
|
xcrun --sdk iphonesimulator --show-sdk-path >/dev/null 2>&1
|
|
;;
|
|
android|android-arm64)
|
|
# discoverAndroidNdk in target.zig accepts $ANDROID_NDK_HOME,
|
|
# $ANDROID_NDK_ROOT, or a scan of $HOME/Library/Android/sdk/ndk.
|
|
[[ -n "${ANDROID_NDK_HOME:-}" || -n "${ANDROID_NDK_ROOT:-}" ]] \
|
|
|| [[ -d "$HOME/Library/Android/sdk/ndk" ]]
|
|
;;
|
|
*)
|
|
return 1
|
|
;;
|
|
esac
|
|
}
|
|
|
|
for tuple in "${TUPLES[@]:-}"; do
|
|
[[ -z "$tuple" ]] && continue
|
|
target="${tuple%%|*}"
|
|
example="${tuple#*|}"
|
|
label="$target / $(basename "$example" .sx)"
|
|
|
|
if ! toolchain_available "$target"; then
|
|
SKIP=$((SKIP + 1))
|
|
printf " %-50s SKIP (no toolchain)\n" "$label"
|
|
continue
|
|
fi
|
|
|
|
out_obj="$TMP_DIR/$(basename "$example" .sx).$target.o"
|
|
printf " %-50s" "$label"
|
|
"$SX" build --target "$target" -o "$out_obj" "$ROOT_DIR/$example" >/dev/null 2>&1
|
|
rc=$?
|
|
if [[ $rc -eq 0 && -s "$out_obj" ]]; then
|
|
PASS=$((PASS + 1))
|
|
echo "ok"
|
|
else
|
|
FAIL=$((FAIL + 1))
|
|
echo "FAIL (exit=$rc, output=$out_obj)"
|
|
fi
|
|
done
|
|
|
|
echo "$PASS passed, $FAIL failed, $SKIP skipped"
|
|
[[ $FAIL -eq 0 ]]
|