Support arch features in bp2build
Bug: 189972518
Test: New soong test
Change-Id: I05d77c8f63ffe6697d8e0300226864658055e116
diff --git a/android/allowlists/allowlists.go b/android/allowlists/allowlists.go
index bcf335f..d2abe0f 100644
--- a/android/allowlists/allowlists.go
+++ b/android/allowlists/allowlists.go
@@ -134,6 +134,7 @@
"external/libjpeg-turbo": Bp2BuildDefaultTrueRecursively,
"external/libmpeg2": Bp2BuildDefaultTrueRecursively,
"external/libpng": Bp2BuildDefaultTrueRecursively,
+ "external/libvpx": Bp2BuildDefaultTrueRecursively,
"external/libyuv": Bp2BuildDefaultTrueRecursively,
"external/lz4/lib": Bp2BuildDefaultTrue,
"external/lzma/C": Bp2BuildDefaultTrueRecursively,
@@ -471,7 +472,6 @@
"linker", // TODO(b/228316882): cc_binary uses link_crt
"versioner", // TODO(b/228313961): depends on prebuilt shared library libclang-cpp_host as a shared library, which does not supply expected providers for a shared library
- "libvpx", // TODO(b/240756936): Arm neon variant not supported
"art_libartbase_headers", // TODO(b/236268577): Header libraries do not support export_shared_libs_headers
"apexer_test", // Requires aapt2
"apexer_test_host_tools",
diff --git a/android/arch.go b/android/arch.go
index 1952b17..9bc9d89 100644
--- a/android/arch.go
+++ b/android/arch.go
@@ -19,6 +19,7 @@
"fmt"
"reflect"
"runtime"
+ "sort"
"strings"
"android/soong/bazel"
@@ -2084,13 +2085,22 @@
// For each arch type (x86, arm64, etc.)
for _, arch := range ArchTypeList() {
// Arch properties are sometimes sharded (see createArchPropTypeDesc() ).
- // Iterate over ever shard and extract a struct with the same type as the
+ // Iterate over every shard and extract a struct with the same type as the
// input one that contains the data specific to that arch.
propertyStructs := make([]reflect.Value, 0)
+ archFeaturePropertyStructs := make(map[string][]reflect.Value, 0)
for _, archProperty := range archProperties {
archTypeStruct, ok := getArchTypeStruct(ctx, archProperty, arch)
if ok {
propertyStructs = append(propertyStructs, archTypeStruct)
+
+ // For each feature this arch supports (arm: neon, x86: ssse3, sse4, ...)
+ for _, feature := range archFeatures[arch] {
+ prefix := "arch." + arch.Name + "." + feature
+ if featureProperties, ok := getChildPropertyStruct(ctx, archTypeStruct, feature, prefix); ok {
+ archFeaturePropertyStructs[feature] = append(archFeaturePropertyStructs[feature], featureProperties)
+ }
+ }
}
multilibStruct, ok := getMultilibStruct(ctx, archProperty, arch)
if ok {
@@ -2098,10 +2108,31 @@
}
}
- // Create a new instance of the requested property set
- value := reflect.New(reflect.ValueOf(propertySet).Elem().Type()).Interface()
+ archToProp[arch.Name] = mergeStructs(ctx, propertyStructs, propertySet)
- archToProp[arch.Name] = mergeStructs(ctx, propertyStructs, value)
+ // In soong, if multiple features match the current configuration, they're
+ // all used. In bazel, we have to have unambiguous select() statements, so
+ // we can't have two features that are both active in the same select().
+ // One alternative is to split out each feature into a separate select(),
+ // but then it's difficult to support exclude_srcs, which may need to
+ // exclude things from the regular arch select() statement if a certain
+ // feature is active. Instead, keep the features in the same select
+ // statement as the arches, but emit the power set of all possible
+ // combinations of features, so that bazel can match the most precise one.
+ allFeatures := make([]string, 0, len(archFeaturePropertyStructs))
+ for feature := range archFeaturePropertyStructs {
+ allFeatures = append(allFeatures, feature)
+ }
+ for _, features := range bazel.PowerSetWithoutEmptySet(allFeatures) {
+ sort.Strings(features)
+ propsForCurrentFeatureSet := make([]reflect.Value, 0)
+ propsForCurrentFeatureSet = append(propsForCurrentFeatureSet, propertyStructs...)
+ for _, feature := range features {
+ propsForCurrentFeatureSet = append(propsForCurrentFeatureSet, archFeaturePropertyStructs[feature]...)
+ }
+ archToProp[arch.Name+"-"+strings.Join(features, "-")] =
+ mergeStructs(ctx, propsForCurrentFeatureSet, propertySet)
+ }
}
axisToProps[bazel.ArchConfigurationAxis] = archToProp