diff options
author | hlopko <hlopko@google.com> | 2018-03-05 06:10:32 -0800 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-03-05 06:11:59 -0800 |
commit | c0e4387c1d35ab589a5456f0d5e1fd1696596714 (patch) | |
tree | b44198c69a31ec7e661d695c18821192acc40699 | |
parent | 6144f2ae0852d030e1cc489b04d80b6256e5fba1 (diff) |
Add experimental_drop_fully_static_linking_mode
When this option is set to true, then bazel will not scan linkopts for -static
and will therefore never set linking mode to fully_static. This option will be
used to flip the switch once the world is migrated away from fully static
linking mode.
RELNOTES: C++: Introduced --experimental_drop_fully_static_linking_mode
Fully static linking mode will be removed soon. This option allows you to test
if your build will be passing.
Strategy for migrating away from fully static linking mode is to define a
crosstool feature named `fully_static_link`, enable it from the target (by
adding `features = [ "fully_static_link" ]`), and make sure the target is build
with `linkstatic = 1`. Buildozer command that will do just that is:
buildozer 'remove linkopts -static' 'set linkstatic 1' 'add features fully_static_link' //foo:bar
PiperOrigin-RevId: 187856775
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", |