Skip to content

Commit 0267a47

Browse files
mkruskal-googlecopybara-github
authored andcommitted
Implement a workaround for macOS/Bazel flakes.
Bazel has a 2 minute timeout for their internal `xcrun` call, which can be exceeded on our github runners about 5% of the time. This leads to flakes and opaque errors, but is a one-time cost. Subsequent xcruns finish in seconds, so we can just do an initial call w/o a timeout before running Bazel. See bazelbuild/bazel#17437 for background. PiperOrigin-RevId: 509869860
1 parent 4b1cd0d commit 0267a47

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

.github/actions/bazel/action.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,29 @@ runs:
9898
run: ${{ inputs.bash }}
9999
shell: bash
100100

101+
# Bazel has multiple Xcode calls with hardcoded timeouts. Many of these
102+
# end up timing out on our github runners, causing flakes on every mac
103+
# build that invoked Bazel. To work around this, we manually inoke these
104+
# calls before running Bazel to make sure they end up in Xcode's cache for
105+
# quicker runs later. All of these calls are obtained from xcrun calls in
106+
# https://github.com/bazelbuild/bazel/blob/e8a69f5d5acaeb6af760631490ecbf73e8a04eeb/tools/cpp/osx_cc_configure.bzl.
107+
# See https://github.com/bazelbuild/bazel/issues/17437 for more details.
108+
# TODO(b/269503614) Remove this once Bazel provides an official solution.
109+
- name: Warm up Xcode
110+
if: ${{ runner.os == 'macOS' }}
111+
shell: bash
112+
run: |
113+
mkdir -p mac_bazel_workaround
114+
bazelisk ${{ steps.bazel.outputs.bazel-startup-flags }} build @bazel_tools//tools/osx:xcode_locator.m $BAZEL_FLAGS
115+
XCODE_LOCATOR_FLAGS=--sdk macosx clang -mmacosx-version-min=10.9 -fobjc-arc -framework CoreServices -framework Foundation
116+
SINGLE_ARCH_COMPILE_FLAGS=--sdk macosx clang -mmacosx-version-min=10.9 -std=c++11 -lc++ -O3
117+
COMPILE_FLAGS=$SINGLE_ARCH_COMPILE_FLAGS -arch arm64 -arch x86_64 -Wl,-no_adhoc_codesign -Wl,-no_uuid -O3
118+
time env -i DEVELOPER_DIR=$DEVELOPER_DIR xcrun $XCODE_LOCATOR_FLAGS -o mac_bazel_workaround/xcode-locator-bin $(bazel info output_base)/external/bazel_tools/tools/osx/xcode_locator.m
119+
time env -i DEVELOPER_DIR=$DEVELOPER_DIR xcrun $SINGLE_ARCH_COMPILE_FLAGS -o mac_bazel_workaround/libtool_check_unique $(bazel info output_base)/external/bazel_tools/tools/objc/libtool_check_unique.cc
120+
time env -i DEVELOPER_DIR=$DEVELOPER_DIR xcrun $COMPILE_FLAGS -o mac_bazel_workaround/libtool_check_unique $(bazel info output_base)/external/bazel_tools/tools/objc/libtool_check_unique.cc
121+
time env -i DEVELOPER_DIR=$DEVELOPER_DIR xcrun $SINGLE_ARCH_COMPILE_FLAGS -o mac_bazel_workaround/wrapped_clang $(bazel info output_base)/external/bazel_tools/tools/osx/crosstool/wrapped_clang.cc
122+
time env -i DEVELOPER_DIR=$DEVELOPER_DIR xcrun $COMPILE_FLAGS -o mac_bazel_workaround/wrapped_clang $(bazel info output_base)/external/bazel_tools/tools/osx/crosstool/wrapped_clang.cc
123+
101124
- name: Run Bazel
102125
if: ${{ !inputs.bash }}
103126
run: >-

.github/actions/internal/bazel-setup/action.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ runs:
4242
- name: Initialize MacOS-specific Bazel flags
4343
if: runner.os == 'macOS'
4444
shell: bash
45-
run: echo "BAZEL_FLAGS=$BAZEL_FLAGS --xcode_version_config=//.github:host_xcodes" >> $GITHUB_ENV
45+
run: |
46+
echo "BAZEL_FLAGS=$BAZEL_FLAGS --xcode_version_config=//.github:host_xcodes" >> $GITHUB_ENV
47+
echo "DEVELOPER_DIR=${{ env.DEVELOPER_DIR || '/Applications/Xcode_14.1.app/Contents/Developer' }}" >> $GITHUB_ENV
4648
4749
- name: Configure Bazel caching
4850
# Skip bazel cache for local act runs due to issue with credential files

0 commit comments

Comments
 (0)