Decouple non-Mac builds from Xcode dependency (#6316)

* Decouple non-Mac builds from Xcode via BAZEL_NO_APPLE_CPP_TOOLCHAIN

Set BAZEL_NO_APPLE_CPP_TOOLCHAIN=1 in .bazelrc so apple_support skips
Xcode detection (xcode-locator) entirely for Scala/C++/Go builds.
Only mactools builds (Mac/Sparkle) re-enable the Apple CC toolchain.

This means Xcode version changes no longer affect Eagle, Shardok, test,
auth, docker, or Unity Windows builds — no expunge, no cache invalidation,
no rebuild. The sync script and its expunge/cache-key logic are now scoped
to mactools only and removed from all non-Mac CI workflows.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Revert BAZEL_NO_APPLE_CPP_TOOLCHAIN; keep Apple CC with stable environ

BAZEL_NO_APPLE_CPP_TOOLCHAIN=1 broke builds because apple_support
registers platforms (e.g. macos_x86_64) that require Apple CC toolchains
for resolution — even in non-Mac builds.

Instead, keep Apple CC enabled but ensure its repo rule never
re-evaluates on non-Mac builds by keeping DEVELOPER_DIR pinned in
common:macos. The sync script only runs for mactools builds and
overrides DEVELOPER_DIR there.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-27 16:08:28 -08:00
committed by GitHub
co-authored by Claude Opus 4.6
parent e8780134ee
commit 79c5be3a54
10 changed files with 35 additions and 225 deletions
+26 -14
View File
@@ -1,12 +1,16 @@
#!/usr/bin/env bash
# Keeps Bazel in sync with the installed Xcode version. Two mechanisms:
# Keeps Bazel mactools builds in sync with the installed Xcode version.
#
# 1. Writes .bazelrc.xcode with --action_env=XCODE_BUILD_VERSION=<version>
# so the version is part of every action's cache key. This prevents stale
# remote cache entries from being reused after an Xcode update.
# Only needed on runners that do mactools builds (Mac/Sparkle). Non-Mac builds
# don't run this script; their apple_cc_autoconf stays cached because none of
# its environ vars change, so they're unaffected by Xcode version changes.
#
# 1. Writes .bazelrc.xcode with mactools-scoped flags:
# - action_env for remote cache key invalidation
# - DEVELOPER_DIR pointing to the active Xcode
#
# 2. Runs `bazel clean --expunge` when the version actually changes, because
# local_config_xcode (a cached repository rule) bakes in the old version
# local_config_apple_cc (a cached repository rule) bakes in the old version
# and can only be refreshed by clearing the output base.
#
# .bazelrc imports the generated file via: try-import %workspace%/.bazelrc.xcode
@@ -20,23 +24,31 @@ if [ -z "$XCODE_BUILD_VERSION" ]; then
exit 0
fi
BAZELRC_XCODE=".bazelrc.xcode"
EXPECTED="common --action_env=XCODE_BUILD_VERSION=${XCODE_BUILD_VERSION}"
DEVELOPER_DIR=$(xcode-select -p 2>/dev/null)
# If the file already has the right version, nothing to do
if [ -f "$BAZELRC_XCODE" ] && [ "$(cat "$BAZELRC_XCODE")" = "$EXPECTED" ]; then
exit 0
BAZELRC_XCODE=".bazelrc.xcode"
EXPECTED_LINE="common:mactools --action_env=XCODE_BUILD_VERSION=${XCODE_BUILD_VERSION}"
# Check if the file already has the right version (first line is the version marker)
if [ -f "$BAZELRC_XCODE" ]; then
CURRENT_FIRST_LINE=$(head -1 "$BAZELRC_XCODE")
if [ "$CURRENT_FIRST_LINE" = "$EXPECTED_LINE" ]; then
exit 0
fi
fi
# Xcode version changed (or first run) — expunge local cache to clear
# stale local_config_xcode, then write the new version for remote cache keys
# stale local_config_apple_cc, then write the new config
OLD_VERSION="unknown"
if [ -f "$BAZELRC_XCODE" ]; then
OLD_VERSION=$(sed -n 's/.*XCODE_BUILD_VERSION=//p' "$BAZELRC_XCODE")
OLD_VERSION=$(sed -n 's/.*XCODE_BUILD_VERSION=//p' "$BAZELRC_XCODE" | head -1)
fi
echo "Xcode build version changed: ${OLD_VERSION} -> ${XCODE_BUILD_VERSION}"
echo "Running bazel clean --expunge to clear stale toolchain config..."
bazel clean --expunge 2>/dev/null || true
echo "$EXPECTED" > "$BAZELRC_XCODE"
echo "Updated ${BAZELRC_XCODE} — next build will do a full rebuild with Xcode ${XCODE_BUILD_VERSION}"
cat > "$BAZELRC_XCODE" << EOF
${EXPECTED_LINE}
common:mactools --repo_env=DEVELOPER_DIR=${DEVELOPER_DIR}
EOF
echo "Updated ${BAZELRC_XCODE} — next mactools build will rebuild with Xcode ${XCODE_BUILD_VERSION}"