Merge "bp2build: split full_cc_library into shared/static"
This commit is contained in:
10
cc/cc.go
10
cc/cc.go
@@ -1713,7 +1713,15 @@ func (c *Module) setSubnameProperty(actx android.ModuleContext) {
|
||||
|
||||
// Returns true if Bazel was successfully used for the analysis of this module.
|
||||
func (c *Module) maybeGenerateBazelActions(actx android.ModuleContext) bool {
|
||||
bazelModuleLabel := c.GetBazelLabel(actx, c)
|
||||
var bazelModuleLabel string
|
||||
if actx.ModuleType() == "cc_library" && c.static() {
|
||||
// cc_library is a special case in bp2build; two targets are generated -- one for each
|
||||
// of the shared and static variants. The shared variant keeps the module name, but the
|
||||
// static variant uses a different suffixed name.
|
||||
bazelModuleLabel = bazelLabelForStaticModule(actx, c)
|
||||
} else {
|
||||
bazelModuleLabel = c.GetBazelLabel(actx, c)
|
||||
}
|
||||
bazelActionsUsed := false
|
||||
// Mixed builds mode is disabled for modules outside of device OS.
|
||||
// TODO(b/200841190): Support non-device OS in mixed builds.
|
||||
|
105
cc/library.go
105
cc/library.go
@@ -313,35 +313,74 @@ func CcLibraryBp2Build(ctx android.TopDownMutatorContext) {
|
||||
asFlags = bazel.MakeStringListAttribute(nil)
|
||||
}
|
||||
|
||||
attrs := &bazelCcLibraryAttributes{
|
||||
Srcs: srcs,
|
||||
Srcs_c: compilerAttrs.cSrcs,
|
||||
Srcs_as: compilerAttrs.asSrcs,
|
||||
Hdrs: compilerAttrs.hdrs,
|
||||
staticCommonAttrs := staticOrSharedAttributes{
|
||||
Srcs: *srcs.Clone().Append(staticAttrs.Srcs),
|
||||
Srcs_c: *compilerAttrs.cSrcs.Clone().Append(staticAttrs.Srcs_c),
|
||||
Srcs_as: *compilerAttrs.asSrcs.Clone().Append(staticAttrs.Srcs_as),
|
||||
Copts: *compilerAttrs.copts.Clone().Append(staticAttrs.Copts),
|
||||
Hdrs: *compilerAttrs.hdrs.Clone().Append(staticAttrs.Hdrs),
|
||||
|
||||
Deps: *linkerAttrs.deps.Clone().Append(staticAttrs.Deps),
|
||||
Implementation_deps: *linkerAttrs.implementationDeps.Clone().Append(staticAttrs.Implementation_deps),
|
||||
Dynamic_deps: *linkerAttrs.dynamicDeps.Clone().Append(staticAttrs.Dynamic_deps),
|
||||
Implementation_dynamic_deps: *linkerAttrs.implementationDynamicDeps.Clone().Append(staticAttrs.Implementation_dynamic_deps),
|
||||
Implementation_whole_archive_deps: linkerAttrs.implementationWholeArchiveDeps,
|
||||
Whole_archive_deps: *linkerAttrs.wholeArchiveDeps.Clone().Append(staticAttrs.Whole_archive_deps),
|
||||
System_dynamic_deps: *linkerAttrs.systemDynamicDeps.Clone().Append(staticAttrs.System_dynamic_deps),
|
||||
}
|
||||
|
||||
sharedCommonAttrs := staticOrSharedAttributes{
|
||||
Srcs: *srcs.Clone().Append(sharedAttrs.Srcs),
|
||||
Srcs_c: *compilerAttrs.cSrcs.Clone().Append(sharedAttrs.Srcs_c),
|
||||
Srcs_as: *compilerAttrs.asSrcs.Clone().Append(sharedAttrs.Srcs_as),
|
||||
Copts: *compilerAttrs.copts.Clone().Append(sharedAttrs.Copts),
|
||||
Hdrs: *compilerAttrs.hdrs.Clone().Append(sharedAttrs.Hdrs),
|
||||
|
||||
Deps: *linkerAttrs.deps.Clone().Append(sharedAttrs.Deps),
|
||||
Implementation_deps: *linkerAttrs.implementationDeps.Clone().Append(sharedAttrs.Implementation_deps),
|
||||
Dynamic_deps: *linkerAttrs.dynamicDeps.Clone().Append(sharedAttrs.Dynamic_deps),
|
||||
Implementation_dynamic_deps: *linkerAttrs.implementationDynamicDeps.Clone().Append(sharedAttrs.Implementation_dynamic_deps),
|
||||
Whole_archive_deps: *linkerAttrs.wholeArchiveDeps.Clone().Append(sharedAttrs.Whole_archive_deps),
|
||||
System_dynamic_deps: *linkerAttrs.systemDynamicDeps.Clone().Append(sharedAttrs.System_dynamic_deps),
|
||||
}
|
||||
|
||||
staticTargetAttrs := &bazelCcLibraryStaticAttributes{
|
||||
staticOrSharedAttributes: staticCommonAttrs,
|
||||
|
||||
Copts: compilerAttrs.copts,
|
||||
Cppflags: compilerAttrs.cppFlags,
|
||||
Conlyflags: compilerAttrs.conlyFlags,
|
||||
Asflags: asFlags,
|
||||
|
||||
Implementation_deps: linkerAttrs.implementationDeps,
|
||||
Deps: linkerAttrs.deps,
|
||||
Implementation_dynamic_deps: linkerAttrs.implementationDynamicDeps,
|
||||
Dynamic_deps: linkerAttrs.dynamicDeps,
|
||||
Whole_archive_deps: linkerAttrs.wholeArchiveDeps,
|
||||
Implementation_whole_archive_deps: linkerAttrs.implementationWholeArchiveDeps,
|
||||
System_dynamic_deps: linkerAttrs.systemDynamicDeps,
|
||||
Export_includes: exportedIncludes.Includes,
|
||||
Export_system_includes: exportedIncludes.SystemIncludes,
|
||||
Local_includes: compilerAttrs.localIncludes,
|
||||
Absolute_includes: compilerAttrs.absoluteIncludes,
|
||||
Linkopts: linkerAttrs.linkopts,
|
||||
Link_crt: linkerAttrs.linkCrt,
|
||||
Use_libcrt: linkerAttrs.useLibcrt,
|
||||
Rtti: compilerAttrs.rtti,
|
||||
Stl: compilerAttrs.stl,
|
||||
Cpp_std: compilerAttrs.cppStd,
|
||||
C_std: compilerAttrs.cStd,
|
||||
Export_includes: exportedIncludes.Includes,
|
||||
Export_system_includes: exportedIncludes.SystemIncludes,
|
||||
Local_includes: compilerAttrs.localIncludes,
|
||||
Absolute_includes: compilerAttrs.absoluteIncludes,
|
||||
Use_libcrt: linkerAttrs.useLibcrt,
|
||||
Rtti: compilerAttrs.rtti,
|
||||
Stl: compilerAttrs.stl,
|
||||
Cpp_std: compilerAttrs.cppStd,
|
||||
C_std: compilerAttrs.cStd,
|
||||
|
||||
Features: linkerAttrs.features,
|
||||
}
|
||||
|
||||
sharedTargetAttrs := &bazelCcLibrarySharedAttributes{
|
||||
staticOrSharedAttributes: sharedCommonAttrs,
|
||||
Cppflags: compilerAttrs.cppFlags,
|
||||
Conlyflags: compilerAttrs.conlyFlags,
|
||||
Asflags: asFlags,
|
||||
|
||||
Export_includes: exportedIncludes.Includes,
|
||||
Export_system_includes: exportedIncludes.SystemIncludes,
|
||||
Local_includes: compilerAttrs.localIncludes,
|
||||
Absolute_includes: compilerAttrs.absoluteIncludes,
|
||||
Linkopts: linkerAttrs.linkopts,
|
||||
Link_crt: linkerAttrs.linkCrt,
|
||||
Use_libcrt: linkerAttrs.useLibcrt,
|
||||
Rtti: compilerAttrs.rtti,
|
||||
Stl: compilerAttrs.stl,
|
||||
Cpp_std: compilerAttrs.cppStd,
|
||||
C_std: compilerAttrs.cStd,
|
||||
|
||||
Additional_linker_inputs: linkerAttrs.additionalLinkerInputs,
|
||||
|
||||
@@ -352,20 +391,20 @@ func CcLibraryBp2Build(ctx android.TopDownMutatorContext) {
|
||||
All: linkerAttrs.stripAll,
|
||||
None: linkerAttrs.stripNone,
|
||||
},
|
||||
|
||||
Shared: sharedAttrs,
|
||||
|
||||
Static: staticAttrs,
|
||||
|
||||
Features: linkerAttrs.features,
|
||||
}
|
||||
|
||||
props := bazel.BazelTargetModuleProperties{
|
||||
Rule_class: "cc_library",
|
||||
Bzl_load_location: "//build/bazel/rules:full_cc_library.bzl",
|
||||
staticProps := bazel.BazelTargetModuleProperties{
|
||||
Rule_class: "cc_library_static",
|
||||
Bzl_load_location: "//build/bazel/rules:cc_library_static.bzl",
|
||||
}
|
||||
sharedProps := bazel.BazelTargetModuleProperties{
|
||||
Rule_class: "cc_library_shared",
|
||||
Bzl_load_location: "//build/bazel/rules:cc_library_shared.bzl",
|
||||
}
|
||||
|
||||
ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: m.Name()}, attrs)
|
||||
ctx.CreateBazelTargetModule(staticProps, android.CommonAttributes{Name: m.Name() + "_bp2build_cc_library_static"}, staticTargetAttrs)
|
||||
ctx.CreateBazelTargetModule(sharedProps, android.CommonAttributes{Name: m.Name()}, sharedTargetAttrs)
|
||||
}
|
||||
|
||||
// cc_library creates both static and/or shared libraries for a device and/or
|
||||
|
@@ -257,9 +257,14 @@ cc_library {
|
||||
CcObjectFiles: []string{"foo.o"},
|
||||
Includes: []string{"include"},
|
||||
SystemIncludes: []string{"system_include"},
|
||||
RootStaticArchives: []string{"foo.a"},
|
||||
RootDynamicLibraries: []string{"foo.so"},
|
||||
},
|
||||
"//foo/bar:bar_bp2build_cc_library_static": cquery.CcInfo{
|
||||
CcObjectFiles: []string{"foo.o"},
|
||||
Includes: []string{"include"},
|
||||
SystemIncludes: []string{"system_include"},
|
||||
RootStaticArchives: []string{"foo.a"},
|
||||
},
|
||||
},
|
||||
}
|
||||
ctx := testCcWithConfig(t, config)
|
||||
|
Reference in New Issue
Block a user