#!/bin/bash
# check-mobile-targets: cross-check synckit-client for the Apple targets.
#
# Why this exists: synckit-client compiled cleanly on every host we build on
# while being entirely unbuildable for iOS, because nothing ever pointed a
# compiler at an iOS target. Two separate breaks hid behind that (the Apple
# store crate hard-errors on iOS without its `protected` feature, and keyring's
# store installer is cfg'd out on iOS), and both were found by reading, not by
# building. Run this after touching keystore.rs, the `keychain` feature, or any
# keyring-family dependency.
#
# Runs anywhere with rustup, Linux included: `cargo check` does not link, and
# these feature sets pull in no C code.
#
# Not covered here, and still mbp-only:
#   - the `store` feature, whose bundled SQLite needs the Apple SDK (xcrun)
#   - linking, code signing, and anything on-device
set -euo pipefail

cd "$(dirname "$0")/.."

TARGETS=(aarch64-apple-ios aarch64-apple-darwin)
# `store` is excluded deliberately: bundled libsqlite3-sys shells out to xcrun.
FEATURES="keychain"

for target in "${TARGETS[@]}"; do
    if ! rustup target list --installed | grep -qx "$target"; then
        echo "==> installing target $target"
        rustup target add "$target"
    fi
    echo "==> cargo check --target $target --features $FEATURES"
    cargo check \
        --manifest-path synckit-client/Cargo.toml \
        --target "$target" \
        --no-default-features \
        --features "$FEATURES"
done

echo "==> Apple targets check clean."
