Skip to content

Commit

Permalink
CC rules that use the :cc_toolchain attribute should also set up tool…
Browse files Browse the repository at this point in the history
…chain resolution.

Fixes Bazel's cc_import rule.

PiperOrigin-RevId: 360191200
  • Loading branch information
katre authored and copybara-github committed Mar 1, 2021
1 parent b0c1d0d commit 681232a
Showing 1 changed file with 5 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,41 +14,32 @@

package com.google.devtools.build.lib.bazel.rules.cpp;

import static com.google.devtools.build.lib.packages.Attribute.attr;
import static com.google.devtools.build.lib.packages.BuildType.LABEL;
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.analysis.RuleDefinition;
import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment;
import com.google.devtools.build.lib.bazel.rules.cpp.BazelCppRuleClasses.CcToolchainRequiringRule;
import com.google.devtools.build.lib.packages.RuleClass;
import com.google.devtools.build.lib.rules.cpp.CcImportRule;
import com.google.devtools.build.lib.rules.cpp.CcToolchain;
import com.google.devtools.build.lib.rules.cpp.CcToolchainProvider;
import com.google.devtools.build.lib.rules.cpp.CppConfiguration;
import com.google.devtools.build.lib.rules.cpp.CppRuleClasses;

/** Rule definition for the cc_import rule. */
public final class BazelCcImportRule implements RuleDefinition {
@Override
public RuleClass build(RuleClass.Builder builder, RuleDefinitionEnvironment env) {
return builder
.requiresConfigurationFragments(CppConfiguration.class)
.add(
attr(CcToolchain.CC_TOOLCHAIN_DEFAULT_ATTRIBUTE_NAME, LABEL)
.mandatoryProviders(CcToolchainProvider.PROVIDER.id())
.value(CppRuleClasses.ccToolchainAttribute(env)))
.add(
attr(CcToolchain.CC_TOOLCHAIN_TYPE_ATTRIBUTE_NAME, NODEP_LABEL)
.value(CppRuleClasses.ccToolchainTypeAttribute(env)))
.build();
}

@Override
public Metadata getMetadata() {
return RuleDefinition.Metadata.builder()
.name("cc_import")
.ancestors(BaseRuleClasses.NativeBuildRule.class, CcImportRule.class)
.ancestors(
BaseRuleClasses.NativeBuildRule.class,
CcImportRule.class,
CcToolchainRequiringRule.class)
.factoryClass(BazelCcImport.class)
.build();
}
Expand Down

0 comments on commit 681232a

Please sign in to comment.