Convert coverage libs as alwayslink
Bug: 291090629
Test: bp2build.sh and CI
Change-Id: I050a870b36b5bc84dbdbca73405e0a0fab1aef86
diff --git a/cc/library.go b/cc/library.go
index aec6433..0cdc9fa 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -32,6 +32,20 @@
"github.com/google/blueprint/proptools"
)
+var (
+ alwaysLinkLibraries = map[string]bool{
+ // Coverage libraries are _always_ added as a whole_static_dep. By converting as these as
+ // alwayslink = True, we can add these as to deps (e.g. as a regular static dep) in Bazel
+ // without any extra complications in cc_shared_library roots to prevent linking the same
+ // library repeatedly.
+ "libprofile-extras_ndk": true,
+ "libprofile-extras": true,
+ "libprofile-clang-extras_ndk": true,
+ "libprofile-clang-extras_cfi_support": true,
+ "libprofile-clang-extras": true,
+ }
+)
+
// LibraryProperties is a collection of properties shared by cc library rules/cc.
type LibraryProperties struct {
// local file name to pass to the linker as -unexported_symbols_list
@@ -435,6 +449,10 @@
Bzl_load_location: "//build/bazel/rules/cc:cc_library_shared.bzl",
}
+ if _, ok := alwaysLinkLibraries[m.Name()]; ok {
+ staticTargetAttrs.Alwayslink = proptools.BoolPtr(true)
+ }
+
var tagsForStaticVariant bazel.StringListAttribute
if compilerAttrs.stubsSymbolFile == nil && len(compilerAttrs.stubsVersions.Value) == 0 {
tagsForStaticVariant = android.ApexAvailableTagsWithoutTestApexes(ctx, m)
@@ -2947,6 +2965,10 @@
var attrs interface{}
if isStatic {
commonAttrs.Deps.Add(baseAttributes.protoDependency)
+ var alwayslink *bool
+ if _, ok := alwaysLinkLibraries[module.Name()]; ok && isStatic {
+ alwayslink = proptools.BoolPtr(true)
+ }
attrs = &bazelCcLibraryStaticAttributes{
staticOrSharedAttributes: commonAttrs,
Rtti: compilerAttrs.rtti,
@@ -2960,8 +2982,10 @@
Conlyflags: compilerAttrs.conlyFlags,
Asflags: asFlags,
- Features: *features,
+ Alwayslink: alwayslink,
+ Features: *features,
}
+
} else {
commonAttrs.Dynamic_deps.Add(baseAttributes.protoDependency)
@@ -3043,7 +3067,8 @@
Conlyflags bazel.StringListAttribute
Asflags bazel.StringListAttribute
- Features bazel.StringListAttribute
+ Alwayslink *bool
+ Features bazel.StringListAttribute
}
// TODO(b/199902614): Can this be factored to share with the other Attributes?