Skip to content

Commit

Permalink
Make cc_toolchain_suite a no-op
Browse files Browse the repository at this point in the history
Remove cc_toolchain_suite from Bazel's unit tests.

The rule cc_toolchain_suite doesn't participate in toolchain resolution anymore. It may be used in cc_library.toolchains or genrule.toolchains, where a simple replacement with //tools/cpp:current_cc_toolchain works.

Removing the rule is an incompatible change (because transitions depend on the label value). That will require a cleanup. That's why making it a no-op first.
RELNOTES[INC]: cc_toolchain_suite is a no op rule (#7260).

PiperOrigin-RevId: 588364153
Change-Id: I3502554628c442ddf38b52cb949bdaa128e641e9
  • Loading branch information
comius authored and copybara-github committed Dec 6, 2023
1 parent e116bae commit 2e3903c
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 417 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import com.google.devtools.build.lib.bazel.rules.cpp.BazelCcTestRule;
import com.google.devtools.build.lib.bazel.rules.cpp.BazelCppRuleClasses;
import com.google.devtools.build.lib.bazel.rules.cpp.BazelCppRuleClasses.CcToolchainRequiringRule;
import com.google.devtools.build.lib.rules.apple.AppleConfiguration;
import com.google.devtools.build.lib.rules.core.CoreRules;
import com.google.devtools.build.lib.rules.cpp.CcImportRule;
import com.google.devtools.build.lib.rules.cpp.CcInfo;
Expand Down Expand Up @@ -66,11 +65,6 @@ private CcRules() {
@Override
public void init(ConfiguredRuleClassProvider.Builder builder) {
BazelCcModule bazelCcModule = new BazelCcModule();
// TODO(gnish): This is only required for cc_toolchain_suite rule,
// because it does not have AppleConfiguration fragment.
// After legacy C++ toolchain resolution is removed the rule is going away
// and we should delete this.
builder.addConfigurationFragment(AppleConfiguration.class);
builder.addConfigurationFragment(CppConfiguration.class);
builder.addBzlToplevel("CcSharedLibraryInfo", Starlark.NONE);
builder.addBzlToplevel("CcSharedLibraryHintInfo", Starlark.NONE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,12 @@ private static String createBuildFile(
String ruleName, String defaultCrosstool, List<CrosstoolStlPair> crosstools) {

String buildFileTemplate = getTemplate("android_ndk_build_file_template.txt");
String ccToolchainSuiteTemplate = getTemplate("android_ndk_cc_toolchain_suite_template.txt");
String ccToolchainTemplate = getTemplate("android_ndk_cc_toolchain_template.txt");
String stlFilegroupTemplate = getTemplate("android_ndk_stl_filegroup_template.txt");
String vulkanValidationLayersTemplate =
getTemplate("android_ndk_vulkan_validation_layers_template.txt");
String miscLibrariesTemplate = getTemplate("android_ndk_misc_libraries_template.txt");

StringBuilder ccToolchainSuites = new StringBuilder();
StringBuilder ccToolchainRules = new StringBuilder();
StringBuilder stlFilegroups = new StringBuilder();
StringBuilder vulkanValidationLayers = new StringBuilder();
Expand All @@ -116,14 +114,6 @@ private static String createBuildFile(
toolchain.getToolchainIdentifier()));
}

String toolchainName = createToolchainName(crosstoolStlPair.stlImpl.getName());

ccToolchainSuites.append(
ccToolchainSuiteTemplate
.replace("%toolchainName%", toolchainName)
.replace("%toolchainMap%", toolchainMap.toString().trim())
.replace("%crosstoolReleaseProto%", crosstool.toString()));

// Create the cc_toolchain rules
for (CToolchain toolchain : crosstool.getToolchainList()) {
ccToolchainRules.append(
Expand Down Expand Up @@ -153,7 +143,6 @@ private static String createBuildFile(
return buildFileTemplate
.replace("%ruleName%", ruleName)
.replace("%defaultCrosstool%", "//:toolchain-" + defaultCrosstool)
.replace("%ccToolchainSuites%", ccToolchainSuites)
.replace("%ccToolchainRules%", ccToolchainRules)
.replace("%stlFilegroups%", stlFilegroups)
.replace("%vulkanValidationLayers%", vulkanValidationLayers)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@ alias(
actual = "%defaultCrosstool%",
)

################################################################
# cc toolchain suite rules (one for each STL in the NDK)
################################################################

%ccToolchainSuites%

################################################################
# cc toolchain rules
################################################################
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -189,16 +189,6 @@ public List<Pair<Artifact, Label>> getHeaders() {
return getHeaders(ruleContext);
}

public static void reportInvalidOptions(
RuleContext ruleContext, CppConfiguration cppConfiguration, CcToolchainProvider ccToolchain) {
if (cppConfiguration.getLibcTopLabel() != null && ccToolchain.getDefaultSysroot() == null) {
ruleContext.ruleError(
"The selected toolchain "
+ ccToolchain.getToolchainIdentifier()
+ " does not support setting --grte_top (it doesn't specify builtin_sysroot).");
}
}

/**
* Supply CC_FLAGS Make variable value computed from FeatureConfiguration. Appends them to
* original CC_FLAGS, so FeatureConfiguration can override legacy values.
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,19 @@
package com.google.devtools.build.lib.rules.cpp;

import static com.google.devtools.build.lib.packages.Attribute.attr;
import static com.google.devtools.build.lib.packages.BuildType.NODEP_LABEL;

import com.google.devtools.build.lib.analysis.BaseRuleClasses;
import com.google.devtools.build.lib.actions.MutableActionGraph.ActionConflictException;
import com.google.devtools.build.lib.analysis.BaseRuleClasses.NativeBuildRule;
import com.google.devtools.build.lib.analysis.ConfiguredTarget;
import com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder;
import com.google.devtools.build.lib.analysis.RuleConfiguredTargetFactory;
import com.google.devtools.build.lib.analysis.RuleContext;
import com.google.devtools.build.lib.analysis.RuleDefinition;
import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment;
import com.google.devtools.build.lib.analysis.Runfiles;
import com.google.devtools.build.lib.analysis.RunfilesProvider;
import com.google.devtools.build.lib.packages.BuildType;
import com.google.devtools.build.lib.packages.RuleClass;
import com.google.devtools.build.lib.rules.apple.AppleConfiguration;
import com.google.devtools.build.lib.util.FileTypeSet;

/**
Expand All @@ -32,66 +37,37 @@ public final class CcToolchainSuiteRule implements RuleDefinition {
@Override
public RuleClass build(RuleClass.Builder builder, RuleDefinitionEnvironment environment) {
return builder
.requiresConfigurationFragments(CppConfiguration.class, AppleConfiguration.class)
/* <!-- #BLAZE_RULE(cc_toolchain_suite).ATTRIBUTE(toolchains) -->
A map from "&lt;cpu&gt;" or "&lt;cpu&gt;|&lt;compiler&gt;" strings to
a <code>cc_toolchain</code> label. "&lt;cpu&gt;" will be used when only <code>--cpu</code>
is passed to Bazel, and "&lt;cpu&gt;|&lt;compiler&gt;" will be used when both
<code>--cpu</code> and <code>--compiler</code> are passed to Bazel. Example:
<p>
<pre>
cc_toolchain_suite(
name = "toolchain",
toolchains = {
"piii|gcc": ":my_cc_toolchain_for_piii_using_gcc",
"piii": ":my_cc_toolchain_for_piii_using_default_compiler",
},
)
</pre>
</p>
<!-- #END_BLAZE_RULE.ATTRIBUTE -->*/
.add(
attr("toolchains", BuildType.LABEL_DICT_UNARY)
.mandatory()
.allowedFileTypes(FileTypeSet.NO_FILE)
.nonconfigurable("Used during configuration creation"))
.add(
attr(CcToolchainRule.CC_TOOLCHAIN_TYPE_ATTRIBUTE_NAME, NODEP_LABEL)
.value(CppRuleClasses.ccToolchainTypeAttribute(environment)))
.build();
}

@Override
public Metadata getMetadata() {
return RuleDefinition.Metadata.builder()
return Metadata.builder()
.name("cc_toolchain_suite")
.ancestors(BaseRuleClasses.NativeBuildRule.class)
.ancestors(NativeBuildRule.class)
.factoryClass(CcToolchainSuite.class)
.build();
}

/** A noop rule factory, just used for compatibility. */
public static final class CcToolchainSuite implements RuleConfiguredTargetFactory {
@Override
public ConfiguredTarget create(RuleContext ruleContext)
throws InterruptedException, ActionConflictException {
ruleContext.ruleWarning("Rule is a no-op.");
return new RuleConfiguredTargetBuilder(ruleContext)
.addProvider(RunfilesProvider.simple(Runfiles.EMPTY))
.build();
}
}
}

/*<!-- #BLAZE_RULE (NAME = cc_toolchain_suite, TYPE = OTHER, FAMILY = C / C++) -->
<p>Represents a collections of C++ toolchains.</p>
<p>
This rule is responsible for:
<ul>
<li>Collecting all relevant C++ toolchains.</li>
<li>
Selecting one toolchain depending on <code>--cpu</code> and <code>--compiler</code> options
passed to Bazel.
</li>
</ul>
</p>
<p>
See also this
<a href="https://bazel.build/docs/cc-toolchain-config-reference">
page
</a> for elaborate C++ toolchain configuration and toolchain selection documentation.
</p>
<p>Deprecated: the rule is a no-op and will be removed.
<!-- #END_BLAZE_RULE -->*/
Loading

0 comments on commit 2e3903c

Please sign in to comment.