diff --git a/.bazelrc b/.bazelrc index 72be189391..7697892ba1 100644 --- a/.bazelrc +++ b/.bazelrc @@ -41,9 +41,8 @@ common:macos --host_linkopt=-Wl,-no_warn_duplicate_libraries # See: https://github.com/grpc/grpc/issues/37619 common:macos --features=-module_maps -# Pin DEVELOPER_DIR so Apple repo rules use full Xcode instead of Command Line -# Tools. The sync script writes .bazelrc.xcode with an Xcode build-version -# marker so in-place Xcode updates refresh Bazel's generated Apple toolchains. +# Pin default DEVELOPER_DIR so Apple repo rules use full Xcode instead of +# Command Line Tools when they are needed. common:macos --repo_env=DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer # Local machine or CI overrides. This lets Bazel-only runners use Command Line @@ -51,8 +50,9 @@ common:macos --repo_env=DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer # generated Xcode settings win when both files exist. try-import %workspace%/.bazelrc.local -# Xcode config for macOS builds. Generated by scripts/sync_bazel_xcode.sh. -# Bakes the Xcode build version into action cache keys and sets DEVELOPER_DIR. +# Xcode config for Apple tool builds. Generated by scripts/sync_bazel_xcode.sh. +# Bakes the Xcode build version into mactools action cache keys without making +# ordinary macOS Bazel builds depend on the installed Xcode build number. try-import %workspace%/.bazelrc.xcode common --java_language_version=25 diff --git a/scripts/sync_bazel_xcode.sh b/scripts/sync_bazel_xcode.sh index 5bc3c0b707..a98ed23259 100755 --- a/scripts/sync_bazel_xcode.sh +++ b/scripts/sync_bazel_xcode.sh @@ -6,9 +6,9 @@ # Xcode version. If Xcode is upgraded in place, the DEVELOPER_DIR path stays the # same, so Bazel can otherwise keep using stale Xcode metadata. # -# 1. Writes .bazelrc.xcode with macOS-scoped flags: -# - action_env for remote cache key invalidation -# - DEVELOPER_DIR pointing to the active Xcode +# 1. Writes .bazelrc.xcode with mactools-scoped flags: +# - action_env for Apple build remote cache key invalidation +# - DEVELOPER_DIR pointing to the active Xcode for Apple builds # # 2. Runs `bazel clean --expunge` when the version actually changes, because # local_config_apple_cc (a cached repository rule) bakes in the old version @@ -35,7 +35,7 @@ if [ -z "$XCODE_BUILD_VERSION" ]; then fi BAZELRC_XCODE=".bazelrc.xcode" -EXPECTED_LINE="common:macos --action_env=XCODE_BUILD_VERSION=${XCODE_BUILD_VERSION}" +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 @@ -45,19 +45,19 @@ if [ -f "$BAZELRC_XCODE" ]; then fi fi -# Xcode version changed (or first run) — expunge local cache to clear +# Xcode Bazel config changed (or first run) — expunge local cache to clear # stale local_config_apple_cc, then write the new config -OLD_VERSION="unknown" +OLD_CONFIG="missing" if [ -f "$BAZELRC_XCODE" ]; then - OLD_VERSION=$(sed -n 's/.*XCODE_BUILD_VERSION=//p' "$BAZELRC_XCODE" | head -1) + OLD_CONFIG=$(head -1 "$BAZELRC_XCODE") fi -echo "Xcode build version changed: ${OLD_VERSION} -> ${XCODE_BUILD_VERSION}" +echo "Xcode Bazel config changed: ${OLD_CONFIG} -> ${EXPECTED_LINE}" echo "Running bazel clean --expunge to clear stale toolchain config..." bazel clean --expunge 2>/dev/null || true cat > "$BAZELRC_XCODE" << EOF ${EXPECTED_LINE} -common:macos --repo_env=DEVELOPER_DIR=${DEVELOPER_DIR} +common:mactools --repo_env=DEVELOPER_DIR=${DEVELOPER_DIR} EOF if [ -n "${GITHUB_ENV:-}" ]; then