Skip to content

Commit 7c84693

Browse files
authored
Wire up apple_support xcode_config so @system_sdk selects resolve on macOS
1 parent 66071dd commit 7c84693

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

‎.bazelrc‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,20 @@ common --flag_alias=host_swiftcopt=@rules_swift//swift:exec_copt
4444
build:macos --swiftcopt=-target --swiftcopt=arm64-apple-macosx10.15
4545
build:macos --host_swiftcopt=-target --host_swiftcopt=arm64-apple-macosx10.15
4646

47+
# Point Bazel at `apple_support`'s xcode_config on macOS.
48+
#
49+
# `xcode_swift_toolchain` pulls in `@system_sdk//:{all_modules,implicit_modules}`,
50+
# whose `select({":xcode_<version>": ...})` keys use the exact version string
51+
# from `@bazel_tools//tools/osx:xcode_locator.m` (e.g. `xcode_26_6_0_17F113`).
52+
# Bazel's built-in `@bazel_tools//tools/osx:host_xcodes` produces a shorter
53+
# version without the build number, so none of the config_settings match and
54+
# the select fails.
55+
#
56+
# `apple_support`'s `@local_config_xcode//:host_xcodes` uses the SAME
57+
# `xcode_locator.m`, so its version string agrees with the select keys.
58+
# Wired up in `MODULE.bazel` via the `xcode_configure` extension.
59+
build:macos --xcode_version_config=@local_config_xcode//:host_xcodes
60+
4761
# Disable Android SDK auto-detection (we don't use it, and rules_android has Bazel 9 compatibility issues)
4862
build --repo_env=ANDROID_HOME=
4963

‎MODULE.bazel‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ bazel_dep(name = "googletest", version = "1.17.0.bcr.2")
3333
bazel_dep(name = "rules_rust", version = "0.69.0")
3434
bazel_dep(name = "rules_swift", version = "4.0.0-rc4")
3535
bazel_dep(name = "swift-syntax", version = "602.0.0.bcr.2")
36+
# `apple_support` is a transitive dep of `rules_swift`, but we depend on it
37+
# directly so we can `use_repo` `local_config_xcode` (see below). This lets
38+
# `xcode_swift_toolchain`'s `system_sdk` selects — which are keyed on the
39+
# exact Xcode version string from `xcode_locator.m` (e.g.
40+
# `xcode_26_6_0_17F113`) — resolve on macOS.
41+
bazel_dep(name = "apple_support", version = "2.6.1")
3642

3743
bazel_dep(name = "zstd", version = "1.5.7.bcr.1")
3844

@@ -270,6 +276,23 @@ register_toolchains(
270276
"@swift_toolchain//:swift_toolchain_exec_ubuntu24.04",
271277
)
272278

279+
# On macOS, `xcode_swift_toolchain` (auto-registered by rules_swift at
280+
# `@rules_swift//swift/toolchains:xcode-toolchain-*`) pulls in
281+
# `@system_sdk//:{all_modules,implicit_modules}`, whose targets are
282+
# `alias(..., select({":xcode_<version>": ...}))` keyed on the exact
283+
# Xcode version string produced by `@bazel_tools//tools/osx:xcode_locator.m`
284+
# (e.g. `xcode_26_6_0_17F113`). Bazel's built-in `@bazel_tools//tools/osx:host_xcodes`
285+
# reports a shorter version without the build number, so no `config_setting`
286+
# matches and the select fails with
287+
# "configurable attribute doesn't match this configuration".
288+
#
289+
# `apple_support`'s `@local_config_xcode//:host_xcodes` uses the SAME
290+
# `xcode_locator.m` as rules_swift's `system_sdk` extension, so its version
291+
# strings agree with the config_setting keys. Wire it up here and select it
292+
# on macOS via `--xcode_version_config` in `.bazelrc`.
293+
xcode_configure = use_extension("@apple_support//xcode:xcode_configure.bzl", "xcode_configure_extension")
294+
use_repo(xcode_configure, "local_config_xcode")
295+
273296
node = use_extension("@rules_nodejs//nodejs:extensions.bzl", "node")
274297
node.toolchain(
275298
name = "nodejs",

0 commit comments

Comments
 (0)