Add target_compatible_with for compile_multilib
For explicit values of compile_multilib (e.g. 32 or 64), add an incompatibilty constraint for the arches that do not have the correct bitness. Test: go test ./bp2build Bug: 299135307 Change-Id: I4cd997de6804a5c6d89086d740f773936db1cab9
This commit is contained in:
@@ -1418,10 +1418,42 @@ func (attrs *CommonAttributes) fillCommonBp2BuildModuleAttrs(ctx *topDownMutator
|
|||||||
moduleEnableConstraints := bazel.LabelListAttribute{}
|
moduleEnableConstraints := bazel.LabelListAttribute{}
|
||||||
moduleEnableConstraints.Append(platformEnabledAttribute)
|
moduleEnableConstraints.Append(platformEnabledAttribute)
|
||||||
moduleEnableConstraints.Append(productConfigEnabledAttribute)
|
moduleEnableConstraints.Append(productConfigEnabledAttribute)
|
||||||
|
addCompatibilityConstraintForCompileMultilib(ctx, &moduleEnableConstraints)
|
||||||
|
|
||||||
return constraintAttributes{Target_compatible_with: moduleEnableConstraints}
|
return constraintAttributes{Target_compatible_with: moduleEnableConstraints}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
incompatible = bazel.LabelList{[]bazel.Label{{Label: "@platforms//:incompatible"}}, nil}
|
||||||
|
)
|
||||||
|
|
||||||
|
// If compile_mulitilib is set to
|
||||||
|
// 1. 32: Add an incompatibility constraint for non-32 arches
|
||||||
|
// 1. 64: Add an incompatibility constraint for non-64 arches
|
||||||
|
func addCompatibilityConstraintForCompileMultilib(ctx *topDownMutatorContext, enabled *bazel.LabelListAttribute) {
|
||||||
|
mod := ctx.Module().base()
|
||||||
|
multilib, _ := decodeMultilib(mod, mod.commonProperties.CompileOS, ctx.Config().IgnorePrefer32OnDevice())
|
||||||
|
|
||||||
|
switch multilib {
|
||||||
|
case "32":
|
||||||
|
// Add an incompatibility constraint for all known 64-bit arches
|
||||||
|
enabled.SetSelectValue(bazel.ArchConfigurationAxis, "arm64", incompatible)
|
||||||
|
enabled.SetSelectValue(bazel.ArchConfigurationAxis, "x86_64", incompatible)
|
||||||
|
enabled.SetSelectValue(bazel.ArchConfigurationAxis, "riscv64", incompatible)
|
||||||
|
case "64":
|
||||||
|
// Add an incompatibility constraint for all known 32-bit arches
|
||||||
|
enabled.SetSelectValue(bazel.ArchConfigurationAxis, "arm", incompatible)
|
||||||
|
enabled.SetSelectValue(bazel.ArchConfigurationAxis, "x86", incompatible)
|
||||||
|
case "both":
|
||||||
|
// Do nothing: "both" is trivially compatible with 32-bit and 64-bit
|
||||||
|
// The top level rule (e.g. apex/partition) will be responsible for building this module in both variants via an
|
||||||
|
// outgoing_transition.
|
||||||
|
default: // e.g. first, common
|
||||||
|
// TODO - b/299135307: Add bp2build support for these properties.
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// Check product variables for `enabled: true` flag override.
|
// Check product variables for `enabled: true` flag override.
|
||||||
// Returns a list of the constraint_value targets who enable this override.
|
// Returns a list of the constraint_value targets who enable this override.
|
||||||
func productVariableConfigEnableAttribute(ctx *topDownMutatorContext) bazel.LabelListAttribute {
|
func productVariableConfigEnableAttribute(ctx *topDownMutatorContext) bazel.LabelListAttribute {
|
||||||
|
@@ -5279,3 +5279,58 @@ cc_library {
|
|||||||
}
|
}
|
||||||
runCcLibraryTestCase(t, tc)
|
runCcLibraryTestCase(t, tc)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCcCompileMultilibConversion(t *testing.T) {
|
||||||
|
tc := Bp2buildTestCase{
|
||||||
|
Description: "cc_library with compile_multilib",
|
||||||
|
ModuleTypeUnderTest: "cc_library",
|
||||||
|
ModuleTypeUnderTestFactory: cc.LibraryFactory,
|
||||||
|
Blueprint: `
|
||||||
|
cc_library {
|
||||||
|
name: "lib32",
|
||||||
|
compile_multilib: "32",
|
||||||
|
}
|
||||||
|
cc_library {
|
||||||
|
name: "lib64",
|
||||||
|
compile_multilib: "64",
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
ExpectedBazelTargets: []string{
|
||||||
|
MakeBazelTargetNoRestrictions("cc_library_shared", "lib32", AttrNameToString{
|
||||||
|
"local_includes": `["."]`,
|
||||||
|
"target_compatible_with": `["//build/bazel/platforms/os:android"] + select({
|
||||||
|
"//build/bazel/platforms/arch:arm64": ["@platforms//:incompatible"],
|
||||||
|
"//build/bazel/platforms/arch:riscv64": ["@platforms//:incompatible"],
|
||||||
|
"//build/bazel/platforms/arch:x86_64": ["@platforms//:incompatible"],
|
||||||
|
"//conditions:default": [],
|
||||||
|
})`,
|
||||||
|
}),
|
||||||
|
MakeBazelTargetNoRestrictions("cc_library_static", "lib32_bp2build_cc_library_static", AttrNameToString{
|
||||||
|
"local_includes": `["."]`,
|
||||||
|
"target_compatible_with": `["//build/bazel/platforms/os:android"] + select({
|
||||||
|
"//build/bazel/platforms/arch:arm64": ["@platforms//:incompatible"],
|
||||||
|
"//build/bazel/platforms/arch:riscv64": ["@platforms//:incompatible"],
|
||||||
|
"//build/bazel/platforms/arch:x86_64": ["@platforms//:incompatible"],
|
||||||
|
"//conditions:default": [],
|
||||||
|
})`,
|
||||||
|
}),
|
||||||
|
MakeBazelTargetNoRestrictions("cc_library_shared", "lib64", AttrNameToString{
|
||||||
|
"local_includes": `["."]`,
|
||||||
|
"target_compatible_with": `["//build/bazel/platforms/os:android"] + select({
|
||||||
|
"//build/bazel/platforms/arch:arm": ["@platforms//:incompatible"],
|
||||||
|
"//build/bazel/platforms/arch:x86": ["@platforms//:incompatible"],
|
||||||
|
"//conditions:default": [],
|
||||||
|
})`,
|
||||||
|
}),
|
||||||
|
MakeBazelTargetNoRestrictions("cc_library_static", "lib64_bp2build_cc_library_static", AttrNameToString{
|
||||||
|
"local_includes": `["."]`,
|
||||||
|
"target_compatible_with": `["//build/bazel/platforms/os:android"] + select({
|
||||||
|
"//build/bazel/platforms/arch:arm": ["@platforms//:incompatible"],
|
||||||
|
"//build/bazel/platforms/arch:x86": ["@platforms//:incompatible"],
|
||||||
|
"//conditions:default": [],
|
||||||
|
})`,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
runCcLibraryTestCase(t, tc)
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user