diff options
Diffstat (limited to 'cc')
| -rw-r--r-- | cc/bp2build.go | 89 | ||||
| -rw-r--r-- | cc/library.go | 83 |
2 files changed, 119 insertions, 53 deletions
diff --git a/cc/bp2build.go b/cc/bp2build.go index 67f88e26a..7d01986f1 100644 --- a/cc/bp2build.go +++ b/cc/bp2build.go @@ -85,7 +85,11 @@ func depsBp2BuildMutator(ctx android.BottomUpMutatorContext) { } type sharedAttributes struct { - staticDeps bazel.LabelListAttribute + copts bazel.StringListAttribute + srcs bazel.LabelListAttribute + staticDeps bazel.LabelListAttribute + dynamicDeps bazel.LabelListAttribute + wholeArchiveDeps bazel.LabelListAttribute } // bp2buildParseSharedProps returns the attributes for the shared variant of a cc_library. @@ -95,17 +99,35 @@ func bp2BuildParseSharedProps(ctx android.TopDownMutatorContext, module *Module) return sharedAttributes{} } - var staticDeps bazel.LabelListAttribute + copts := bazel.StringListAttribute{Value: lib.SharedProperties.Shared.Cflags} - staticDeps.Value = android.BazelLabelForModuleDeps(ctx, lib.SharedProperties.Shared.Whole_static_libs) + srcs := bazel.LabelListAttribute{ + Value: android.BazelLabelForModuleSrc(ctx, lib.SharedProperties.Shared.Srcs)} + + staticDeps := bazel.LabelListAttribute{ + Value: android.BazelLabelForModuleDeps(ctx, lib.SharedProperties.Shared.Static_libs)} + + dynamicDeps := bazel.LabelListAttribute{ + Value: android.BazelLabelForModuleDeps(ctx, lib.SharedProperties.Shared.Shared_libs)} + + wholeArchiveDeps := bazel.LabelListAttribute{ + Value: android.BazelLabelForModuleDeps(ctx, lib.SharedProperties.Shared.Whole_static_libs)} return sharedAttributes{ - staticDeps: staticDeps, + copts: copts, + srcs: srcs, + staticDeps: staticDeps, + dynamicDeps: dynamicDeps, + wholeArchiveDeps: wholeArchiveDeps, } } type staticAttributes struct { - srcs bazel.LabelListAttribute + copts bazel.StringListAttribute + srcs bazel.LabelListAttribute + staticDeps bazel.LabelListAttribute + dynamicDeps bazel.LabelListAttribute + wholeArchiveDeps bazel.LabelListAttribute } // bp2buildParseStaticProps returns the attributes for the static variant of a cc_library. @@ -115,11 +137,26 @@ func bp2BuildParseStaticProps(ctx android.TopDownMutatorContext, module *Module) return staticAttributes{} } - var srcs bazel.LabelListAttribute - srcs.Value = android.BazelLabelForModuleSrc(ctx, lib.StaticProperties.Static.Srcs) + copts := bazel.StringListAttribute{Value: lib.StaticProperties.Static.Cflags} + + srcs := bazel.LabelListAttribute{ + Value: android.BazelLabelForModuleSrc(ctx, lib.StaticProperties.Static.Srcs)} + + staticDeps := bazel.LabelListAttribute{ + Value: android.BazelLabelForModuleDeps(ctx, lib.StaticProperties.Static.Static_libs)} + + dynamicDeps := bazel.LabelListAttribute{ + Value: android.BazelLabelForModuleDeps(ctx, lib.StaticProperties.Static.Shared_libs)} + + wholeArchiveDeps := bazel.LabelListAttribute{ + Value: android.BazelLabelForModuleDeps(ctx, lib.StaticProperties.Static.Whole_static_libs)} return staticAttributes{ - srcs: srcs, + copts: copts, + srcs: srcs, + staticDeps: staticDeps, + dynamicDeps: dynamicDeps, + wholeArchiveDeps: wholeArchiveDeps, } } @@ -246,10 +283,11 @@ func bp2BuildParseCompilerProps(ctx android.TopDownMutatorContext, module *Modul // Convenience struct to hold all attributes parsed from linker properties. type linkerAttributes struct { - deps bazel.LabelListAttribute - dynamicDeps bazel.LabelListAttribute - linkopts bazel.StringListAttribute - versionScript bazel.LabelAttribute + deps bazel.LabelListAttribute + dynamicDeps bazel.LabelListAttribute + wholeArchiveDeps bazel.LabelListAttribute + linkopts bazel.StringListAttribute + versionScript bazel.LabelAttribute } // FIXME(b/187655838): Use the existing linkerFlags() function instead of duplicating logic here @@ -266,6 +304,7 @@ func getBp2BuildLinkerFlags(linkerProperties *BaseLinkerProperties) []string { func bp2BuildParseLinkerProps(ctx android.TopDownMutatorContext, module *Module) linkerAttributes { var deps bazel.LabelListAttribute var dynamicDeps bazel.LabelListAttribute + var wholeArchiveDeps bazel.LabelListAttribute var linkopts bazel.StringListAttribute var versionScript bazel.LabelAttribute @@ -274,11 +313,11 @@ func bp2BuildParseLinkerProps(ctx android.TopDownMutatorContext, module *Module) libs := baseLinkerProps.Header_libs libs = append(libs, baseLinkerProps.Export_header_lib_headers...) libs = append(libs, baseLinkerProps.Static_libs...) - libs = append(libs, baseLinkerProps.Whole_static_libs...) + wholeArchiveLibs := baseLinkerProps.Whole_static_libs libs = android.SortedUniqueStrings(libs) deps = bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, libs)) - linkopts.Value = getBp2BuildLinkerFlags(baseLinkerProps) + wholeArchiveDeps = bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, wholeArchiveLibs)) if baseLinkerProps.Version_script != nil { versionScript.Value = android.BazelLabelForModuleSrcSingle(ctx, *baseLinkerProps.Version_script) @@ -296,19 +335,19 @@ func bp2BuildParseLinkerProps(ctx android.TopDownMutatorContext, module *Module) libs := baseLinkerProps.Header_libs libs = append(libs, baseLinkerProps.Export_header_lib_headers...) libs = append(libs, baseLinkerProps.Static_libs...) - libs = append(libs, baseLinkerProps.Whole_static_libs...) + wholeArchiveLibs := baseLinkerProps.Whole_static_libs libs = android.SortedUniqueStrings(libs) deps.SetValueForArch(arch.Name, android.BazelLabelForModuleDeps(ctx, libs)) - linkopts.SetValueForArch(arch.Name, getBp2BuildLinkerFlags(baseLinkerProps)) + wholeArchiveDeps.SetValueForArch(arch.Name, android.BazelLabelForModuleDeps(ctx, wholeArchiveLibs)) if baseLinkerProps.Version_script != nil { versionScript.SetValueForArch(arch.Name, android.BazelLabelForModuleSrcSingle(ctx, *baseLinkerProps.Version_script)) - - sharedLibs := baseLinkerProps.Shared_libs - dynamicDeps.SetValueForArch(arch.Name, android.BazelLabelForModuleDeps(ctx, sharedLibs)) } + + sharedLibs := baseLinkerProps.Shared_libs + dynamicDeps.SetValueForArch(arch.Name, android.BazelLabelForModuleDeps(ctx, sharedLibs)) } } @@ -317,8 +356,9 @@ func bp2BuildParseLinkerProps(ctx android.TopDownMutatorContext, module *Module) libs := baseLinkerProps.Header_libs libs = append(libs, baseLinkerProps.Export_header_lib_headers...) libs = append(libs, baseLinkerProps.Static_libs...) - libs = append(libs, baseLinkerProps.Whole_static_libs...) + wholeArchiveLibs := baseLinkerProps.Whole_static_libs libs = android.SortedUniqueStrings(libs) + wholeArchiveDeps.SetValueForOS(os.Name, android.BazelLabelForModuleDeps(ctx, wholeArchiveLibs)) deps.SetValueForOS(os.Name, android.BazelLabelForModuleDeps(ctx, libs)) linkopts.SetValueForOS(os.Name, getBp2BuildLinkerFlags(baseLinkerProps)) @@ -329,10 +369,11 @@ func bp2BuildParseLinkerProps(ctx android.TopDownMutatorContext, module *Module) } return linkerAttributes{ - deps: deps, - dynamicDeps: dynamicDeps, - linkopts: linkopts, - versionScript: versionScript, + deps: deps, + dynamicDeps: dynamicDeps, + wholeArchiveDeps: wholeArchiveDeps, + linkopts: linkopts, + versionScript: versionScript, } } diff --git a/cc/library.go b/cc/library.go index 7e960a7fa..c5ff9b1f4 100644 --- a/cc/library.go +++ b/cc/library.go @@ -220,16 +220,29 @@ func RegisterLibraryBuildComponents(ctx android.RegistrationContext) { // For bp2build conversion. type bazelCcLibraryAttributes struct { - Srcs bazel.LabelListAttribute - Hdrs bazel.LabelListAttribute - Copts bazel.StringListAttribute - Linkopts bazel.StringListAttribute - Deps bazel.LabelListAttribute - Dynamic_deps bazel.LabelListAttribute - User_link_flags bazel.StringListAttribute - Includes bazel.StringListAttribute - Static_deps_for_shared bazel.LabelListAttribute - Version_script bazel.LabelAttribute + // Attributes pertaining to both static and shared variants. + Srcs bazel.LabelListAttribute + Hdrs bazel.LabelListAttribute + Deps bazel.LabelListAttribute + Dynamic_deps bazel.LabelListAttribute + Whole_archive_deps bazel.LabelListAttribute + Copts bazel.StringListAttribute + Includes bazel.StringListAttribute + Linkopts bazel.StringListAttribute + // Attributes pertaining to shared variant. + Shared_copts bazel.StringListAttribute + Shared_srcs bazel.LabelListAttribute + Static_deps_for_shared bazel.LabelListAttribute + Dynamic_deps_for_shared bazel.LabelListAttribute + Whole_archive_deps_for_shared bazel.LabelListAttribute + User_link_flags bazel.StringListAttribute + Version_script bazel.LabelAttribute + // Attributes pertaining to static variant. + Static_copts bazel.StringListAttribute + Static_srcs bazel.LabelListAttribute + Static_deps_for_static bazel.LabelListAttribute + Dynamic_deps_for_static bazel.LabelListAttribute + Whole_archive_deps_for_static bazel.LabelListAttribute } type bazelCcLibrary struct { @@ -276,17 +289,26 @@ func CcLibraryBp2Build(ctx android.TopDownMutatorContext) { var srcs bazel.LabelListAttribute srcs.Append(compilerAttrs.srcs) - srcs.Append(staticAttrs.srcs) attrs := &bazelCcLibraryAttributes{ - Srcs: srcs, - Copts: compilerAttrs.copts, - Linkopts: linkerAttrs.linkopts, - Deps: linkerAttrs.deps, - Dynamic_deps: linkerAttrs.dynamicDeps, - Version_script: linkerAttrs.versionScript, - Static_deps_for_shared: sharedAttrs.staticDeps, - Includes: exportedIncludes, + Srcs: srcs, + Deps: linkerAttrs.deps, + Dynamic_deps: linkerAttrs.dynamicDeps, + Whole_archive_deps: linkerAttrs.wholeArchiveDeps, + Copts: compilerAttrs.copts, + Includes: exportedIncludes, + Linkopts: linkerAttrs.linkopts, + Shared_copts: sharedAttrs.copts, + Shared_srcs: sharedAttrs.srcs, + Static_deps_for_shared: sharedAttrs.staticDeps, + Whole_archive_deps_for_shared: sharedAttrs.wholeArchiveDeps, + Dynamic_deps_for_shared: sharedAttrs.dynamicDeps, + Version_script: linkerAttrs.versionScript, + Static_copts: staticAttrs.copts, + Static_srcs: staticAttrs.srcs, + Static_deps_for_static: staticAttrs.staticDeps, + Whole_archive_deps_for_static: staticAttrs.wholeArchiveDeps, + Dynamic_deps_for_static: staticAttrs.dynamicDeps, } props := bazel.BazelTargetModuleProperties{ @@ -2194,13 +2216,14 @@ func maybeInjectBoringSSLHash(ctx android.ModuleContext, outputFile android.Modu } type bazelCcLibraryStaticAttributes struct { - Copts bazel.StringListAttribute - Srcs bazel.LabelListAttribute - Deps bazel.LabelListAttribute - Linkopts bazel.StringListAttribute - Linkstatic bool - Includes bazel.StringListAttribute - Hdrs bazel.LabelListAttribute + Copts bazel.StringListAttribute + Srcs bazel.LabelListAttribute + Deps bazel.LabelListAttribute + Whole_archive_deps bazel.LabelListAttribute + Linkopts bazel.StringListAttribute + Linkstatic bool + Includes bazel.StringListAttribute + Hdrs bazel.LabelListAttribute } type bazelCcLibraryStatic struct { @@ -2221,9 +2244,11 @@ func ccLibraryStaticBp2BuildInternal(ctx android.TopDownMutatorContext, module * exportedIncludes := bp2BuildParseExportedIncludes(ctx, module) attrs := &bazelCcLibraryStaticAttributes{ - Copts: compilerAttrs.copts, - Srcs: compilerAttrs.srcs, - Deps: linkerAttrs.deps, + Copts: compilerAttrs.copts, + Srcs: compilerAttrs.srcs, + Deps: linkerAttrs.deps, + Whole_archive_deps: linkerAttrs.wholeArchiveDeps, + Linkopts: linkerAttrs.linkopts, Linkstatic: true, Includes: exportedIncludes, |