Skip to content

Commit de45109

Browse files
Ensure Bazel uses the correct Xcode version when compiling (#1099)
This is three changes: - On the command-line, set `--xcode_version` to whatever `xcode-select` is set to - In Xcode, set `--xcode_version` to `$XCODE_PRODUCT_BUILD_VERSION` - For both, set `--repo_env=USE_CLANG_CL= $XCODE_PRODUCT_BUILD_VERSION` to work around bazelbuild/bazel#8902
1 parent 7a9c85d commit de45109

File tree

10 files changed

+148
-9
lines changed

10 files changed

+148
-9
lines changed

examples/cc/test/fixtures/bwb.xcodeproj/rules_xcodeproj/bazel/bazel_build.sh

Lines changed: 15 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/cc/test/fixtures/bwx.xcodeproj/rules_xcodeproj/bazel/bazel_build.sh

Lines changed: 15 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/integration/test/fixtures/bwb.xcodeproj/rules_xcodeproj/bazel/bazel_build.sh

Lines changed: 15 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/integration/test/fixtures/bwx.xcodeproj/rules_xcodeproj/bazel/bazel_build.sh

Lines changed: 15 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/simple/test/fixtures/bwb.xcodeproj/rules_xcodeproj/bazel/bazel_build.sh

Lines changed: 15 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/simple/test/fixtures/bwx.xcodeproj/rules_xcodeproj/bazel/bazel_build.sh

Lines changed: 15 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/fixtures/generator/bwb.xcodeproj/rules_xcodeproj/bazel/bazel_build.sh

Lines changed: 15 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/fixtures/generator/bwx.xcodeproj/rules_xcodeproj/bazel/bazel_build.sh

Lines changed: 15 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

xcodeproj/internal/bazel_integration_files/bazel_build.sh

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,15 @@ bazel_cmd=(
8989
"$BAZEL_PATH"
9090
"${bazelrcs[@]}"
9191
)
92+
pre_config_flags=(
93+
# Be explicit about our desired Xcode version
94+
"--xcode_version=$XCODE_PRODUCT_BUILD_VERSION"
95+
96+
# Work around https://github.com/bazelbuild/bazel/issues/8902
97+
# `USE_CLANG_CL` is only used on Windows, we set it here to cause Bazel to
98+
# re-evaluate the cc_toolchain for a different Xcode version
99+
"--repo_env=USE_CLANG_CL=$XCODE_PRODUCT_BUILD_VERSION"
100+
)
92101

93102
# Determine Bazel output_path
94103

@@ -111,7 +120,11 @@ else
111120
fi
112121

113122
output_path=$("${bazel_cmd[@]}" \
114-
info --config="${BAZEL_CONFIG}_info" --color="$color" output_path)
123+
info \
124+
"${pre_config_flags[@]}" \
125+
--config="${BAZEL_CONFIG}_info" \
126+
--color="$color" \
127+
output_path)
115128
execution_root="${output_path%/*}"
116129

117130
# Create `bazel.lldbinit``
@@ -181,6 +194,7 @@ touch "$build_marker"
181194
"$BAZEL_INTEGRATION_DIR/process_bazel_build_log.py" \
182195
"${bazel_cmd[@]}" \
183196
build \
197+
"${pre_config_flags[@]}" \
184198
--config="$config" \
185199
--color=yes \
186200
${toolchain:+--define=SWIFT_CUSTOM_TOOLCHAIN="$toolchain"} \

xcodeproj/internal/runner.template.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,17 @@ if [[ -s "$extra_flags_bazelrc" ]]; then
5252
bazelrcs+=("--bazelrc=$extra_flags_bazelrc")
5353
fi
5454

55+
xcode_build_version=$(/usr/bin/xcodebuild -version | tail -1 | cut -d " " -f3)
56+
pre_config_flags=(
57+
# Be explicit about our desired Xcode version
58+
"--xcode_version=$xcode_build_version"
59+
60+
# Work around https://github.com/bazelbuild/bazel/issues/8902
61+
# `USE_CLANG_CL` is only used on Windows, we set it here to cause Bazel to
62+
# re-evaluate the cc_toolchain for a different Xcode version
63+
"--repo_env=USE_CLANG_CL=$xcode_build_version"
64+
)
65+
5566
# Ensure that our top-level cache buster `new_local_repository` is valid
5667
mkdir -p /tmp/rules_xcodeproj
5768
date +%s > "/tmp/rules_xcodeproj/top_level_cache_buster"
@@ -63,6 +74,7 @@ if [[ -z "${build_output_groups:-}" ]]; then
6374
"%bazel_path%" \
6475
"${bazelrcs[@]}" \
6576
run \
77+
"${pre_config_flags[@]}" \
6678
"--config=%config%_generator" \
6779
%extra_generator_flags% \
6880
"%generator_label%" \
@@ -73,6 +85,7 @@ else
7385
"%bazel_path%" \
7486
"${bazelrcs[@]}" \
7587
build \
88+
"${pre_config_flags[@]}" \
7689
"--config=_%config%_build" \
7790
--output_groups="$build_output_groups" \
7891
"%generator_label%"

0 commit comments

Comments
 (0)