Skip to content

Commit

Permalink
Add automatic exec groups to cc_common.link
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 514332514
Change-Id: I5ea3b2fa70a858c8d206a36ede1eec02fb344bf2
  • Loading branch information
kotlaja authored and copybara-github committed Mar 6, 2023
1 parent 6249719 commit 8681437
Show file tree
Hide file tree
Showing 8 changed files with 326 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ private BazelCppSemantics(Language language) {
this.language = language;
}

private static final String CPP_TOOLCHAIN_TYPE = "@bazel_tools//tools/cpp:toolchain_type";

@Override
public String getCppToolchainType() {
return CPP_TOOLCHAIN_TYPE;
}

@Override
public Language language() {
return language;
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/com/google/devtools/build/lib/rules/cpp/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,7 @@ java_library(
"//src/main/java/com/google/devtools/build/lib/analysis:platform_configuration",
"//src/main/java/com/google/devtools/build/lib/analysis:rule_definition_environment",
"//src/main/java/com/google/devtools/build/lib/analysis:starlark/args",
"//src/main/java/com/google/devtools/build/lib/analysis:starlark/starlark_api_provider",
"//src/main/java/com/google/devtools/build/lib/analysis:statically_linked_marker_provider",
"//src/main/java/com/google/devtools/build/lib/analysis:template_variable_info",
"//src/main/java/com/google/devtools/build/lib/analysis:test/instrumented_files_info",
"//src/main/java/com/google/devtools/build/lib/analysis:transitive_info_collection",
"//src/main/java/com/google/devtools/build/lib/analysis:transitive_info_provider",
"//src/main/java/com/google/devtools/build/lib/analysis:workspace_status_action",
Expand All @@ -91,6 +88,7 @@ java_library(
"//src/main/java/com/google/devtools/build/lib/events",
"//src/main/java/com/google/devtools/build/lib/exec:spawn_strategy_resolver",
"//src/main/java/com/google/devtools/build/lib/packages",
"//src/main/java/com/google/devtools/build/lib/packages:exec_group",
"//src/main/java/com/google/devtools/build/lib/packages/semantics",
"//src/main/java/com/google/devtools/build/lib/profiler",
"//src/main/java/com/google/devtools/build/lib/rules:alias",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1159,8 +1159,21 @@ public static ImmutableMap<Linkstamp, Artifact> mapLinkstampsToOutputs(
}

protected ActionOwner getOwner() {
ActionOwner execGroupOwner = actionConstructionContext.getActionOwner(CPP_LINK_EXEC_GROUP);
return execGroupOwner == null ? actionConstructionContext.getActionOwner() : execGroupOwner;
ActionOwner cppLinkExecGroupOwner =
actionConstructionContext.getActionOwner(CPP_LINK_EXEC_GROUP);
if (cppLinkExecGroupOwner != null) {
return cppLinkExecGroupOwner;
}

if (((RuleContext) actionConstructionContext).useAutoExecGroups()) {
ActionOwner autoExecGroupOwner =
actionConstructionContext.getActionOwner(cppSemantics.getCppToolchainType());
return autoExecGroupOwner == null
? actionConstructionContext.getActionOwner()
: autoExecGroupOwner;
}

return actionConstructionContext.getActionOwner();
}

/** Sets the mnemonic for the link action. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import static com.google.devtools.build.lib.rules.cpp.CppFileTypes.VERSIONED_SHARED_LIBRARY;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableMap;
import com.google.devtools.build.lib.analysis.RuleDefinition;
import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment;
import com.google.devtools.build.lib.analysis.config.ExecutionTransitionFactory;
Expand All @@ -41,6 +42,7 @@
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.packages.Attribute.LabelLateBoundDefault;
import com.google.devtools.build.lib.packages.Attribute.LateBoundDefault.Resolver;
import com.google.devtools.build.lib.packages.ExecGroup;
import com.google.devtools.build.lib.packages.ImplicitOutputsFunction.SafeImplicitOutputsFunction;
import com.google.devtools.build.lib.packages.RuleClass;
import com.google.devtools.build.lib.packages.RuleClass.Builder.RuleClassType;
Expand Down Expand Up @@ -554,7 +556,12 @@ public Metadata getMetadata() {
public static final class CcLinkingRule implements RuleDefinition {
@Override
public RuleClass build(RuleClass.Builder builder, RuleDefinitionEnvironment env) {
return builder.addExecGroup(CPP_LINK_EXEC_GROUP).build();
return builder
.addExecGroups(
ImmutableMap.of(
CPP_LINK_EXEC_GROUP,
ExecGroup.builder().addToolchainType(ccToolchainTypeRequirement(env)).build()))
.build();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@

/** Pluggable C++ compilation semantics. */
public interface CppSemantics extends StarlarkValue {

/** Returns cpp toolchain type. */
String getCppToolchainType();

/** What language to treat the headers. */
Language language();

Expand Down
Loading

0 comments on commit 8681437

Please sign in to comment.