bp2build support for instruction_set
Convert `instruction_set: "arm"` to an
"arm_isa_arm" bazel feature.
Bug: 215719349
Test: go tests
Change-Id: Ib976d23d2a57e8c0ab5d83ec994a0b7f3c69a7fe
diff --git a/bp2build/cc_binary_conversion_test.go b/bp2build/cc_binary_conversion_test.go
index 1f69b5a..9e449eb 100644
--- a/bp2build/cc_binary_conversion_test.go
+++ b/bp2build/cc_binary_conversion_test.go
@@ -581,3 +581,32 @@
},
})
}
+
+func TestCcBinaryWithInstructionSet(t *testing.T) {
+ runCcBinaryTests(t, ccBinaryBp2buildTestCase{
+ description: "instruction set",
+ blueprint: `
+{rule_name} {
+ name: "foo",
+ arch: {
+ arm: {
+ instruction_set: "arm",
+ }
+ }
+}
+`,
+ targets: []testBazelTarget{
+ {"cc_binary", "foo", AttrNameToString{
+ "features": `select({
+ "//build/bazel/platforms/arch:arm": [
+ "arm_isa_arm",
+ "-arm_isa_thumb",
+ ],
+ "//conditions:default": [],
+ })`,
+ "local_includes": `["."]`,
+ },
+ },
+ },
+ })
+}
diff --git a/bp2build/cc_library_conversion_test.go b/bp2build/cc_library_conversion_test.go
index 72feed5..2d1a7ce 100644
--- a/bp2build/cc_library_conversion_test.go
+++ b/bp2build/cc_library_conversion_test.go
@@ -2566,3 +2566,29 @@
},
})
}
+
+func TestCcLibraryWithInstructionSet(t *testing.T) {
+ runCcLibraryTestCase(t, Bp2buildTestCase{
+ ModuleTypeUnderTest: "cc_library",
+ ModuleTypeUnderTestFactory: cc.LibraryFactory,
+ Blueprint: `cc_library {
+ name: "foo",
+ arch: {
+ arm: {
+ instruction_set: "arm",
+ }
+ }
+}
+`,
+ ExpectedBazelTargets: makeCcLibraryTargets("foo", AttrNameToString{
+ "features": `select({
+ "//build/bazel/platforms/arch:arm": [
+ "arm_isa_arm",
+ "-arm_isa_thumb",
+ ],
+ "//conditions:default": [],
+ })`,
+ "local_includes": `["."]`,
+ }),
+ })
+}
diff --git a/cc/bp2build.go b/cc/bp2build.go
index 9880444..3fe0802 100644
--- a/cc/bp2build.go
+++ b/cc/bp2build.go
@@ -282,6 +282,8 @@
compilerAttributes
linkerAttributes
+ // A combination of compilerAttributes.features and linkerAttributes.features
+ features bazel.StringListAttribute
protoDependency *bazel.LabelAttribute
}
@@ -323,6 +325,8 @@
stubsSymbolFile *string
stubsVersions bazel.StringListAttribute
+
+ features bazel.StringListAttribute
}
type filterOutFn func(string) bool
@@ -386,6 +390,13 @@
ca.absoluteIncludes.SetSelectValue(axis, config, props.Include_dirs)
ca.localIncludes.SetSelectValue(axis, config, localIncludeDirs)
+ instructionSet := proptools.StringDefault(props.Instruction_set, "")
+ if instructionSet == "arm" {
+ ca.features.SetSelectValue(axis, config, []string{"arm_isa_arm", "-arm_isa_thumb"})
+ } else if instructionSet != "" && instructionSet != "thumb" {
+ ctx.ModuleErrorf("Unknown value for instruction_set: %s", instructionSet)
+ }
+
// In Soong, cflags occur on the command line before -std=<val> flag, resulting in the value being
// overridden. In Bazel we always allow overriding, via flags; however, this can cause
// incompatibilities, so we remove "-std=" flags from Cflag properties while leaving it in other
@@ -686,9 +697,13 @@
(&compilerAttrs).srcs.Add(&convertedLSrcs.srcName)
(&compilerAttrs).cSrcs.Add(&convertedLSrcs.cSrcName)
+ features := compilerAttrs.features.Clone().Append(linkerAttrs.features)
+ features.DeduplicateAxesFromBase()
+
return baseAttributes{
compilerAttrs,
linkerAttrs,
+ *features,
protoDep.protoDep,
}
}
diff --git a/cc/library.go b/cc/library.go
index 709dfef..521dcdf 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -359,7 +359,7 @@
C_std: compilerAttrs.cStd,
Use_version_lib: linkerAttrs.useVersionLib,
- Features: linkerAttrs.features,
+ Features: baseAttributes.features,
}
sharedTargetAttrs := &bazelCcLibrarySharedAttributes{
@@ -391,7 +391,7 @@
All: linkerAttrs.stripAll,
None: linkerAttrs.stripNone,
},
- Features: linkerAttrs.features,
+ Features: baseAttributes.features,
}
if compilerAttrs.stubsSymbolFile != nil && len(compilerAttrs.stubsVersions.Value) > 0 {
@@ -2600,7 +2600,7 @@
Conlyflags: compilerAttrs.conlyFlags,
Asflags: asFlags,
- Features: linkerAttrs.features,
+ Features: baseAttributes.features,
}
} else {
commonAttrs.Dynamic_deps.Add(baseAttributes.protoDependency)
@@ -2637,7 +2637,7 @@
None: linkerAttrs.stripNone,
},
- Features: linkerAttrs.features,
+ Features: baseAttributes.features,
}
if compilerAttrs.stubsSymbolFile != nil && len(compilerAttrs.stubsVersions.Value) > 0 {
hasStubs := true