From 268ffb0bc9257f1549266bfff6d98d35e971a6dd Mon Sep 17 00:00:00 2001 From: Ivo List Date: Thu, 7 Sep 2023 12:38:22 +0200 Subject: [PATCH 1/5] Flip --incompatible_enable_cc_toolchain_resolution --- .../com/google/devtools/build/lib/rules/cpp/CppOptions.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppOptions.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppOptions.java index c0896b128e281b..6df2864dc0e417 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppOptions.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppOptions.java @@ -911,7 +911,7 @@ public Label getMemProfProfileLabel() { @Option( name = "incompatible_enable_cc_toolchain_resolution", - defaultValue = "false", + defaultValue = "true", documentationCategory = OptionDocumentationCategory.UNDOCUMENTED, effectTags = {OptionEffectTag.LOADING_AND_ANALYSIS}, metadataTags = {OptionMetadataTag.INCOMPATIBLE_CHANGE}, From c94963cc2b3c84573aece97bc5cfb460a85bb218 Mon Sep 17 00:00:00 2001 From: Ivo List Date: Thu, 7 Sep 2023 16:11:05 +0200 Subject: [PATCH 2/5] Fix tests involving Starlark rules using cc_common --- .../lib/rules/cpp/CcToolchainSuiteTest.java | 2 +- .../lib/rules/cpp/StarlarkCcCommonTest.java | 25 ++++++++++++++++--- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainSuiteTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainSuiteTest.java index b42908195db64a..6923c2b4e785d0 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainSuiteTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainSuiteTest.java @@ -29,7 +29,7 @@ public class CcToolchainSuiteTest extends BuildViewTestCase { @Test public void testInvalidCpu() throws Exception { reporter.removeHandler(failFastHandler); - useConfiguration("--cpu=bogus"); + useConfiguration("--cpu=bogus", "--noincompatible_enable_cc_toolchain_resolution"); getConfiguredTarget( ruleClassProvider.getToolsRepository() + "//tools/cpp:current_cc_toolchain"); assertContainsEvent("does not contain a toolchain for cpu 'bogus'"); diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/StarlarkCcCommonTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/StarlarkCcCommonTest.java index 1eec601fd6a0f6..2dc610f4e08fd6 100755 --- a/src/test/java/com/google/devtools/build/lib/rules/cpp/StarlarkCcCommonTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/StarlarkCcCommonTest.java @@ -5763,7 +5763,10 @@ private static void createFiles( bzlFilePath + "/extension.bzl", "load('//myinfo:myinfo.bzl', 'MyInfo')", "def _cc_aspect_impl(target, ctx):", - " toolchain = ctx.attr._cc_toolchain[cc_common.CcToolchainInfo]", + " if ctx.attr._cc_toolchain:", + " toolchain = ctx.attr._cc_toolchain[cc_common.CcToolchainInfo]", + " else:", + " toolchain = ctx.toolchains['@bazel_tools//tools/cpp:toolchain_type'].cc", " feature_configuration = cc_common.configure_features(", " ctx = ctx,", " cc_toolchain = toolchain,", @@ -5795,6 +5798,7 @@ private static void createFiles( + " '@bazel_tools//tools/cpp:current_cc_toolchain'),", " },", fragments, + " toolchains = ['@bazel_tools//tools/cpp:toolchain_type']", ")", "def _cc_starlark_library_impl(ctx):", " dep_compilation_contexts = []", @@ -5802,7 +5806,10 @@ private static void createFiles( " for dep in ctx.attr._deps:", " dep_compilation_contexts.append(dep[CcInfo].compilation_context)", " dep_linking_contexts.append(dep[CcInfo].linking_context)", - " toolchain = ctx.attr._my_cc_toolchain[cc_common.CcToolchainInfo]", + " if ctx.attr._my_cc_toolchain:", + " toolchain = ctx.attr._my_cc_toolchain[cc_common.CcToolchainInfo]", + " else:", + " toolchain = ctx.toolchains['@bazel_tools//tools/cpp:toolchain_type'].cc", " feature_configuration = cc_common.configure_features(", " ctx = ctx,", " cc_toolchain=toolchain,", @@ -5866,6 +5873,7 @@ private static void createFiles( " configuration_field(fragment = 'cpp', name = 'cc_toolchain'))", " },", fragments, + " toolchains = ['@bazel_tools//tools/cpp:toolchain_type']", ")"); scratch.file( "foo/BUILD", @@ -6369,7 +6377,10 @@ private static void createCcBinRule( extensionDirectory + "/extension.bzl", "load('//myinfo:myinfo.bzl', 'MyInfo')", "def _cc_bin_impl(ctx):", - " toolchain = ctx.attr._cc_toolchain[cc_common.CcToolchainInfo]", + " if ctx.attr._cc_toolchain:", + " toolchain = ctx.attr._cc_toolchain[cc_common.CcToolchainInfo]", + " else:", + " toolchain = ctx.toolchains['@bazel_tools//tools/cpp:toolchain_type'].cc", " feature_configuration = cc_common.configure_features(", " ctx = ctx,", " cc_toolchain = toolchain,", @@ -6406,6 +6417,7 @@ private static void createCcBinRule( " 'additional_outputs': attr.output_list(),", " },", fragments, + " toolchains = ['@bazel_tools//tools/cpp:toolchain_type']", ")"); } @@ -8175,7 +8187,11 @@ public void testGrepIncludesIsSetToNullInsideCcToolchain() throws Exception { scratch.file( "foo/extension.bzl", "def _cc_skylark_library_impl(ctx):", - " return [ctx.attr._cc_toolchain[cc_common.CcToolchainInfo]]", + " if ctx.attr._cc_toolchain:", + " toolchain = ctx.attr._cc_toolchain[cc_common.CcToolchainInfo]", + " else:", + " toolchain = ctx.toolchains['@bazel_tools//tools/cpp:toolchain_type'].cc", + " return [toolchain]", "cc_skylark_library = rule(", " implementation = _cc_skylark_library_impl,", " attrs = {", @@ -8183,6 +8199,7 @@ public void testGrepIncludesIsSetToNullInsideCcToolchain() throws Exception { " configuration_field(fragment = 'cpp', name = 'cc_toolchain')),", " },", " fragments = ['cpp'],", + " toolchains = ['@bazel_tools//tools/cpp:toolchain_type']", ")"); ConfiguredTarget target = getConfiguredTarget("//foo:skylark_lib"); From e8078bfca6686d665a5489e8c55b7f7eab187ac5 Mon Sep 17 00:00:00 2001 From: Ivo List Date: Thu, 7 Sep 2023 16:47:06 +0200 Subject: [PATCH 3/5] Fix unit tests --- .../devtools/build/lib/analysis/AutoExecGroupsTest.java | 7 ++++--- .../build/lib/starlark/StarlarkDefinedAspectsTest.java | 2 +- .../build/lib/view/java/JavaConfigurationTest.java | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/test/java/com/google/devtools/build/lib/analysis/AutoExecGroupsTest.java b/src/test/java/com/google/devtools/build/lib/analysis/AutoExecGroupsTest.java index 8c5c58956ca818..8e6f7d179c87c9 100644 --- a/src/test/java/com/google/devtools/build/lib/analysis/AutoExecGroupsTest.java +++ b/src/test/java/com/google/devtools/build/lib/analysis/AutoExecGroupsTest.java @@ -1991,7 +1991,7 @@ public void ccCommonCompile_moduleActionsExecuteOnFirstPlatform() throws Excepti " srcs = ['custom.cc'],", " hdrs = ['custom.h'],", ")"); - useConfiguration("--incompatible_auto_exec_groups", "--features=header_modules"); + useConfiguration("--incompatible_auto_exec_groups", "--features=header_modules", "--noincompatible_enable_cc_toolchain_resolution"); AnalysisMock.get() .ccSupport() .setupCcToolchainConfig( @@ -2061,7 +2061,8 @@ public void ccCommonCompile_codeGenModuleActionExecutesOnFirstPlatform() throws useConfiguration( "--incompatible_auto_exec_groups", "--features=header_modules", - "--features=header_module_codegen"); + "--features=header_module_codegen", + "--noincompatible_enable_cc_toolchain_resolution"); AnalysisMock.get() .ccSupport() .setupCcToolchainConfig( @@ -2126,7 +2127,7 @@ public void ccCommonCompile_compileHeaderActionExecutesOnFirstPlatform() throws " srcs = ['custom.cc'],", " hdrs = ['custom.h'],", ")"); - useConfiguration("--incompatible_auto_exec_groups", "--features=parse_headers"); + useConfiguration("--incompatible_auto_exec_groups", "--features=parse_headers", "--noincompatible_enable_cc_toolchain_resolution"); AnalysisMock.get() .ccSupport() .setupCcToolchainConfig( diff --git a/src/test/java/com/google/devtools/build/lib/starlark/StarlarkDefinedAspectsTest.java b/src/test/java/com/google/devtools/build/lib/starlark/StarlarkDefinedAspectsTest.java index 8f157f437056e4..6b4eb993cb946d 100644 --- a/src/test/java/com/google/devtools/build/lib/starlark/StarlarkDefinedAspectsTest.java +++ b/src/test/java/com/google/devtools/build/lib/starlark/StarlarkDefinedAspectsTest.java @@ -352,7 +352,7 @@ public void aspectsPropagatingForDefaultAndImplicit() throws Exception { assertThat(names).containsAtLeast("xxx", "yyy"); // 3-4 is the C++ toolchain and alias; its name changes between Blaze and Bazel. - assertThat(names).hasSize(4); + assertThat(names).hasSize(3); } @Test diff --git a/src/test/java/com/google/devtools/build/lib/view/java/JavaConfigurationTest.java b/src/test/java/com/google/devtools/build/lib/view/java/JavaConfigurationTest.java index 8cdc2b39044c74..0af72a8ec78eed 100644 --- a/src/test/java/com/google/devtools/build/lib/view/java/JavaConfigurationTest.java +++ b/src/test/java/com/google/devtools/build/lib/view/java/JavaConfigurationTest.java @@ -48,13 +48,13 @@ public void testJavaLauncherConfiguration() throws Exception { @Test public void testHostCrosstoolTop() throws Exception { - BuildConfigurationValue config = createConfiguration(); + BuildConfigurationValue config = createConfiguration("--noincompatible_enable_cc_toolchain_resolution"); assertThat(config.getFragment(CppConfiguration.class).getRuleProvidingCcToolchainProvider()) .isEqualTo( Label.parseCanonicalUnchecked( TestConstants.TOOLS_REPOSITORY + "//tools/cpp:toolchain")); - BuildConfigurationValue execConfig = createExec(); + BuildConfigurationValue execConfig = createExec("--noincompatible_enable_cc_toolchain_resolution"); assertThat(execConfig.getFragment(CppConfiguration.class).getRuleProvidingCcToolchainProvider()) .isEqualTo( Label.parseCanonicalUnchecked( From bb29018111be582e614e02daaaac6c9f72fb2d00 Mon Sep 17 00:00:00 2001 From: Ivo List Date: Thu, 7 Sep 2023 17:03:34 +0200 Subject: [PATCH 4/5] Fix unit tests --- .../google/devtools/build/lib/analysis/AutoExecGroupsTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/google/devtools/build/lib/analysis/AutoExecGroupsTest.java b/src/test/java/com/google/devtools/build/lib/analysis/AutoExecGroupsTest.java index 8e6f7d179c87c9..1081009968bba7 100644 --- a/src/test/java/com/google/devtools/build/lib/analysis/AutoExecGroupsTest.java +++ b/src/test/java/com/google/devtools/build/lib/analysis/AutoExecGroupsTest.java @@ -1811,7 +1811,7 @@ public void ccCommonLink_cppLTOActionExecutesOnFirstPlatform() throws Exception " srcs = ['custom.cc'],", " deps = ['dep'],", ")"); - useConfiguration("--incompatible_auto_exec_groups", "--features=thin_lto"); + useConfiguration("--incompatible_auto_exec_groups", "--features=thin_lto", "--noincompatible_enable_cc_toolchain_resolution"); AnalysisMock.get() .ccSupport() .setupCcToolchainConfig( From d596c67c8e57b9d10635ab9e5ecf50d7a7205532 Mon Sep 17 00:00:00 2001 From: Ivo List Date: Fri, 8 Sep 2023 11:18:49 +0200 Subject: [PATCH 5/5] Fix AutoExecGroupTests for C++ toolchains --- .../lib/analysis/AutoExecGroupsTest.java | 65 ++++++++----------- 1 file changed, 26 insertions(+), 39 deletions(-) diff --git a/src/test/java/com/google/devtools/build/lib/analysis/AutoExecGroupsTest.java b/src/test/java/com/google/devtools/build/lib/analysis/AutoExecGroupsTest.java index 1081009968bba7..46e33093684f83 100644 --- a/src/test/java/com/google/devtools/build/lib/analysis/AutoExecGroupsTest.java +++ b/src/test/java/com/google/devtools/build/lib/analysis/AutoExecGroupsTest.java @@ -1626,7 +1626,7 @@ public void ccCommonLink_fileWriteActionExecutesOnFirstPlatform() throws Excepti + "', mandatory = False),", " ]", "def _impl(ctx):", - " cc_toolchain = ctx.attr._cc_toolchain[cc_common.CcToolchainInfo]", + " cc_toolchain = ctx.toolchains['" + TestConstants.CPP_TOOLCHAIN_TYPE + "'].cc", " feature_configuration = cc_common.configure_features(", " ctx = ctx,", " cc_toolchain = cc_toolchain,", @@ -1642,14 +1642,12 @@ public void ccCommonLink_fileWriteActionExecutesOnFirstPlatform() throws Excepti " return []", "custom_rule = rule(", " implementation = _impl,", - " attrs = { '_cc_toolchain': attr.label(default=Label('//test:alias')) },", " toolchains = ['//rule:toolchain_type_2'] + _use_cpp_toolchain(),", " fragments = ['cpp']", ")"); scratch.file( "test/BUILD", "load('//test:defs.bzl', 'custom_rule')", - "cc_toolchain_alias(name='alias')", "custom_rule(name = 'custom_rule_name')"); useConfiguration("--incompatible_auto_exec_groups"); @@ -1673,7 +1671,7 @@ public void ccCommonLink_cppLinkExecGroupNotDefined_cppLinkActionExecutesOnFirst + "', mandatory = False),", " ]", "def _impl(ctx):", - " cc_toolchain = ctx.attr._cc_toolchain[cc_common.CcToolchainInfo]", + " cc_toolchain = ctx.toolchains['" + TestConstants.CPP_TOOLCHAIN_TYPE + "'].cc", " feature_configuration = cc_common.configure_features(", " ctx = ctx,", " cc_toolchain = cc_toolchain,", @@ -1689,7 +1687,6 @@ public void ccCommonLink_cppLinkExecGroupNotDefined_cppLinkActionExecutesOnFirst " return []", "custom_rule = rule(", " implementation = _impl,", - " attrs = { '_cc_toolchain': attr.label(default=Label('//test:alias')) },", " exec_groups = { ", " '" + CPP_LINK_EXEC_GROUP + "': exec_group(toolchains = _use_cpp_toolchain()),", " },", @@ -1699,7 +1696,6 @@ public void ccCommonLink_cppLinkExecGroupNotDefined_cppLinkActionExecutesOnFirst scratch.file( "test/BUILD", "load('//test:defs.bzl', 'custom_rule')", - "cc_toolchain_alias(name='alias')", "custom_rule(name = 'custom_rule_name')"); useConfiguration("--incompatible_auto_exec_groups"); @@ -1723,7 +1719,7 @@ public void ccCommonLink_cppLinkExecGroupDefined_cppLinkActionExecutesOnFirstPla + "', mandatory = False),", " ]", "def _impl(ctx):", - " cc_toolchain = ctx.attr._cc_toolchain[cc_common.CcToolchainInfo]", + " cc_toolchain = ctx.toolchains['" + TestConstants.CPP_TOOLCHAIN_TYPE + "'].cc", " feature_configuration = cc_common.configure_features(", " ctx = ctx,", " cc_toolchain = cc_toolchain,", @@ -1739,7 +1735,6 @@ public void ccCommonLink_cppLinkExecGroupDefined_cppLinkActionExecutesOnFirstPla " return []", "custom_rule = rule(", " implementation = _impl,", - " attrs = { '_cc_toolchain': attr.label(default=Label('//test:alias')) },", " exec_groups = { ", " '" + CPP_LINK_EXEC_GROUP + "': exec_group(toolchains = _use_cpp_toolchain()),", " },", @@ -1749,7 +1744,6 @@ public void ccCommonLink_cppLinkExecGroupDefined_cppLinkActionExecutesOnFirstPla scratch.file( "test/BUILD", "load('//test:defs.bzl', 'custom_rule')", - "cc_toolchain_alias(name='alias')", "custom_rule(name = 'custom_rule_name')"); useConfiguration("--incompatible_auto_exec_groups"); @@ -1772,7 +1766,7 @@ public void ccCommonLink_cppLTOActionExecutesOnFirstPlatform() throws Exception + "', mandatory = False),", " ]", "def _impl(ctx):", - " cc_toolchain = ctx.attr._cc_toolchain[cc_common.CcToolchainInfo]", + " cc_toolchain = ctx.toolchains['" + TestConstants.CPP_TOOLCHAIN_TYPE + "'].cc", " feature_configuration = cc_common.configure_features(", " ctx = ctx,", " cc_toolchain = cc_toolchain,", @@ -1793,7 +1787,6 @@ public void ccCommonLink_cppLTOActionExecutesOnFirstPlatform() throws Exception " attrs = {", " 'deps': attr.label_list(),", " 'srcs': attr.label_list(allow_files = ['.cc']),", - " '_cc_toolchain': attr.label(default=Label('//test:alias')),", " },", " toolchains = ['//rule:toolchain_type_2'] + _use_cpp_toolchain(),", " fragments = ['cpp']", @@ -1801,7 +1794,6 @@ public void ccCommonLink_cppLTOActionExecutesOnFirstPlatform() throws Exception scratch.file( "test/BUILD", "load('//test:defs.bzl', 'custom_rule')", - "cc_toolchain_alias(name='alias')", "cc_library(", " name = 'dep',", " srcs = ['dep.cc'],", @@ -1811,13 +1803,15 @@ public void ccCommonLink_cppLTOActionExecutesOnFirstPlatform() throws Exception " srcs = ['custom.cc'],", " deps = ['dep'],", ")"); - useConfiguration("--incompatible_auto_exec_groups", "--features=thin_lto", "--noincompatible_enable_cc_toolchain_resolution"); + useConfiguration("--incompatible_auto_exec_groups", "--features=thin_lto"); AnalysisMock.get() .ccSupport() .setupCcToolchainConfig( mockToolsConfig, CcToolchainConfig.builder() - .withFeatures(CppRuleClasses.THIN_LTO, CppRuleClasses.SUPPORTS_START_END_LIB)); + .withFeatures(CppRuleClasses.THIN_LTO, CppRuleClasses.SUPPORTS_START_END_LIB) + .withToolchainTargetConstraints("@//platforms:constraint_1") + .withToolchainExecConstraints("@//platforms:constraint_1")); ImmutableList actions = getActions("//test:custom_rule_name", CppLinkAction.class); ImmutableList cppLTOActions = @@ -1841,7 +1835,7 @@ public void ccCommonLink_linkstampCompileActionExecutesOnFirstPlatform() throws + "', mandatory = False),", " ]", "def _impl(ctx):", - " cc_toolchain = ctx.attr._cc_toolchain[cc_common.CcToolchainInfo]", + " cc_toolchain = ctx.toolchains['" + TestConstants.CPP_TOOLCHAIN_TYPE + "'].cc", " feature_configuration = cc_common.configure_features(", " ctx = ctx,", " cc_toolchain = cc_toolchain,", @@ -1861,7 +1855,6 @@ public void ccCommonLink_linkstampCompileActionExecutesOnFirstPlatform() throws " implementation = _impl,", " attrs = {", " 'deps': attr.label_list(),", - " '_cc_toolchain': attr.label(default=Label('//bazel_internal/test_rules/cc:alias')),", " },", " toolchains = ['//rule:toolchain_type_2'] + _use_cpp_toolchain(),", " fragments = ['cpp']", @@ -1869,7 +1862,6 @@ public void ccCommonLink_linkstampCompileActionExecutesOnFirstPlatform() throws scratch.file( "bazel_internal/test_rules/cc/BUILD", "load('//bazel_internal/test_rules/cc:defs.bzl', 'custom_rule')", - "cc_toolchain_alias(name='alias')", "cc_library(", " name = 'dep',", " linkstamp = 'stamp.cc',", @@ -1900,7 +1892,7 @@ public void ccCommonCompile_cppCompileActionExecutesOnFirstPlatform() throws Exc + "', mandatory = False),", " ]", "def _impl(ctx):", - " cc_toolchain = ctx.attr._cc_toolchain[cc_common.CcToolchainInfo]", + " cc_toolchain = ctx.toolchains['" + TestConstants.CPP_TOOLCHAIN_TYPE + "'].cc", " feature_configuration = cc_common.configure_features(", " ctx = ctx,", " cc_toolchain = cc_toolchain,", @@ -1919,7 +1911,6 @@ public void ccCommonCompile_cppCompileActionExecutesOnFirstPlatform() throws Exc " implementation = _impl,", " attrs = {", " 'srcs': attr.label_list(allow_files = ['.cc']),", - " '_cc_toolchain': attr.label(default=Label('//bazel_internal/test_rules/cc:alias')),", " },", " toolchains = ['//rule:toolchain_type_2'] + _use_cpp_toolchain(),", " fragments = ['cpp']", @@ -1927,7 +1918,6 @@ public void ccCommonCompile_cppCompileActionExecutesOnFirstPlatform() throws Exc scratch.file( "bazel_internal/test_rules/cc/BUILD", "load('//bazel_internal/test_rules/cc:defs.bzl', 'custom_rule')", - "cc_toolchain_alias(name='alias')", "custom_rule(", " name = 'custom_rule_name',", " srcs = ['custom.cc'],", @@ -1955,7 +1945,7 @@ public void ccCommonCompile_moduleActionsExecuteOnFirstPlatform() throws Excepti + "', mandatory = False),", " ]", "def _impl(ctx):", - " cc_toolchain = ctx.attr._cc_toolchain[cc_common.CcToolchainInfo]", + " cc_toolchain = ctx.toolchains['" + TestConstants.CPP_TOOLCHAIN_TYPE + "'].cc", " feature_configuration = cc_common.configure_features(", " ctx = ctx,", " cc_toolchain = cc_toolchain,", @@ -1977,7 +1967,6 @@ public void ccCommonCompile_moduleActionsExecuteOnFirstPlatform() throws Excepti " attrs = {", " 'srcs': attr.label_list(allow_files = ['.cc']),", " 'hdrs': attr.label_list(allow_files = ['.h']),", - " '_cc_toolchain': attr.label(default=Label('//bazel_internal/test_rules/cc:alias')),", " },", " toolchains = ['//rule:toolchain_type_2'] + _use_cpp_toolchain(),", " fragments = ['cpp']", @@ -1985,18 +1974,19 @@ public void ccCommonCompile_moduleActionsExecuteOnFirstPlatform() throws Excepti scratch.file( "bazel_internal/test_rules/cc/BUILD", "load('//bazel_internal/test_rules/cc:defs.bzl', 'custom_rule')", - "cc_toolchain_alias(name='alias')", "custom_rule(", " name = 'custom_rule_name',", " srcs = ['custom.cc'],", " hdrs = ['custom.h'],", ")"); - useConfiguration("--incompatible_auto_exec_groups", "--features=header_modules", "--noincompatible_enable_cc_toolchain_resolution"); + useConfiguration("--incompatible_auto_exec_groups", "--features=header_modules"); AnalysisMock.get() .ccSupport() .setupCcToolchainConfig( mockToolsConfig, - CcToolchainConfig.builder().withFeatures(MockCcSupport.HEADER_MODULES_FEATURES)); + CcToolchainConfig.builder().withFeatures(MockCcSupport.HEADER_MODULES_FEATURES) + .withToolchainTargetConstraints("@//platforms:constraint_1") + .withToolchainExecConstraints("@//platforms:constraint_1")); ImmutableList cppCompileActions = getActions("//bazel_internal/test_rules/cc:custom_rule_name", CppCompileAction.class); @@ -2023,7 +2013,7 @@ public void ccCommonCompile_codeGenModuleActionExecutesOnFirstPlatform() throws + "', mandatory = False),", " ]", "def _impl(ctx):", - " cc_toolchain = ctx.attr._cc_toolchain[cc_common.CcToolchainInfo]", + " cc_toolchain = ctx.toolchains['" + TestConstants.CPP_TOOLCHAIN_TYPE + "'].cc", " feature_configuration = cc_common.configure_features(", " ctx = ctx,", " cc_toolchain = cc_toolchain,", @@ -2044,7 +2034,6 @@ public void ccCommonCompile_codeGenModuleActionExecutesOnFirstPlatform() throws " attrs = {", " 'srcs': attr.label_list(allow_files = ['.cc']),", " 'hdrs': attr.label_list(allow_files = ['.h']),", - " '_cc_toolchain': attr.label(default=Label('//bazel_internal/test_rules/cc:alias')),", " },", " toolchains = ['//rule:toolchain_type_2'] + _use_cpp_toolchain(),", " fragments = ['cpp']", @@ -2052,7 +2041,6 @@ public void ccCommonCompile_codeGenModuleActionExecutesOnFirstPlatform() throws scratch.file( "bazel_internal/test_rules/cc/BUILD", "load('//bazel_internal/test_rules/cc:defs.bzl', 'custom_rule')", - "cc_toolchain_alias(name='alias')", "custom_rule(", " name = 'custom_rule_name',", " srcs = ['custom.cc'],", @@ -2061,13 +2049,14 @@ public void ccCommonCompile_codeGenModuleActionExecutesOnFirstPlatform() throws useConfiguration( "--incompatible_auto_exec_groups", "--features=header_modules", - "--features=header_module_codegen", - "--noincompatible_enable_cc_toolchain_resolution"); + "--features=header_module_codegen"); AnalysisMock.get() .ccSupport() .setupCcToolchainConfig( mockToolsConfig, - CcToolchainConfig.builder().withFeatures(MockCcSupport.HEADER_MODULES_FEATURES)); + CcToolchainConfig.builder().withFeatures(MockCcSupport.HEADER_MODULES_FEATURES) + .withToolchainTargetConstraints("@//platforms:constraint_1") + .withToolchainExecConstraints("@//platforms:constraint_1")); ImmutableList cppCompileActions = getActions("//bazel_internal/test_rules/cc:custom_rule_name", CppCompileAction.class); @@ -2092,7 +2081,7 @@ public void ccCommonCompile_compileHeaderActionExecutesOnFirstPlatform() throws + "', mandatory = False),", " ]", "def _impl(ctx):", - " cc_toolchain = ctx.attr._cc_toolchain[cc_common.CcToolchainInfo]", + " cc_toolchain = ctx.toolchains['" + TestConstants.CPP_TOOLCHAIN_TYPE + "'].cc", " feature_configuration = cc_common.configure_features(", " ctx = ctx,", " cc_toolchain = cc_toolchain,", @@ -2113,7 +2102,6 @@ public void ccCommonCompile_compileHeaderActionExecutesOnFirstPlatform() throws " attrs = {", " 'srcs': attr.label_list(allow_files = ['.cc']),", " 'hdrs': attr.label_list(allow_files = ['.h']),", - " '_cc_toolchain': attr.label(default=Label('//bazel_internal/test_rules/cc:alias')),", " },", " toolchains = ['//rule:toolchain_type_2'] + _use_cpp_toolchain(),", " fragments = ['cpp']", @@ -2121,18 +2109,19 @@ public void ccCommonCompile_compileHeaderActionExecutesOnFirstPlatform() throws scratch.file( "bazel_internal/test_rules/cc/BUILD", "load('//bazel_internal/test_rules/cc:defs.bzl', 'custom_rule')", - "cc_toolchain_alias(name='alias')", "custom_rule(", " name = 'custom_rule_name',", " srcs = ['custom.cc'],", " hdrs = ['custom.h'],", ")"); - useConfiguration("--incompatible_auto_exec_groups", "--features=parse_headers", "--noincompatible_enable_cc_toolchain_resolution"); + useConfiguration("--incompatible_auto_exec_groups", "--features=parse_headers"); AnalysisMock.get() .ccSupport() .setupCcToolchainConfig( mockToolsConfig, - CcToolchainConfig.builder().withFeatures(CppRuleClasses.PARSE_HEADERS)); + CcToolchainConfig.builder().withFeatures(CppRuleClasses.PARSE_HEADERS) + .withToolchainTargetConstraints("@//platforms:constraint_1") + .withToolchainExecConstraints("@//platforms:constraint_1")); ImmutableList cppCompileActions = getActions("//bazel_internal/test_rules/cc:custom_rule_name", CppCompileAction.class); @@ -2171,7 +2160,7 @@ public void ccCommonCompile_treeArtifactActionExecutesOnFirstPlatform() throws E " return [DefaultInfo(files = depset([tree]))]", "create_tree_artifact = rule(implementation = _ta_impl)", "def _impl(ctx):", - " cc_toolchain = ctx.attr._cc_toolchain[cc_common.CcToolchainInfo]", + " cc_toolchain = ctx.toolchains['" + TestConstants.CPP_TOOLCHAIN_TYPE + "'].cc", " feature_configuration = cc_common.configure_features(", " ctx = ctx,", " cc_toolchain = cc_toolchain,", @@ -2190,7 +2179,6 @@ public void ccCommonCompile_treeArtifactActionExecutesOnFirstPlatform() throws E " implementation = _impl,", " attrs = {", " 'srcs': attr.label_list(allow_files = ['.cc']),", - " '_cc_toolchain': attr.label(default=Label('//test:alias')),", " },", " toolchains = ['//rule:toolchain_type_2'] + _use_cpp_toolchain(),", " fragments = ['cpp']", @@ -2199,7 +2187,6 @@ public void ccCommonCompile_treeArtifactActionExecutesOnFirstPlatform() throws E "test/BUILD", "package(default_visibility = ['//visibility:public'])", "load('//test:defs.bzl', 'custom_rule', 'create_tree_artifact')", - "cc_toolchain_alias(name='alias')", "create_tree_artifact(name = 'tree_artifact')", "custom_rule(", " name = 'custom_rule_name',",