Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flip --incompatible_enable_cc_toolchain_resolution #19441

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,",
Expand All @@ -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");

Expand All @@ -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,",
Expand All @@ -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()),",
" },",
Expand All @@ -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");

Expand All @@ -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,",
Expand All @@ -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()),",
" },",
Expand All @@ -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");

Expand All @@ -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,",
Expand All @@ -1793,15 +1787,13 @@ 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']",
")");
scratch.file(
"test/BUILD",
"load('//test:defs.bzl', 'custom_rule')",
"cc_toolchain_alias(name='alias')",
"cc_library(",
" name = 'dep',",
" srcs = ['dep.cc'],",
Expand All @@ -1817,7 +1809,9 @@ public void ccCommonLink_cppLTOActionExecutesOnFirstPlatform() throws Exception
.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<Action> actions = getActions("//test:custom_rule_name", CppLinkAction.class);
ImmutableList<Action> cppLTOActions =
Expand All @@ -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,",
Expand All @@ -1861,15 +1855,13 @@ 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']",
")");
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',",
Expand Down Expand Up @@ -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,",
Expand All @@ -1919,15 +1911,13 @@ 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']",
")");
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'],",
Expand Down Expand Up @@ -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,",
Expand All @@ -1977,15 +1967,13 @@ 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']",
")");
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'],",
Expand All @@ -1996,7 +1984,9 @@ public void ccCommonCompile_moduleActionsExecuteOnFirstPlatform() throws Excepti
.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<Action> cppCompileActions =
getActions("//bazel_internal/test_rules/cc:custom_rule_name", CppCompileAction.class);
Expand All @@ -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,",
Expand All @@ -2044,15 +2034,13 @@ 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']",
")");
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'],",
Expand All @@ -2066,7 +2054,9 @@ public void ccCommonCompile_codeGenModuleActionExecutesOnFirstPlatform() throws
.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<Action> cppCompileActions =
getActions("//bazel_internal/test_rules/cc:custom_rule_name", CppCompileAction.class);
Expand All @@ -2091,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,",
Expand All @@ -2112,15 +2102,13 @@ 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']",
")");
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'],",
Expand All @@ -2131,7 +2119,9 @@ public void ccCommonCompile_compileHeaderActionExecutesOnFirstPlatform() throws
.ccSupport()
.setupCcToolchainConfig(
mockToolsConfig,
CcToolchainConfig.builder().withFeatures(CppRuleClasses.PARSE_HEADERS));
CcToolchainConfig.builder().withFeatures(CppRuleClasses.PARSE_HEADERS)
.withToolchainTargetConstraints("@//platforms:constraint_1")
.withToolchainExecConstraints("@//platforms:constraint_1"));

ImmutableList<Action> cppCompileActions =
getActions("//bazel_internal/test_rules/cc:custom_rule_name", CppCompileAction.class);
Expand Down Expand Up @@ -2170,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,",
Expand All @@ -2189,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']",
Expand All @@ -2198,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',",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,",
Expand Down Expand Up @@ -5795,14 +5798,18 @@ 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 = []",
" dep_linking_contexts = []",
" 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,",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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,",
Expand Down Expand Up @@ -6406,6 +6417,7 @@ private static void createCcBinRule(
" 'additional_outputs': attr.output_list(),",
" },",
fragments,
" toolchains = ['@bazel_tools//tools/cpp:toolchain_type']",
")");
}

Expand Down Expand Up @@ -8175,14 +8187,19 @@ 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 = {",
" '_cc_toolchain': attr.label(default =",
" configuration_field(fragment = 'cpp', name = 'cc_toolchain')),",
" },",
" fragments = ['cpp'],",
" toolchains = ['@bazel_tools//tools/cpp:toolchain_type']",
")");

ConfiguredTarget target = getConfiguredTarget("//foo:skylark_lib");
Expand Down
Loading
Loading