Files
ICCery-CPU/Scripts/select_xcode.sh
T
Local Admin 23995f18e5
Build macOS Packages / Build macOS (Apple Silicon) (push) Failing after 2m1s
Build macOS Packages / Build macOS (Intel) (push) Failing after 2m6s
Build macOS Packages / Build macOS (Universal) (push) Skipped
fix build sxriots for command line xcode
2026-09-07 05:36:51 -07:00

93 lines
2.7 KiB
Bash

#!/bin/bash
# Locate a compiler for TargetPrint.
#
# Full Xcode.app is preferred (xcodebuild). If it is missing — the usual Gitea
# macos runner state, with xcode-select pointed at Command Line Tools — we
# fall back to CLT `swiftc` + the macOS SDK, which is enough to produce
# TargetPrint.app.
set -euo pipefail
github_env() {
local key="$1" val="$2"
echo "$key=$val"
if [ -n "${GITHUB_ENV:-}" ]; then
echo "$key=$val" >> "$GITHUB_ENV"
fi
eval "export $key=\"\$val\""
}
echo "==> Toolchain probe"
echo " xcode-select -p: $(xcode-select -p 2>/dev/null || echo unset)"
echo " /Applications:"
ls -1 /Applications 2>/dev/null | sed 's/^/ /' || echo " (unreadable)"
shopt -s nullglob
candidates=()
[ -n "${XCODE_APP:-}" ] && candidates+=("$XCODE_APP")
candidates+=(
/Applications/Xcode.app
/Applications/Xcode-beta.app
/Applications/Xcode_*.app
/Applications/Xcode-*.app
)
resolve_app() {
local c="$1"
[ -n "$c" ] || return 1
if [ -x "$c/Contents/Developer/usr/bin/xcodebuild" ]; then
echo "$c"
return 0
fi
return 1
}
pick=""
for c in "${candidates[@]}"; do
if app="$(resolve_app "$c")"; then
pick="$app"
break
fi
done
if [ -n "$pick" ]; then
DEV="$pick/Contents/Developer"
echo "==> Full Xcode at $pick"
github_env HAS_FULL_XCODE 1
github_env DEVELOPER_DIR "$DEV"
github_env XCODEBUILD "$DEV/usr/bin/xcodebuild"
if command -v sudo >/dev/null 2>&1 && sudo -n true 2>/dev/null; then
sudo xcode-select -s "$DEV" || true
sudo "$DEV/usr/bin/xcodebuild" -license accept >/dev/null 2>&1 || true
sudo "$DEV/usr/bin/xcodebuild" -runFirstLaunch >/dev/null 2>&1 || true
fi
"$DEV/usr/bin/xcodebuild" -version || true
else
echo "==> No Xcode.app (this is why 'xcode-select -s /Applications/Xcode.app/...' fails)."
echo " Building with Command Line Tools swiftc + macOS SDK."
github_env HAS_FULL_XCODE 0
github_env XCODEBUILD ""
CLT="/Library/Developer/CommandLineTools"
if [ -d "$CLT" ]; then
github_env DEVELOPER_DIR "$CLT"
fi
fi
if ! SDKROOT_VAL="$(xcrun --sdk macosx --show-sdk-path 2>/dev/null)"; then
echo "No macOS SDK via xcrun. Install Command Line Tools:"
echo " xcode-select --install"
exit 1
fi
github_env SDKROOT "$SDKROOT_VAL"
if ! SWIFT_VAL="$(xcrun --find swiftc 2>/dev/null)"; then
echo "swiftc not found."
exit 1
fi
github_env SWIFT "$SWIFT_VAL"
echo " HAS_FULL_XCODE=${HAS_FULL_XCODE}"
echo " SDKROOT=${SDKROOT}"
echo " SWIFT=${SWIFT} ($("$SWIFT" --version 2>/dev/null | head -n 1))"
echo " sw_vers: $(sw_vers -productName) $(sw_vers -productVersion)"
echo " uname -m: $(uname -m)"