aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar hlopko <hlopko@google.com>2018-03-09 07:38:39 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2018-03-09 07:40:07 -0800
commit4764d70ee774961b912ae75b0ea3991276221706 (patch)
treeab21583d5234c66c8c0b6ddc737a5908e4eba907 /src
parent7cbe1fbd138facf1c7e70c677e4101d8e7b31900 (diff)
Enable static_linking_mode or dynamic_linking_mode features from cc_binary
RELNOTES: CppRules: cc_binary/cc_test now enable 'static_linking_mode' or 'dynamic_linking_mode'. PiperOrigin-RevId: 188482267
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java24
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CppRuleClasses.java6
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/nativedeps/NativeDepsHelper.java9
3 files changed, 31 insertions, 8 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java
index 36c281f4db..845ee1f3f9 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java
@@ -13,6 +13,9 @@
// limitations under the License.
package com.google.devtools.build.lib.rules.cpp;
+import static com.google.devtools.build.lib.rules.cpp.CppRuleClasses.DYNAMIC_LINKING_MODE;
+import static com.google.devtools.build.lib.rules.cpp.CppRuleClasses.STATIC_LINKING_MODE;
+
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function;
import com.google.common.base.Preconditions;
@@ -182,10 +185,6 @@ public abstract class CcBinary implements RuleConfiguredTargetFactory {
} else {
ruleContext.initConfigurationMakeVariableContext(new CcFlagsSupplier(ruleContext));
}
-
- FdoSupportProvider fdoSupport = common.getFdoSupport();
- FeatureConfiguration featureConfiguration =
- CcCommon.configureFeatures(ruleContext, ccToolchain);
CppConfiguration cppConfiguration = ruleContext.getFragment(CppConfiguration.class);
PrecompiledFiles precompiledFiles = new PrecompiledFiles(ruleContext);
LinkTargetType linkType =
@@ -213,6 +212,20 @@ public abstract class CcBinary implements RuleConfiguredTargetFactory {
return null;
}
+ List<String> linkopts = common.getLinkopts();
+ LinkStaticness linkStaticness =
+ getLinkStaticness(ruleContext, linkopts, cppConfiguration, ccToolchain);
+ FdoSupportProvider fdoSupport = common.getFdoSupport();
+ FeatureConfiguration featureConfiguration =
+ CcCommon.configureFeatures(
+ ruleContext,
+ /* requestedFeatures= */ ImmutableSet.of(
+ linkStaticness == LinkStaticness.DYNAMIC
+ ? DYNAMIC_LINKING_MODE
+ : STATIC_LINKING_MODE),
+ /* unsupportedFeatures= */ ImmutableSet.of(),
+ ccToolchain);
+
CcCompilationHelper compilationHelper =
new CcCompilationHelper(
ruleContext, semantics, featureConfiguration, ccToolchain, fdoSupport)
@@ -225,9 +238,6 @@ public abstract class CcBinary implements RuleConfiguredTargetFactory {
CcCompilationInfo ccCompilationInfo = compilationInfo.getCcCompilationInfo();
CcCompilationOutputs ccCompilationOutputs = compilationInfo.getCcCompilationOutputs();
- List<String> linkopts = common.getLinkopts();
- LinkStaticness linkStaticness =
- getLinkStaticness(ruleContext, linkopts, cppConfiguration, ccToolchain);
// We currently only want link the dynamic library generated for test code separately.
boolean linkCompileOutputSeparately =
ruleContext.isTestTarget()
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppRuleClasses.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppRuleClasses.java
index 0aacc00a01..2525eb588d 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppRuleClasses.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppRuleClasses.java
@@ -266,6 +266,12 @@ public class CppRuleClasses {
*/
public static final String INCLUDE_PATHS = "include_paths";
+ /** A string constant for the feature signalling static linking mode. */
+ public static final String STATIC_LINKING_MODE = "static_linking_mode";
+
+ /** A string constant for the feature signalling dynamic linking mode. */
+ public static final String DYNAMIC_LINKING_MODE = "dynamic_linking_mode";
+
/**
* A string constant for the ThinLTO feature.
*/
diff --git a/src/main/java/com/google/devtools/build/lib/rules/nativedeps/NativeDepsHelper.java b/src/main/java/com/google/devtools/build/lib/rules/nativedeps/NativeDepsHelper.java
index e15c7485a3..729ac2b75d 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/nativedeps/NativeDepsHelper.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/nativedeps/NativeDepsHelper.java
@@ -14,6 +14,8 @@
package com.google.devtools.build.lib.rules.nativedeps;
+import static com.google.devtools.build.lib.rules.cpp.CppRuleClasses.STATIC_LINKING_MODE;
+
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
@@ -216,7 +218,12 @@ public abstract class NativeDepsHelper {
}
FdoSupportProvider fdoSupport =
CppHelper.getFdoSupportUsingDefaultCcToolchainAttribute(ruleContext);
- FeatureConfiguration featureConfiguration = CcCommon.configureFeatures(ruleContext, toolchain);
+ FeatureConfiguration featureConfiguration =
+ CcCommon.configureFeatures(
+ ruleContext,
+ /* requestedFeatures= */ ImmutableSet.of(STATIC_LINKING_MODE),
+ /* unsupportedFeatures= */ ImmutableSet.of(),
+ toolchain);
CppLinkActionBuilder builder =
new CppLinkActionBuilder(
ruleContext,