Skip to content

Commit cc25a58

Browse files
allevatobrentleyjones
authored andcommitted
Move the C++ toolchain into its own execution group so that it does not have to be bound by the same constraints as the execution platform selected for the Swift toolchain.
PiperOrigin-RevId: 745988579 (cherry picked from commit bb0f38b) Signed-off-by: Brentley Jones <[email protected]>
1 parent 3dfbf33 commit cc25a58

File tree

3 files changed

+33
-6
lines changed

3 files changed

+33
-6
lines changed

swift/toolchains/swift_toolchain.bzl

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ load("@bazel_skylib//lib:paths.bzl", "paths")
2525
load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
2626
load(
2727
"@bazel_tools//tools/cpp:toolchain_utils.bzl",
28-
"find_cpp_toolchain",
2928
"use_cpp_toolchain",
3029
)
3130
load("@rules_cc//cc/common:cc_common.bzl", "cc_common")
@@ -92,6 +91,8 @@ load(
9291
)
9392
load("//swift/toolchains/config:tool_config.bzl", "ToolConfigInfo")
9493

94+
_CPP_TOOLCHAIN_TYPE = Label("@bazel_tools//tools/cpp:toolchain_type")
95+
9596
def _swift_compile_resource_set(_os, inputs_size):
9697
# The `os` argument is unused, but the Starlark API requires both
9798
# positional arguments.
@@ -410,7 +411,7 @@ def _parse_target_system_name(*, arch, os, target_system_name):
410411

411412
def _swift_toolchain_impl(ctx):
412413
toolchain_root = ctx.attr.root
413-
cc_toolchain = find_cpp_toolchain(ctx)
414+
cc_toolchain = ctx.exec_groups["default"].toolchains[_CPP_TOOLCHAIN_TYPE].cc
414415
target_system_name = _parse_target_system_name(
415416
arch = ctx.attr.arch,
416417
os = ctx.attr.os,
@@ -706,6 +707,14 @@ The version of XCTest that the toolchain packages.
706707
},
707708
),
708709
doc = "Represents a Swift compiler toolchain.",
710+
exec_groups = {
711+
# An execution group that has no specific platform requirements. This
712+
# ensures that the execution platform of this Swift toolchain does not
713+
# unnecessarily constrain the execution platform of the C++ toolchain.
714+
"default": exec_group(
715+
toolchains = use_cpp_toolchain(),
716+
),
717+
},
709718
fragments = [] if bazel_features.cc.swift_fragment_removed else ["swift"],
710719
toolchains = use_cpp_toolchain(),
711720
implementation = _swift_toolchain_impl,

swift/toolchains/xcode_swift_toolchain.bzl

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ load("@bazel_skylib//lib:paths.bzl", "paths")
2525
load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
2626
load(
2727
"@bazel_tools//tools/cpp:toolchain_utils.bzl",
28-
"find_cpp_toolchain",
2928
"use_cpp_toolchain",
3029
)
3130
load("@rules_cc//cc/common:cc_common.bzl", "cc_common")
@@ -108,6 +107,8 @@ load(
108107
)
109108
load("//swift/toolchains/config:tool_config.bzl", "ToolConfigInfo")
110109

110+
_CPP_TOOLCHAIN_TYPE = Label("@bazel_tools//tools/cpp:toolchain_type")
111+
111112
def _platform_developer_framework_dir(
112113
apple_toolchain,
113114
target_triple):
@@ -626,7 +627,7 @@ def _dsym_provider(*, ctx):
626627
def _xcode_swift_toolchain_impl(ctx):
627628
cpp_fragment = ctx.fragments.cpp
628629
apple_toolchain = apple_common.apple_toolchain()
629-
cc_toolchain = find_cpp_toolchain(ctx)
630+
cc_toolchain = ctx.exec_groups["default"].toolchains[_CPP_TOOLCHAIN_TYPE].cc
630631

631632
target_triple = ctx.var.get("CC_TARGET_TRIPLE") or target_triples.normalize_for_swift(
632633
target_triples.parse(cc_toolchain.target_gnu_system_name),
@@ -998,6 +999,14 @@ for incremental compilation using a persistent mode.
998999
},
9991000
),
10001001
doc = "Represents a Swift compiler toolchain provided by Xcode.",
1002+
exec_groups = {
1003+
# An execution group that has no specific platform requirements. This
1004+
# ensures that the execution platform of this Swift toolchain does not
1005+
# unnecessarily constrain the execution platform of the C++ toolchain.
1006+
"default": exec_group(
1007+
toolchains = use_cpp_toolchain(),
1008+
),
1009+
},
10011010
fragments = [
10021011
"cpp",
10031012
"objc",

test/fixtures/linking/fake_framework.bzl

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,21 @@
22

33
load(
44
"@bazel_tools//tools/cpp:toolchain_utils.bzl",
5-
"find_cpp_toolchain",
65
"use_cpp_toolchain",
76
)
87
load("@rules_cc//cc/common:cc_common.bzl", "cc_common")
98
load("@rules_cc//cc/common:cc_info.bzl", "CcInfo")
109

10+
_CPP_TOOLCHAIN_TYPE = Label("@bazel_tools//tools/cpp:toolchain_type")
11+
1112
def _impl(ctx):
1213
binary1 = ctx.actions.declare_file("framework1.framework/framework1")
1314
ctx.actions.write(binary1, "empty")
1415

1516
binary2 = ctx.actions.declare_file("framework2.framework/framework2")
1617
ctx.actions.write(binary2, "empty")
1718

18-
cc_toolchain = find_cpp_toolchain(ctx)
19+
cc_toolchain = ctx.exec_groups["default"].toolchains[_CPP_TOOLCHAIN_TYPE].cc
1920
feature_configuration = cc_common.configure_features(
2021
ctx = ctx,
2122
cc_toolchain = cc_toolchain,
@@ -56,6 +57,14 @@ fake_framework = rule(
5657
doc = "The C++ toolchain to use.",
5758
),
5859
},
60+
exec_groups = {
61+
# An execution group that has no specific platform requirements. This
62+
# ensures that the execution platform of this Swift toolchain does not
63+
# unnecessarily constrain the execution platform of the C++ toolchain.
64+
"default": exec_group(
65+
toolchains = use_cpp_toolchain(),
66+
),
67+
},
5968
toolchains = use_cpp_toolchain(),
6069
fragments = ["cpp"],
6170
)

0 commit comments

Comments
 (0)