diff options
5 files changed, 43 insertions, 1 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 9d96ba2716..351644e91a 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 @@ -623,6 +623,9 @@ public abstract class CcBinary implements RuleConfiguredTargetFactory { private static final boolean dashStaticInLinkopts(List<String> linkopts, CppConfiguration cppConfiguration) { + if (cppConfiguration.dropFullyStaticLinkingMode()) { + return false; + } return linkopts.contains("-static") || cppConfiguration.hasStaticLinkOption(); } diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppActionConfigs.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppActionConfigs.java index dd39fe24c3..3f06465378 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppActionConfigs.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppActionConfigs.java @@ -1026,6 +1026,18 @@ public class CppActionConfigs { .join( ImmutableList.of( ifTrue( + !existingFeatureNames.contains("fully_static_link"), + "feature {", + " name: 'fully_static_link'", + " flag_set {", + " action: 'c++-link-executable'", + " action: 'c++-link-dynamic-library'", + " flag_group {", + " flag: '-static'", + " }", + " }", + "}"), + ifTrue( !existingFeatureNames.contains("user_compile_flags"), "feature {", " name: 'user_compile_flags'", diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java index ba4c6202e4..7423d785a0 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java @@ -196,6 +196,8 @@ public final class CppConfiguration extends BuildConfiguration.Fragment { private final CompilationMode compilationMode; private final boolean shouldProvideMakeVariables; + private final boolean dropFullyStaticLinkingMode; + /** * If true, the ConfiguredTarget is only used to get the necessary cross-referenced {@code @@ -317,6 +319,7 @@ public final class CppConfiguration extends BuildConfiguration.Fragment { && compilationMode == CompilationMode.FASTBUILD)), compilationMode, params.commonOptions.makeVariableSource == MakeVariableSource.CONFIGURATION, + cppOptions.dropFullyStaticLinkingMode, cppOptions.isLipoContextCollector(), cppToolchainInfo); } @@ -351,6 +354,7 @@ public final class CppConfiguration extends BuildConfiguration.Fragment { boolean stripBinaries, CompilationMode compilationMode, boolean shouldProvideMakeVariables, + boolean dropFullyStaticLinkingMode, boolean lipoContextCollector, CppToolchainInfo cppToolchainInfo) { this.crosstoolTop = crosstoolTop; @@ -381,6 +385,7 @@ public final class CppConfiguration extends BuildConfiguration.Fragment { this.stripBinaries = stripBinaries; this.compilationMode = compilationMode; this.shouldProvideMakeVariables = shouldProvideMakeVariables; + this.dropFullyStaticLinkingMode = dropFullyStaticLinkingMode; this.lipoContextCollector = lipoContextCollector; this.cppToolchainInfo = cppToolchainInfo; } @@ -700,6 +705,9 @@ public final class CppConfiguration extends BuildConfiguration.Fragment { } public boolean hasStaticLinkOption() { + if (dropFullyStaticLinkingMode()) { + return false; + } return linkOptions.contains("-static"); } @@ -867,6 +875,10 @@ public final class CppConfiguration extends BuildConfiguration.Fragment { return convertLipoToThinLto; } + public boolean dropFullyStaticLinkingMode() { + return dropFullyStaticLinkingMode; + } + public boolean isFdo() { return cppOptions.isFdo(); } diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java index 0aa8e4de93..0ca8887dd7 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java @@ -969,7 +969,10 @@ public class CppHelper { public static void maybeAddStaticLinkMarkerProvider(RuleConfiguredTargetBuilder builder, RuleContext ruleContext) { boolean staticallyLinked = false; - if (ruleContext.getFragment(CppConfiguration.class).hasStaticLinkOption()) { + CppConfiguration cppConfiguration = ruleContext.getFragment(CppConfiguration.class); + if (ruleContext.getFeatures().contains("fully_static_link")) { + staticallyLinked = true; + } else if (cppConfiguration.hasStaticLinkOption()) { staticallyLinked = true; } else if (ruleContext.attributes().has("linkopts", Type.STRING_LIST) && ruleContext.attributes().get("linkopts", Type.STRING_LIST).contains("-static")) { diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppOptions.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppOptions.java index f544e1538d..9a57d6ad8f 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppOptions.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppOptions.java @@ -257,6 +257,18 @@ public class CppOptions extends FragmentOptions { public DynamicMode dynamicMode; @Option( + name = "experimental_drop_fully_static_linking_mode", + defaultValue = "false", + category = "semantics", + documentationCategory = OptionDocumentationCategory.UNDOCUMENTED, + effectTags = {OptionEffectTag.LOADING_AND_ANALYSIS, OptionEffectTag.AFFECTS_OUTPUTS}, + help = + "If enabled, bazel will not scan linkopts for -static. Rules have to define their fully" + + " static linking mode through 'link_fully_static_binary' feature." + ) + public boolean dropFullyStaticLinkingMode; + + @Option( name = "experimental_link_compile_output_separately", defaultValue = "false", category = "semantics", |