diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionBuilder.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionBuilder.java index aa32ea8e6efcb3..e2e61c0517168f 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionBuilder.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionBuilder.java @@ -1077,6 +1077,11 @@ private static boolean needWholeArchive( // is not needed). return false; } + if (featureConfiguration + .getRequestedFeatures() + .contains(CppRuleClasses.FORCE_NO_WHOLE_ARCHIVE)) { + return false; + } if (cppConfig.removeLegacyWholeArchive()) { // --incompatible_remove_legacy_whole_archive has been flipped, no --whole-archive for the // entire build. 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 967055de10b0d3..c21de5d26a2096 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 @@ -461,6 +461,9 @@ public static ToolchainTypeRequirement ccToolchainTypeRequirement(RuleDefinition /** A feature marking that the target needs to link its deps in --whole-archive block. */ public static final String LEGACY_WHOLE_ARCHIVE = "legacy_whole_archive"; + /** A feature for force disabling whole-archive on a per target and per rule type basis. */ + public static final String FORCE_NO_WHOLE_ARCHIVE = "force_no_whole_archive"; + /** * A feature marking that the target generates libraries that should not be put in a * --whole-archive block. diff --git a/src/main/starlark/builtins_bzl/common/cc/experimental_cc_shared_library.bzl b/src/main/starlark/builtins_bzl/common/cc/experimental_cc_shared_library.bzl index 2c2070c8eca170..bd4b0e843e0259 100644 --- a/src/main/starlark/builtins_bzl/common/cc/experimental_cc_shared_library.bzl +++ b/src/main/starlark/builtins_bzl/common/cc/experimental_cc_shared_library.bzl @@ -398,7 +398,7 @@ def _cc_shared_library_impl(ctx): feature_configuration = cc_common.configure_features( ctx = ctx, cc_toolchain = cc_toolchain, - requested_features = ctx.features, + requested_features = ctx.features + ["force_no_whole_archive"], unsupported_features = ctx.disabled_features, )