Add musl defaults in bp2build
Bug: 261657184
Test: Unit Tests
Test: Manual Inspection of generated files
Change-Id: I69864abb410fddecd530fc75f2531aff33b33c97
diff --git a/bazel/properties.go b/bazel/properties.go
index 76450dc..9037cac 100644
--- a/bazel/properties.go
+++ b/bazel/properties.go
@@ -814,6 +814,16 @@
return false
}
+// HasAxisSpecificValues returns true if the attribute contains axis specific label list values from a given axis
+func (lla LabelListAttribute) HasAxisSpecificValues(axis ConfigurationAxis) bool {
+ for _, values := range lla.ConfigurableValues[axis] {
+ if !values.IsNil() {
+ return true
+ }
+ }
+ return false
+}
+
// IsEmpty returns true if the attribute has no values under any configuration.
func (lla LabelListAttribute) IsEmpty() bool {
if len(lla.Value.Includes) > 0 {
diff --git a/bp2build/cc_library_conversion_test.go b/bp2build/cc_library_conversion_test.go
index f924d00..052bc32 100644
--- a/bp2build/cc_library_conversion_test.go
+++ b/bp2build/cc_library_conversion_test.go
@@ -1806,6 +1806,11 @@
ModuleTypeUnderTestFactory: cc.LibraryFactory,
Blueprint: soongCcLibraryPreamble + `
cc_library {
+ name: "libc_musl",
+ bazel_module: { bp2build_available: false },
+}
+
+cc_library {
name: "target_linux_bionic_empty",
target: {
linux_bionic: {
@@ -1816,7 +1821,10 @@
}
`,
ExpectedBazelTargets: makeCcLibraryTargets("target_linux_bionic_empty", AttrNameToString{
- "system_dynamic_deps": `[]`,
+ "system_dynamic_deps": `select({
+ "//build/bazel/platforms/os:linux_musl": [":libc_musl"],
+ "//conditions:default": [],
+ })`,
}),
},
)
@@ -1829,6 +1837,11 @@
ModuleTypeUnderTestFactory: cc.LibraryFactory,
Blueprint: soongCcLibraryPreamble + `
cc_library {
+ name: "libc_musl",
+ bazel_module: { bp2build_available: false },
+}
+
+cc_library {
name: "target_bionic_empty",
target: {
bionic: {
@@ -1839,12 +1852,68 @@
}
`,
ExpectedBazelTargets: makeCcLibraryTargets("target_bionic_empty", AttrNameToString{
- "system_dynamic_deps": `[]`,
+ "system_dynamic_deps": `select({
+ "//build/bazel/platforms/os:linux_musl": [":libc_musl"],
+ "//conditions:default": [],
+ })`,
}),
},
)
}
+func TestCcLibrary_SystemSharedLibsMuslEmpty(t *testing.T) {
+ runCcLibraryTestCase(t, Bp2buildTestCase{
+ Description: "cc_library system_shared_lib empty for musl variant",
+ ModuleTypeUnderTest: "cc_library",
+ ModuleTypeUnderTestFactory: cc.LibraryFactory,
+ Blueprint: soongCcLibraryPreamble + `
+cc_library {
+ name: "libc_musl",
+ bazel_module: { bp2build_available: false },
+}
+
+cc_library {
+ name: "target_musl_empty",
+ target: {
+ musl: {
+ system_shared_libs: [],
+ },
+ },
+ include_build_directory: false,
+}
+`,
+ ExpectedBazelTargets: makeCcLibraryTargets("target_musl_empty", AttrNameToString{
+ "system_dynamic_deps": `[]`,
+ }),
+ })
+}
+
+func TestCcLibrary_SystemSharedLibsLinuxMuslEmpty(t *testing.T) {
+ runCcLibraryTestCase(t, Bp2buildTestCase{
+ Description: "cc_library system_shared_lib empty for linux_musl variant",
+ ModuleTypeUnderTest: "cc_library",
+ ModuleTypeUnderTestFactory: cc.LibraryFactory,
+ Blueprint: soongCcLibraryPreamble + `
+cc_library {
+ name: "libc_musl",
+ bazel_module: { bp2build_available: false },
+}
+
+cc_library {
+ name: "target_linux_musl_empty",
+ target: {
+ linux_musl: {
+ system_shared_libs: [],
+ },
+ },
+ include_build_directory: false,
+}
+`,
+ ExpectedBazelTargets: makeCcLibraryTargets("target_linux_musl_empty", AttrNameToString{
+ "system_dynamic_deps": `[]`,
+ }),
+ })
+}
func TestCcLibrary_SystemSharedLibsSharedAndRoot(t *testing.T) {
runCcLibraryTestCase(t, Bp2buildTestCase{
Description: "cc_library system_shared_libs set for shared and root",
diff --git a/bp2build/cc_library_static_conversion_test.go b/bp2build/cc_library_static_conversion_test.go
index 767f4ad..d5256f6 100644
--- a/bp2build/cc_library_static_conversion_test.go
+++ b/bp2build/cc_library_static_conversion_test.go
@@ -1310,6 +1310,11 @@
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
Description: "cc_library_static system_shared_lib empty for bionic variant",
Blueprint: soongCcLibraryStaticPreamble + `
+cc_library {
+ name: "libc_musl",
+ bazel_module: { bp2build_available: false },
+}
+
cc_library_static {
name: "target_bionic_empty",
target: {
@@ -1322,7 +1327,10 @@
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("cc_library_static", "target_bionic_empty", AttrNameToString{
- "system_dynamic_deps": `[]`,
+ "system_dynamic_deps": `select({
+ "//build/bazel/platforms/os:linux_musl": [":libc_musl"],
+ "//conditions:default": [],
+ })`,
}),
},
})
@@ -1336,6 +1344,11 @@
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
Description: "cc_library_static system_shared_lib empty for linux_bionic variant",
Blueprint: soongCcLibraryStaticPreamble + `
+cc_library {
+ name: "libc_musl",
+ bazel_module: { bp2build_available: false },
+}
+
cc_library_static {
name: "target_linux_bionic_empty",
target: {
@@ -1348,6 +1361,63 @@
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("cc_library_static", "target_linux_bionic_empty", AttrNameToString{
+ "system_dynamic_deps": `select({
+ "//build/bazel/platforms/os:linux_musl": [":libc_musl"],
+ "//conditions:default": [],
+ })`,
+ }),
+ },
+ })
+}
+
+func TestStaticLibrary_SystemSharedLibsMuslEmpty(t *testing.T) {
+ runCcLibraryStaticTestCase(t, Bp2buildTestCase{
+ Description: "cc_library_static system_shared_lib empty for musl variant",
+ Blueprint: soongCcLibraryStaticPreamble + `
+cc_library {
+ name: "libc_musl",
+ bazel_module: { bp2build_available: false },
+}
+
+cc_library_static {
+ name: "target_musl_empty",
+ target: {
+ musl: {
+ system_shared_libs: [],
+ },
+ },
+ include_build_directory: false,
+}
+`,
+ ExpectedBazelTargets: []string{
+ MakeBazelTarget("cc_library_static", "target_musl_empty", AttrNameToString{
+ "system_dynamic_deps": `[]`,
+ }),
+ },
+ })
+}
+
+func TestStaticLibrary_SystemSharedLibsLinuxMuslEmpty(t *testing.T) {
+ runCcLibraryStaticTestCase(t, Bp2buildTestCase{
+ Description: "cc_library_static system_shared_lib empty for linux_musl variant",
+ Blueprint: soongCcLibraryStaticPreamble + `
+cc_library {
+ name: "libc_musl",
+ bazel_module: { bp2build_available: false },
+}
+
+cc_library_static {
+ name: "target_linux_musl_empty",
+ target: {
+ linux_musl: {
+ system_shared_libs: [],
+ },
+ },
+ include_build_directory: false,
+}
+`,
+ ExpectedBazelTargets: []string{
+ MakeBazelTarget("cc_library_static", "target_linux_musl_empty", AttrNameToString{
"system_dynamic_deps": `[]`,
}),
},
@@ -1359,6 +1429,11 @@
Description: "cc_library_static system_shared_libs set for bionic variant",
Blueprint: soongCcLibraryStaticPreamble +
simpleModuleDoNotConvertBp2build("cc_library", "libc") + `
+cc_library {
+ name: "libc_musl",
+ bazel_module: { bp2build_available: false },
+}
+
cc_library_static {
name: "target_bionic",
target: {
@@ -1374,6 +1449,7 @@
"system_dynamic_deps": `select({
"//build/bazel/platforms/os:android": [":libc"],
"//build/bazel/platforms/os:linux_bionic": [":libc"],
+ "//build/bazel/platforms/os:linux_musl": [":libc_musl"],
"//conditions:default": [],
})`,
}),
@@ -1387,6 +1463,11 @@
Blueprint: soongCcLibraryStaticPreamble +
simpleModuleDoNotConvertBp2build("cc_library", "libc") +
simpleModuleDoNotConvertBp2build("cc_library", "libm") + `
+cc_library {
+ name: "libc_musl",
+ bazel_module: { bp2build_available: false },
+}
+
cc_library_static {
name: "target_linux_bionic",
system_shared_libs: ["libc"],
@@ -1402,6 +1483,7 @@
MakeBazelTarget("cc_library_static", "target_linux_bionic", AttrNameToString{
"system_dynamic_deps": `[":libc"] + select({
"//build/bazel/platforms/os:linux_bionic": [":libm"],
+ "//build/bazel/platforms/os:linux_musl": [":libc_musl"],
"//conditions:default": [],
})`,
}),
diff --git a/cc/bp2build.go b/cc/bp2build.go
index d331d89..f031f42 100644
--- a/cc/bp2build.go
+++ b/cc/bp2build.go
@@ -813,6 +813,8 @@
features := compilerAttrs.features.Clone().Append(linkerAttrs.features).Append(bp2buildSanitizerFeatures(ctx, module))
features.DeduplicateAxesFromBase()
+ addMuslSystemDynamicDeps(ctx, linkerAttrs)
+
return baseAttributes{
compilerAttrs,
linkerAttrs,
@@ -823,6 +825,16 @@
}
}
+// As a workaround for b/261657184, we are manually adding the default value
+// of system_dynamic_deps for the linux_musl os.
+// TODO: Solve this properly
+func addMuslSystemDynamicDeps(ctx android.Bp2buildMutatorContext, attrs linkerAttributes) {
+ systemDynamicDeps := attrs.systemDynamicDeps.SelectValue(bazel.OsConfigurationAxis, "linux_musl")
+ if attrs.systemDynamicDeps.HasAxisSpecificValues(bazel.OsConfigurationAxis) && systemDynamicDeps.IsNil() {
+ attrs.systemDynamicDeps.SetSelectValue(bazel.OsConfigurationAxis, "linux_musl", android.BazelLabelForModuleDeps(ctx, config.MuslDefaultSharedLibraries))
+ }
+}
+
type fdoProfileAttributes struct {
Absolute_path_profile string
}
diff --git a/cc/config/x86_linux_host.go b/cc/config/x86_linux_host.go
index 740405e..93aa82e 100644
--- a/cc/config/x86_linux_host.go
+++ b/cc/config/x86_linux_host.go
@@ -112,7 +112,7 @@
muslCrtBeginSharedBinary, muslCrtEndSharedBinary = []string{"libc_musl_crtbegin_dynamic"}, []string{"libc_musl_crtend"}
muslCrtBeginSharedLibrary, muslCrtEndSharedLibrary = []string{"libc_musl_crtbegin_so"}, []string{"libc_musl_crtend_so"}
- muslDefaultSharedLibraries = []string{"libc_musl"}
+ MuslDefaultSharedLibraries = []string{"libc_musl"}
)
const (
@@ -331,7 +331,7 @@
func (toolchainMusl) CrtEndSharedBinary() []string { return muslCrtEndSharedBinary }
func (toolchainMusl) CrtEndSharedLibrary() []string { return muslCrtEndSharedLibrary }
-func (toolchainMusl) DefaultSharedLibraries() []string { return muslDefaultSharedLibraries }
+func (toolchainMusl) DefaultSharedLibraries() []string { return MuslDefaultSharedLibraries }
func (toolchainMusl) Cflags() string {
return "${config.LinuxMuslCflags}"