From 7c9c01c4f59ffe7a4bddaf6e6079abb034d15e80 Mon Sep 17 00:00:00 2001 From: Tony Allevato Date: Thu, 10 Apr 2025 05:33:23 -0700 Subject: [PATCH] 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 bb0f38be62004cfd5e6f90958ccc58d2b77af233) Signed-off-by: Brentley Jones --- swift/toolchains/swift_toolchain.bzl | 14 +++++++++++--- swift/toolchains/xcode_swift_toolchain.bzl | 14 +++++++++++--- test/fixtures/linking/fake_framework.bzl | 14 +++++++++++--- 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/swift/toolchains/swift_toolchain.bzl b/swift/toolchains/swift_toolchain.bzl index e879ce7bf..fb79414fb 100644 --- a/swift/toolchains/swift_toolchain.bzl +++ b/swift/toolchains/swift_toolchain.bzl @@ -25,7 +25,6 @@ load("@bazel_skylib//lib:paths.bzl", "paths") load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo") load( "@bazel_tools//tools/cpp:toolchain_utils.bzl", - "find_cpp_toolchain", "use_cpp_toolchain", ) load("@rules_cc//cc/common:cc_common.bzl", "cc_common") @@ -92,6 +91,8 @@ load( ) load("//swift/toolchains/config:tool_config.bzl", "ToolConfigInfo") +_CPP_TOOLCHAIN_TYPE = Label("@bazel_tools//tools/cpp:toolchain_type") + def _swift_compile_resource_set(_os, inputs_size): # The `os` argument is unused, but the Starlark API requires both # positional arguments. @@ -410,7 +411,7 @@ def _parse_target_system_name(*, arch, os, target_system_name): def _swift_toolchain_impl(ctx): toolchain_root = ctx.attr.root - cc_toolchain = find_cpp_toolchain(ctx) + cc_toolchain = ctx.exec_groups["default"].toolchains[_CPP_TOOLCHAIN_TYPE].cc target_system_name = _parse_target_system_name( arch = ctx.attr.arch, os = ctx.attr.os, @@ -706,7 +707,14 @@ The version of XCTest that the toolchain packages. }, ), doc = "Represents a Swift compiler toolchain.", + exec_groups = { + # An execution group that has no specific platform requirements. This + # ensures that the execution platform of this Swift toolchain does not + # unnecessarily constrain the execution platform of the C++ toolchain. + "default": exec_group( + toolchains = use_cpp_toolchain(), + ), + }, fragments = [] if bazel_features.cc.swift_fragment_removed else ["swift"], - toolchains = use_cpp_toolchain(), implementation = _swift_toolchain_impl, ) diff --git a/swift/toolchains/xcode_swift_toolchain.bzl b/swift/toolchains/xcode_swift_toolchain.bzl index b6b8a1ed6..ddd26734f 100644 --- a/swift/toolchains/xcode_swift_toolchain.bzl +++ b/swift/toolchains/xcode_swift_toolchain.bzl @@ -25,7 +25,6 @@ load("@bazel_skylib//lib:paths.bzl", "paths") load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo") load( "@bazel_tools//tools/cpp:toolchain_utils.bzl", - "find_cpp_toolchain", "use_cpp_toolchain", ) load("@rules_cc//cc/common:cc_common.bzl", "cc_common") @@ -108,6 +107,8 @@ load( ) load("//swift/toolchains/config:tool_config.bzl", "ToolConfigInfo") +_CPP_TOOLCHAIN_TYPE = Label("@bazel_tools//tools/cpp:toolchain_type") + def _platform_developer_framework_dir( apple_toolchain, target_triple): @@ -626,7 +627,7 @@ def _dsym_provider(*, ctx): def _xcode_swift_toolchain_impl(ctx): cpp_fragment = ctx.fragments.cpp apple_toolchain = apple_common.apple_toolchain() - cc_toolchain = find_cpp_toolchain(ctx) + cc_toolchain = ctx.exec_groups["default"].toolchains[_CPP_TOOLCHAIN_TYPE].cc target_triple = ctx.var.get("CC_TARGET_TRIPLE") or target_triples.normalize_for_swift( target_triples.parse(cc_toolchain.target_gnu_system_name), @@ -998,10 +999,17 @@ for incremental compilation using a persistent mode. }, ), doc = "Represents a Swift compiler toolchain provided by Xcode.", + exec_groups = { + # An execution group that has no specific platform requirements. This + # ensures that the execution platform of this Swift toolchain does not + # unnecessarily constrain the execution platform of the C++ toolchain. + "default": exec_group( + toolchains = use_cpp_toolchain(), + ), + }, fragments = [ "cpp", "objc", ] + ([] if bazel_features.cc.swift_fragment_removed else ["swift"]), - toolchains = use_cpp_toolchain(), implementation = _xcode_swift_toolchain_impl, ) diff --git a/test/fixtures/linking/fake_framework.bzl b/test/fixtures/linking/fake_framework.bzl index 52d66b932..3df7675c0 100644 --- a/test/fixtures/linking/fake_framework.bzl +++ b/test/fixtures/linking/fake_framework.bzl @@ -2,12 +2,13 @@ load( "@bazel_tools//tools/cpp:toolchain_utils.bzl", - "find_cpp_toolchain", "use_cpp_toolchain", ) load("@rules_cc//cc/common:cc_common.bzl", "cc_common") load("@rules_cc//cc/common:cc_info.bzl", "CcInfo") +_CPP_TOOLCHAIN_TYPE = Label("@bazel_tools//tools/cpp:toolchain_type") + def _impl(ctx): binary1 = ctx.actions.declare_file("framework1.framework/framework1") ctx.actions.write(binary1, "empty") @@ -15,7 +16,7 @@ def _impl(ctx): binary2 = ctx.actions.declare_file("framework2.framework/framework2") ctx.actions.write(binary2, "empty") - cc_toolchain = find_cpp_toolchain(ctx) + cc_toolchain = ctx.exec_groups["default"].toolchains[_CPP_TOOLCHAIN_TYPE].cc feature_configuration = cc_common.configure_features( ctx = ctx, cc_toolchain = cc_toolchain, @@ -56,6 +57,13 @@ fake_framework = rule( doc = "The C++ toolchain to use.", ), }, - toolchains = use_cpp_toolchain(), + exec_groups = { + # An execution group that has no specific platform requirements. This + # ensures that the execution platform of this Swift toolchain does not + # unnecessarily constrain the execution platform of the C++ toolchain. + "default": exec_group( + toolchains = use_cpp_toolchain(), + ), + }, fragments = ["cpp"], )