1"""Constants for arch/cpu variants/features.""" 2 3# Copyright (C) 2022 The Android Open Source Project 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16 17load( 18 "@soong_injection//product_config:arch_configuration.bzl", 19 _aml_arches = "aml_arches", 20 _android_arch_feature_for_arch_variant = "android_arch_feature_for_arch_variants", 21 _arch_to_cpu_variants = "arch_to_cpu_variants", 22 _arch_to_features = "arch_to_features", 23 _arch_to_variants = "arch_to_variants", 24 _ndk_arches = "ndk_arches", 25) 26 27def _flatten_string_list_dict_to_set(string_list_dict): 28 ret = {} 29 for l in string_list_dict.values(): 30 for i in l: 31 ret[i] = True 32 return ret 33 34_arch_variants = _flatten_string_list_dict_to_set(_arch_to_variants) 35_cpu_variants = _flatten_string_list_dict_to_set(_arch_to_cpu_variants) 36_arch_features = _flatten_string_list_dict_to_set(_arch_to_features) 37 38constants = struct( 39 AvailableArchVariants = _arch_variants, 40 AvailableCpuVariants = _cpu_variants, 41 AvailableArchFeatures = _arch_features, 42 ArchToVariants = _arch_to_variants, 43 CpuToVariants = _arch_to_cpu_variants, 44 ArchToFeatures = _arch_to_features, 45 AndroidArchToVariantToFeatures = _android_arch_feature_for_arch_variant, 46 aml_arches = _aml_arches, 47 ndk_arches = _ndk_arches, 48) 49 50def power_set(items, *, include_empty = True): 51 """Calculates the power set of the given items.""" 52 53 def _exp(x, y): 54 result = 1 55 for _ in range(y): 56 result *= x 57 return result 58 59 power_set = [] 60 n = len(items) 61 for i in range(0 if include_empty else 1, _exp(2, n)): 62 combination = [] 63 for j in range(n): 64 if (i >> j) % 2 == 1: 65 combination.append(items[j]) 66 power_set.append(combination) 67 return power_set 68 69arch_variant_to_constraints = { 70 "arm": "//build/bazel_common_rules/platforms/arch:arm", 71 "arm64": "//build/bazel_common_rules/platforms/arch:arm64", 72 "x86": "//build/bazel_common_rules/platforms/arch:x86", 73 "x86_64": "//build/bazel_common_rules/platforms/arch:x86_64", 74 "riscv64": "//build/bazel_common_rules/platforms/arch:riscv64", 75 "android": "//build/bazel_common_rules/platforms/os:android", 76 "darwin": "//build/bazel_common_rules/platforms/os:darwin", 77 "linux": "//build/bazel_common_rules/platforms/os:linux", 78 "linux_bionic": "//build/bazel_common_rules/platforms/os:linux_bionic", 79 "linux_glibc": "//build/bazel_common_rules/platforms/os:linux_glibc", 80 "linux_musl": "//build/bazel_common_rules/platforms/os:linux_musl", 81 "windows": "//build/bazel_common_rules/platforms/os:windows", 82} 83