diff options
Diffstat (limited to 'cc/library.go')
| -rw-r--r-- | cc/library.go | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/cc/library.go b/cc/library.go index 266fa7511..df1dbc5b4 100644 --- a/cc/library.go +++ b/cc/library.go @@ -32,6 +32,20 @@ import ( "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 @@ func libraryBp2Build(ctx android.TopDownMutatorContext, m *Module) { 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) @@ -2951,6 +2969,10 @@ func sharedOrStaticLibraryBp2Build(ctx android.TopDownMutatorContext, module *Mo 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, @@ -2964,8 +2986,10 @@ func sharedOrStaticLibraryBp2Build(ctx android.TopDownMutatorContext, module *Mo Conlyflags: compilerAttrs.conlyFlags, Asflags: asFlags, - Features: *features, + Alwayslink: alwayslink, + Features: *features, } + } else { commonAttrs.Dynamic_deps.Add(baseAttributes.protoDependency) @@ -3047,7 +3071,8 @@ type bazelCcLibraryStaticAttributes struct { 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? |