diff --git a/android/bazel.go b/android/bazel.go index facd1166d..8341e5725 100644 --- a/android/bazel.go +++ b/android/bazel.go @@ -212,6 +212,13 @@ var ( "libc_ndk", // http://b/187013218, cc_library_static, depends on //bionic/libm:libm (http://b/183064661) "libc_malloc_hooks", // http://b/187016307, cc_library, ld.lld: error: undefined symbol: __malloc_hook + // There are unexported symbols that don't surface on a shared library build, + // from the source static archive + // e.g. _Unwind_{GetRegionStart,GetLanguageSpecificData,GetIP,Set{IP,GR},Resume,{Raise,Delete}Exception}, pthread_atfork + // ... from: cxa_{personality,exception}.o, system_error.o, wrappers_c_bionic.o + // cf. http://b/198403271 + "libc++", + // http://b/186823769: Needs C++ STL support, includes from unconverted standard libraries in //external/libcxx // c++_static "libbase_ndk", // http://b/186826477, cc_library, no such target '//build/bazel/platforms/os:darwin' when --platforms //build/bazel/platforms:android_x86 is added @@ -223,6 +230,8 @@ var ( "libbase", // Requires liblog. http://b/186826479, cc_library, fatal error: 'memory' file not found, from libcxx. // Also depends on fmtlib. + "libfdtrack", // depends on STL + "libseccomp_policy", // depends on libbase "gwp_asan_crash_handler", // cc_library, ld.lld: error: undefined symbol: memset diff --git a/bp2build/Android.bp b/bp2build/Android.bp index 5ee04f989..1d52a7040 100644 --- a/bp2build/Android.bp +++ b/bp2build/Android.bp @@ -37,6 +37,7 @@ bootstrap_go_package { "cc_library_conversion_test.go", "cc_library_headers_conversion_test.go", "cc_library_static_conversion_test.go", + "cc_library_shared_conversion_test.go", "cc_object_conversion_test.go", "conversion_test.go", "filegroup_conversion_test.go", diff --git a/bp2build/cc_library_shared_conversion_test.go b/bp2build/cc_library_shared_conversion_test.go new file mode 100644 index 000000000..52a07cc47 --- /dev/null +++ b/bp2build/cc_library_shared_conversion_test.go @@ -0,0 +1,366 @@ +// Copyright 2021 Google Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package bp2build + +import ( + "testing" + + "android/soong/android" + "android/soong/cc" +) + +const ( + // See cc/testing.go for more context + // TODO(alexmarquez): Split out the preamble into common code? + soongCcLibrarySharedPreamble = soongCcLibraryStaticPreamble +) + +func registerCcLibrarySharedModuleTypes(ctx android.RegistrationContext) { + cc.RegisterCCBuildComponents(ctx) + ctx.RegisterModuleType("toolchain_library", cc.ToolchainLibraryFactory) + ctx.RegisterModuleType("cc_library_headers", cc.LibraryHeaderFactory) + ctx.RegisterModuleType("cc_library_static", cc.LibraryStaticFactory) +} + +func runCcLibrarySharedTestCase(t *testing.T, tc bp2buildTestCase) { + t.Helper() + runBp2BuildTestCase(t, registerCcLibrarySharedModuleTypes, tc) +} + +func TestCcLibrarySharedSimple(t *testing.T) { + runCcLibrarySharedTestCase(t, bp2buildTestCase{ + description: "cc_library_shared simple overall test", + moduleTypeUnderTest: "cc_library_shared", + moduleTypeUnderTestFactory: cc.LibrarySharedFactory, + moduleTypeUnderTestBp2BuildMutator: cc.CcLibrarySharedBp2Build, + filesystem: map[string]string{ + // NOTE: include_dir headers *should not* appear in Bazel hdrs later (?) + "include_dir_1/include_dir_1_a.h": "", + "include_dir_1/include_dir_1_b.h": "", + "include_dir_2/include_dir_2_a.h": "", + "include_dir_2/include_dir_2_b.h": "", + // NOTE: local_include_dir headers *should not* appear in Bazel hdrs later (?) + "local_include_dir_1/local_include_dir_1_a.h": "", + "local_include_dir_1/local_include_dir_1_b.h": "", + "local_include_dir_2/local_include_dir_2_a.h": "", + "local_include_dir_2/local_include_dir_2_b.h": "", + // NOTE: export_include_dir headers *should* appear in Bazel hdrs later + "export_include_dir_1/export_include_dir_1_a.h": "", + "export_include_dir_1/export_include_dir_1_b.h": "", + "export_include_dir_2/export_include_dir_2_a.h": "", + "export_include_dir_2/export_include_dir_2_b.h": "", + // NOTE: Soong implicitly includes headers in the current directory + "implicit_include_1.h": "", + "implicit_include_2.h": "", + }, + blueprint: soongCcLibrarySharedPreamble + ` +cc_library_headers { + name: "header_lib_1", + export_include_dirs: ["header_lib_1"], + bazel_module: { bp2build_available: false }, +} + +cc_library_headers { + name: "header_lib_2", + export_include_dirs: ["header_lib_2"], + bazel_module: { bp2build_available: false }, +} + +cc_library_shared { + name: "shared_lib_1", + srcs: ["shared_lib_1.cc"], + bazel_module: { bp2build_available: false }, +} + +cc_library_shared { + name: "shared_lib_2", + srcs: ["shared_lib_2.cc"], + bazel_module: { bp2build_available: false }, +} + +cc_library_static { + name: "whole_static_lib_1", + srcs: ["whole_static_lib_1.cc"], + bazel_module: { bp2build_available: false }, +} + +cc_library_static { + name: "whole_static_lib_2", + srcs: ["whole_static_lib_2.cc"], + bazel_module: { bp2build_available: false }, +} + +cc_library_shared { + name: "foo_shared", + srcs: [ + "foo_shared1.cc", + "foo_shared2.cc", + ], + cflags: [ + "-Dflag1", + "-Dflag2" + ], + shared_libs: [ + "shared_lib_1", + "shared_lib_2" + ], + whole_static_libs: [ + "whole_static_lib_1", + "whole_static_lib_2" + ], + include_dirs: [ + "include_dir_1", + "include_dir_2", + ], + local_include_dirs: [ + "local_include_dir_1", + "local_include_dir_2", + ], + export_include_dirs: [ + "export_include_dir_1", + "export_include_dir_2" + ], + header_libs: [ + "header_lib_1", + "header_lib_2" + ], + + // TODO: Also support export_header_lib_headers +}`, + expectedBazelTargets: []string{`cc_library_shared( + name = "foo_shared", + absolute_includes = [ + "include_dir_1", + "include_dir_2", + ], + copts = [ + "-Dflag1", + "-Dflag2", + ], + dynamic_deps = [ + ":shared_lib_1", + ":shared_lib_2", + ], + export_includes = [ + "export_include_dir_1", + "export_include_dir_2", + ], + implementation_deps = [ + ":header_lib_1", + ":header_lib_2", + ], + local_includes = [ + "local_include_dir_1", + "local_include_dir_2", + ".", + ], + srcs = [ + "foo_shared1.cc", + "foo_shared2.cc", + ], + whole_archive_deps = [ + ":whole_static_lib_1", + ":whole_static_lib_2", + ], +)`}, + }) +} + +func TestCcLibrarySharedArchSpecificSharedLib(t *testing.T) { + runCcLibrarySharedTestCase(t, bp2buildTestCase{ + description: "cc_library_shared arch-specific shared_libs with whole_static_libs", + moduleTypeUnderTest: "cc_library_shared", + moduleTypeUnderTestFactory: cc.LibrarySharedFactory, + moduleTypeUnderTestBp2BuildMutator: cc.CcLibrarySharedBp2Build, + filesystem: map[string]string{}, + blueprint: soongCcLibrarySharedPreamble + ` +cc_library_static { + name: "static_dep", + bazel_module: { bp2build_available: false }, +} +cc_library_shared { + name: "shared_dep", + bazel_module: { bp2build_available: false }, +} +cc_library_shared { + name: "foo_shared", + arch: { arm64: { shared_libs: ["shared_dep"], whole_static_libs: ["static_dep"] } }, + include_build_directory: false, +}`, + expectedBazelTargets: []string{`cc_library_shared( + name = "foo_shared", + dynamic_deps = select({ + "//build/bazel/platforms/arch:arm64": [":shared_dep"], + "//conditions:default": [], + }), + whole_archive_deps = select({ + "//build/bazel/platforms/arch:arm64": [":static_dep"], + "//conditions:default": [], + }), +)`}, + }) +} + +func TestCcLibrarySharedOsSpecificSharedLib(t *testing.T) { + runCcLibraryStaticTestCase(t, bp2buildTestCase{ + description: "cc_library_shared os-specific shared_libs", + moduleTypeUnderTest: "cc_library_shared", + moduleTypeUnderTestFactory: cc.LibrarySharedFactory, + moduleTypeUnderTestBp2BuildMutator: cc.CcLibrarySharedBp2Build, + filesystem: map[string]string{}, + blueprint: soongCcLibrarySharedPreamble + ` +cc_library_shared { + name: "shared_dep", + bazel_module: { bp2build_available: false }, +} +cc_library_shared { + name: "foo_shared", + target: { android: { shared_libs: ["shared_dep"], } }, + include_build_directory: false, +}`, + expectedBazelTargets: []string{`cc_library_shared( + name = "foo_shared", + dynamic_deps = select({ + "//build/bazel/platforms/os:android": [":shared_dep"], + "//conditions:default": [], + }), +)`}, + }) +} + +func TestCcLibrarySharedBaseArchOsSpecificSharedLib(t *testing.T) { + runCcLibrarySharedTestCase(t, bp2buildTestCase{ + description: "cc_library_shared base, arch, and os-specific shared_libs", + moduleTypeUnderTest: "cc_library_shared", + moduleTypeUnderTestFactory: cc.LibrarySharedFactory, + moduleTypeUnderTestBp2BuildMutator: cc.CcLibrarySharedBp2Build, + filesystem: map[string]string{}, + blueprint: soongCcLibrarySharedPreamble + ` +cc_library_shared { + name: "shared_dep", + bazel_module: { bp2build_available: false }, +} +cc_library_shared { + name: "shared_dep2", + bazel_module: { bp2build_available: false }, +} +cc_library_shared { + name: "shared_dep3", + bazel_module: { bp2build_available: false }, +} +cc_library_shared { + name: "foo_shared", + shared_libs: ["shared_dep"], + target: { android: { shared_libs: ["shared_dep2"] } }, + arch: { arm64: { shared_libs: ["shared_dep3"] } }, + include_build_directory: false, +}`, + expectedBazelTargets: []string{`cc_library_shared( + name = "foo_shared", + dynamic_deps = [":shared_dep"] + select({ + "//build/bazel/platforms/arch:arm64": [":shared_dep3"], + "//conditions:default": [], + }) + select({ + "//build/bazel/platforms/os:android": [":shared_dep2"], + "//conditions:default": [], + }), +)`}, + }) +} + +func TestCcLibrarySharedSimpleExcludeSrcs(t *testing.T) { + runCcLibrarySharedTestCase(t, bp2buildTestCase{ + description: "cc_library_shared simple exclude_srcs", + moduleTypeUnderTest: "cc_library_shared", + moduleTypeUnderTestFactory: cc.LibrarySharedFactory, + moduleTypeUnderTestBp2BuildMutator: cc.CcLibrarySharedBp2Build, + filesystem: map[string]string{ + "common.c": "", + "foo-a.c": "", + "foo-excluded.c": "", + }, + blueprint: soongCcLibrarySharedPreamble + ` +cc_library_shared { + name: "foo_shared", + srcs: ["common.c", "foo-*.c"], + exclude_srcs: ["foo-excluded.c"], + include_build_directory: false, +}`, + expectedBazelTargets: []string{`cc_library_shared( + name = "foo_shared", + srcs_c = [ + "common.c", + "foo-a.c", + ], +)`}, + }) +} + +func TestCcLibrarySharedStrip(t *testing.T) { + runCcLibrarySharedTestCase(t, bp2buildTestCase{ + description: "cc_library_shared stripping", + moduleTypeUnderTest: "cc_library_shared", + moduleTypeUnderTestFactory: cc.LibrarySharedFactory, + moduleTypeUnderTestBp2BuildMutator: cc.CcLibrarySharedBp2Build, + filesystem: map[string]string{}, + blueprint: soongCcLibrarySharedPreamble + ` +cc_library_shared { + name: "foo_shared", + strip: { + keep_symbols: false, + keep_symbols_and_debug_frame: true, + keep_symbols_list: ["sym", "sym2"], + all: true, + none: false, + }, + include_build_directory: false, +}`, + expectedBazelTargets: []string{`cc_library_shared( + name = "foo_shared", + strip = { + "all": True, + "keep_symbols": False, + "keep_symbols_and_debug_frame": True, + "keep_symbols_list": [ + "sym", + "sym2", + ], + "none": False, + }, +)`}, + }) +} + +func TestCcLibrarySharedVersionScript(t *testing.T) { + runCcLibrarySharedTestCase(t, bp2buildTestCase{ + description: "cc_library_shared version script", + moduleTypeUnderTest: "cc_library_shared", + moduleTypeUnderTestFactory: cc.LibrarySharedFactory, + moduleTypeUnderTestBp2BuildMutator: cc.CcLibrarySharedBp2Build, + filesystem: map[string]string{ + "version_script": "", + }, + blueprint: soongCcLibrarySharedPreamble + ` +cc_library_shared { + name: "foo_shared", + version_script: "version_script", + include_build_directory: false, +}`, + expectedBazelTargets: []string{`cc_library_shared( + name = "foo_shared", + version_script = "version_script", +)`}, + }) +} diff --git a/cc/bp2build.go b/cc/bp2build.go index 7a98fd0e4..67ea70e2c 100644 --- a/cc/bp2build.go +++ b/cc/bp2build.go @@ -111,24 +111,23 @@ func groupSrcsByExtension(ctx android.TopDownMutatorContext, srcs bazel.LabelLis return } -// bp2buildParseSharedProps returns the attributes for the shared variant of a cc_library. -func bp2BuildParseSharedProps(ctx android.TopDownMutatorContext, module *Module) staticOrSharedAttributes { +// bp2BuildParseLibProps returns the attributes for a variant of a cc_library. +func bp2BuildParseLibProps(ctx android.TopDownMutatorContext, module *Module, isStatic bool) staticOrSharedAttributes { lib, ok := module.compiler.(*libraryDecorator) if !ok { return staticOrSharedAttributes{} } + return bp2buildParseStaticOrSharedProps(ctx, module, lib, isStatic) +} - return bp2buildParseStaticOrSharedProps(ctx, module, lib, false) +// bp2buildParseSharedProps returns the attributes for the shared variant of a cc_library. +func bp2BuildParseSharedProps(ctx android.TopDownMutatorContext, module *Module) staticOrSharedAttributes { + return bp2BuildParseLibProps(ctx, module, false) } // bp2buildParseStaticProps returns the attributes for the static variant of a cc_library. func bp2BuildParseStaticProps(ctx android.TopDownMutatorContext, module *Module) staticOrSharedAttributes { - lib, ok := module.compiler.(*libraryDecorator) - if !ok { - return staticOrSharedAttributes{} - } - - return bp2buildParseStaticOrSharedProps(ctx, module, lib, true) + return bp2BuildParseLibProps(ctx, module, true) } func bp2buildParseStaticOrSharedProps(ctx android.TopDownMutatorContext, module *Module, lib *libraryDecorator, isStatic bool) staticOrSharedAttributes { @@ -178,6 +177,7 @@ type prebuiltAttributes struct { Src bazel.LabelAttribute } +// NOTE: Used outside of Soong repo project, in the clangprebuilts.go bootstrap_go_package func Bp2BuildParsePrebuiltLibraryProps(ctx android.TopDownMutatorContext, module *Module) prebuiltAttributes { var srcLabelAttribute bazel.LabelAttribute diff --git a/cc/library.go b/cc/library.go index 7caec9d25..8a663ff11 100644 --- a/cc/library.go +++ b/cc/library.go @@ -205,6 +205,7 @@ func init() { RegisterLibraryBuildComponents(android.InitRegistrationContext) android.RegisterBp2BuildMutator("cc_library_static", CcLibraryStaticBp2Build) + android.RegisterBp2BuildMutator("cc_library_shared", CcLibrarySharedBp2Build) android.RegisterBp2BuildMutator("cc_library", CcLibraryBp2Build) } @@ -216,6 +217,7 @@ func RegisterLibraryBuildComponents(ctx android.RegistrationContext) { ctx.RegisterModuleType("cc_library_host_shared", LibraryHostSharedFactory) } +// TODO(b/199902614): Can this be factored to share with the other Attributes? // For bp2build conversion. type bazelCcLibraryAttributes struct { // Attributes pertaining to both static and shared variants. @@ -274,7 +276,7 @@ func CcLibraryBp2Build(ctx android.TopDownMutatorContext) { // converted, but not their shared variants. For these modules, delegate to // the cc_library_static bp2build converter temporarily instead. if android.GenerateCcLibraryStaticOnly(ctx) { - ccLibraryStaticBp2BuildInternal(ctx, m) + ccSharedOrStaticBp2BuildMutatorInternal(ctx, m, "cc_library_static") return } @@ -2323,6 +2325,123 @@ func maybeInjectBoringSSLHash(ctx android.ModuleContext, outputFile android.Modu return outputFile } +func ccSharedOrStaticBp2BuildMutator(ctx android.TopDownMutatorContext, modType string) { + module, ok := ctx.Module().(*Module) + if !ok { + // Not a cc module + return + } + if !module.ConvertWithBp2build(ctx) { + return + } + if ctx.ModuleType() != modType { + return + } + + ccSharedOrStaticBp2BuildMutatorInternal(ctx, module, modType) +} + +func ccSharedOrStaticBp2BuildMutatorInternal(ctx android.TopDownMutatorContext, module *Module, modType string) { + if modType != "cc_library_static" && modType != "cc_library_shared" { + panic("ccSharedOrStaticBp2BuildMutatorInternal only supports cc_library_{static,shared}") + } + isStatic := modType == "cc_library_static" + + compilerAttrs := bp2BuildParseCompilerProps(ctx, module) + linkerAttrs := bp2BuildParseLinkerProps(ctx, module) + exportedIncludes := bp2BuildParseExportedIncludes(ctx, module) + + // Append shared/static{} stanza properties. These won't be specified on + // cc_library_* itself, but may be specified in cc_defaults that this module + // depends on. + libSharedOrStaticAttrs := bp2BuildParseLibProps(ctx, module, isStatic) + + compilerAttrs.srcs.Append(libSharedOrStaticAttrs.Srcs) + compilerAttrs.cSrcs.Append(libSharedOrStaticAttrs.Srcs_c) + compilerAttrs.asSrcs.Append(libSharedOrStaticAttrs.Srcs_as) + compilerAttrs.copts.Append(libSharedOrStaticAttrs.Copts) + linkerAttrs.exportedDeps.Append(libSharedOrStaticAttrs.Static_deps) + linkerAttrs.dynamicDeps.Append(libSharedOrStaticAttrs.Dynamic_deps) + linkerAttrs.wholeArchiveDeps.Append(libSharedOrStaticAttrs.Whole_archive_deps) + linkerAttrs.systemDynamicDeps.Append(libSharedOrStaticAttrs.System_dynamic_deps) + + asFlags := compilerAttrs.asFlags + if compilerAttrs.asSrcs.IsEmpty() { + // Skip asflags for BUILD file simplicity if there are no assembly sources. + asFlags = bazel.MakeStringListAttribute(nil) + } + + var attrs interface{} + if isStatic { + attrs = &bazelCcLibraryStaticAttributes{ + Copts: compilerAttrs.copts, + Srcs: compilerAttrs.srcs, + Implementation_deps: linkerAttrs.deps, + Deps: linkerAttrs.exportedDeps, + Whole_archive_deps: linkerAttrs.wholeArchiveDeps, + Dynamic_deps: linkerAttrs.dynamicDeps, + System_dynamic_deps: linkerAttrs.systemDynamicDeps, + + Linkopts: linkerAttrs.linkopts, + Use_libcrt: linkerAttrs.useLibcrt, + Rtti: compilerAttrs.rtti, + Export_includes: exportedIncludes.Includes, + Export_system_includes: exportedIncludes.SystemIncludes, + Local_includes: compilerAttrs.localIncludes, + Absolute_includes: compilerAttrs.absoluteIncludes, + + Cppflags: compilerAttrs.cppFlags, + Srcs_c: compilerAttrs.cSrcs, + Conlyflags: compilerAttrs.conlyFlags, + Srcs_as: compilerAttrs.asSrcs, + Asflags: asFlags, + } + } else { + attrs = &bazelCcLibrarySharedAttributes{ + Srcs: compilerAttrs.srcs, + Srcs_c: compilerAttrs.cSrcs, + Srcs_as: compilerAttrs.asSrcs, + + Implementation_deps: linkerAttrs.deps, + Deps: linkerAttrs.exportedDeps, + Whole_archive_deps: linkerAttrs.wholeArchiveDeps, + Dynamic_deps: linkerAttrs.dynamicDeps, + System_dynamic_deps: linkerAttrs.systemDynamicDeps, + + Copts: compilerAttrs.copts, + Cppflags: compilerAttrs.cppFlags, + Conlyflags: compilerAttrs.conlyFlags, + Asflags: asFlags, + Linkopts: linkerAttrs.linkopts, + + Use_libcrt: linkerAttrs.useLibcrt, + Rtti: compilerAttrs.rtti, + + Export_includes: exportedIncludes.Includes, + Export_system_includes: exportedIncludes.SystemIncludes, + Local_includes: compilerAttrs.localIncludes, + Absolute_includes: compilerAttrs.absoluteIncludes, + Version_script: linkerAttrs.versionScript, + + Strip: stripAttributes{ + Keep_symbols: linkerAttrs.stripKeepSymbols, + Keep_symbols_and_debug_frame: linkerAttrs.stripKeepSymbolsAndDebugFrame, + Keep_symbols_list: linkerAttrs.stripKeepSymbolsList, + All: linkerAttrs.stripAll, + None: linkerAttrs.stripNone, + }, + } + } + + props := bazel.BazelTargetModuleProperties{ + Rule_class: modType, + Bzl_load_location: fmt.Sprintf("//build/bazel/rules:%s.bzl", modType), + } + + ctx.CreateBazelTargetModule(module.Name(), props, attrs) +} + +// TODO(b/199902614): Can this be factored to share with the other Attributes? type bazelCcLibraryStaticAttributes struct { Copts bazel.StringListAttribute Srcs bazel.LabelListAttribute @@ -2345,80 +2464,42 @@ type bazelCcLibraryStaticAttributes struct { Conlyflags bazel.StringListAttribute Srcs_as bazel.LabelListAttribute Asflags bazel.StringListAttribute - - Static staticOrSharedAttributes -} - -func ccLibraryStaticBp2BuildInternal(ctx android.TopDownMutatorContext, module *Module) { - compilerAttrs := bp2BuildParseCompilerProps(ctx, module) - linkerAttrs := bp2BuildParseLinkerProps(ctx, module) - exportedIncludes := bp2BuildParseExportedIncludes(ctx, module) - - asFlags := compilerAttrs.asFlags - if compilerAttrs.asSrcs.IsEmpty() { - // Skip asflags for BUILD file simplicity if there are no assembly sources. - asFlags = bazel.MakeStringListAttribute(nil) - } - - // Append static{} stanza properties. These won't be specified on - // cc_library_static itself, but may be specified in cc_defaults that this module - // depends on. - staticAttrs := bp2BuildParseStaticProps(ctx, module) - - compilerAttrs.srcs.Append(staticAttrs.Srcs) - compilerAttrs.cSrcs.Append(staticAttrs.Srcs_c) - compilerAttrs.asSrcs.Append(staticAttrs.Srcs_as) - compilerAttrs.copts.Append(staticAttrs.Copts) - linkerAttrs.exportedDeps.Append(staticAttrs.Static_deps) - linkerAttrs.dynamicDeps.Append(staticAttrs.Dynamic_deps) - linkerAttrs.wholeArchiveDeps.Append(staticAttrs.Whole_archive_deps) - linkerAttrs.systemDynamicDeps.Append(staticAttrs.System_dynamic_deps) - - attrs := &bazelCcLibraryStaticAttributes{ - Copts: compilerAttrs.copts, - Srcs: compilerAttrs.srcs, - Implementation_deps: linkerAttrs.deps, - Deps: linkerAttrs.exportedDeps, - Whole_archive_deps: linkerAttrs.wholeArchiveDeps, - Dynamic_deps: linkerAttrs.dynamicDeps, - System_dynamic_deps: linkerAttrs.systemDynamicDeps, - - Linkopts: linkerAttrs.linkopts, - Linkstatic: true, - Use_libcrt: linkerAttrs.useLibcrt, - Rtti: compilerAttrs.rtti, - Export_includes: exportedIncludes.Includes, - Export_system_includes: exportedIncludes.SystemIncludes, - Local_includes: compilerAttrs.localIncludes, - Absolute_includes: compilerAttrs.absoluteIncludes, - - Cppflags: compilerAttrs.cppFlags, - Srcs_c: compilerAttrs.cSrcs, - Conlyflags: compilerAttrs.conlyFlags, - Srcs_as: compilerAttrs.asSrcs, - Asflags: asFlags, - } - - props := bazel.BazelTargetModuleProperties{ - Rule_class: "cc_library_static", - Bzl_load_location: "//build/bazel/rules:cc_library_static.bzl", - } - - ctx.CreateBazelTargetModule(module.Name(), props, attrs) } func CcLibraryStaticBp2Build(ctx android.TopDownMutatorContext) { - module, ok := ctx.Module().(*Module) - if !ok { - // Not a cc module - return - } - if !module.ConvertWithBp2build(ctx) { - return - } - if ctx.ModuleType() != "cc_library_static" { - return - } - - ccLibraryStaticBp2BuildInternal(ctx, module) + ccSharedOrStaticBp2BuildMutator(ctx, "cc_library_static") +} + +// TODO(b/199902614): Can this be factored to share with the other Attributes? +type bazelCcLibrarySharedAttributes struct { + Srcs bazel.LabelListAttribute + Srcs_c bazel.LabelListAttribute + Srcs_as bazel.LabelListAttribute + + Implementation_deps bazel.LabelListAttribute + Deps bazel.LabelListAttribute + Whole_archive_deps bazel.LabelListAttribute + Dynamic_deps bazel.LabelListAttribute + System_dynamic_deps bazel.LabelListAttribute + + Linkopts bazel.StringListAttribute + Use_libcrt bazel.BoolAttribute + Rtti bazel.BoolAttribute + Strip stripAttributes + + Export_includes bazel.StringListAttribute + Export_system_includes bazel.StringListAttribute + Local_includes bazel.StringListAttribute + Absolute_includes bazel.StringListAttribute + Hdrs bazel.LabelListAttribute + Version_script bazel.LabelAttribute + + Copts bazel.StringListAttribute + Cppflags bazel.StringListAttribute + Conlyflags bazel.StringListAttribute + Asflags bazel.StringListAttribute +} + +func CcLibrarySharedBp2Build(ctx android.TopDownMutatorContext) { + ccSharedOrStaticBp2BuildMutator(ctx, "cc_library_shared") }