From 91c50b689da6aba20cd80bc064714b86ea7fd5be Mon Sep 17 00:00:00 2001
From: Guillaume Chatelet <gchatelet@google.com>
Date: Wed, 18 Dec 2024 15:18:09 +0000
Subject: [PATCH] [bazel] Add armv7 and use alias for cpus

---
 BUILD.bazel | 84 ++++++++++++++++++++++++++++++-----------------------
 1 file changed, 48 insertions(+), 36 deletions(-)

diff --git a/BUILD.bazel b/BUILD.bazel
index 25c10bf..ff0367d 100644
--- a/BUILD.bazel
+++ b/BUILD.bazel
@@ -27,6 +27,18 @@ C99_FLAGS = select({
     ],
 })
 
+PLATFORM_CPU_X86 = ("@platforms//cpu:x86_32", "@platforms//cpu:x86_64")
+
+PLATFORM_CPU_ARM = ("@platforms//cpu:arm", "@platforms//cpu:armv7")
+
+PLATFORM_CPU_ARM64 = "@platforms//cpu:arm64"
+
+PLATFORM_CPU_MIPS = "@platforms//cpu:mips64"
+
+PLATFORM_CPU_PPC = "@platforms//cpu:ppc"
+
+PLATFORM_CPU_RISCV = ("@platforms//cpu:riscv32", "@platforms//cpu:riscv64")
+
 cc_library(
     name = "cpu_features_macros",
     copts = C99_FLAGS,
@@ -218,38 +230,38 @@ cc_library(
 cc_library(
     name = "cpuinfo",
     srcs = selects.with_or({
-        ("@platforms//cpu:x86_32", "@platforms//cpu:x86_64"): [
+        PLATFORM_CPU_X86: [
             "src/impl_x86_freebsd.c",
             "src/impl_x86_linux_or_android.c",
             "src/impl_x86_macos.c",
             "src/impl_x86_windows.c",
         ],
-        "@platforms//cpu:arm": ["src/impl_arm_linux_or_android.c"],
-        "@platforms//cpu:arm64": [
+        PLATFORM_CPU_ARM: ["src/impl_arm_linux_or_android.c"],
+        PLATFORM_CPU_ARM64: [
             "src/impl_aarch64_cpuid.c",
             "src/impl_aarch64_linux_or_android.c",
             "src/impl_aarch64_macos_or_iphone.c",
             "src/impl_aarch64_windows.c",
             "src/impl_aarch64_freebsd_or_openbsd.c",
         ],
-        "@platforms//cpu:mips64": ["src/impl_mips_linux_or_android.c"],
-        "@platforms//cpu:ppc": ["src/impl_ppc_linux.c"],
-        ("@platforms//cpu:riscv32", "@platforms//cpu:riscv64"): ["src/impl_riscv_linux.c"],
+        PLATFORM_CPU_MIPS: ["src/impl_mips_linux_or_android.c"],
+        PLATFORM_CPU_PPC: ["src/impl_ppc_linux.c"],
+        PLATFORM_CPU_RISCV: ["src/impl_riscv_linux.c"],
     }),
     hdrs = selects.with_or({
-        ("@platforms//cpu:x86_32", "@platforms//cpu:x86_64"): [
+        PLATFORM_CPU_X86: [
             "include/cpuinfo_x86.h",
             "include/internal/cpuid_x86.h",
             "include/internal/windows_utils.h",
         ],
-        "@platforms//cpu:arm": ["include/cpuinfo_arm.h"],
-        "@platforms//cpu:arm64": [
+        PLATFORM_CPU_ARM: ["include/cpuinfo_arm.h"],
+        PLATFORM_CPU_ARM64: [
             "include/cpuinfo_aarch64.h",
             "include/internal/cpuid_aarch64.h",
         ],
-        "@platforms//cpu:mips64": ["include/cpuinfo_mips.h"],
-        "@platforms//cpu:ppc": ["include/cpuinfo_ppc.h"],
-        ("@platforms//cpu:riscv32", "@platforms//cpu:riscv64"): ["include/cpuinfo_riscv.h"],
+        PLATFORM_CPU_MIPS: ["include/cpuinfo_mips.h"],
+        PLATFORM_CPU_PPC: ["include/cpuinfo_ppc.h"],
+        PLATFORM_CPU_RISCV: ["include/cpuinfo_riscv.h"],
     }),
     copts = C99_FLAGS,
     defines = selects.with_or({
@@ -258,8 +270,8 @@ cc_library(
     }),
     includes = INCLUDES,
     textual_hdrs = selects.with_or({
-        ("@platforms//cpu:x86_32", "@platforms//cpu:x86_64"): ["src/impl_x86__base_implementation.inl"],
-        "@platforms//cpu:arm64": ["src/impl_aarch64__base_implementation.inl"],
+        PLATFORM_CPU_X86: ["src/impl_x86__base_implementation.inl"],
+        PLATFORM_CPU_ARM64: ["src/impl_aarch64__base_implementation.inl"],
         "//conditions:default": [],
     }) + [
         "src/define_introspection.inl",
@@ -281,43 +293,43 @@ cc_library(
     name = "cpuinfo_for_testing",
     testonly = 1,
     srcs = selects.with_or({
-        ("@platforms//cpu:x86_32", "@platforms//cpu:x86_64"): [
+        PLATFORM_CPU_X86: [
             "src/impl_x86_freebsd.c",
             "src/impl_x86_linux_or_android.c",
             "src/impl_x86_macos.c",
             "src/impl_x86_windows.c",
         ],
-        "@platforms//cpu:arm": ["src/impl_arm_linux_or_android.c"],
-        "@platforms//cpu:arm64": [
+        PLATFORM_CPU_ARM: ["src/impl_arm_linux_or_android.c"],
+        PLATFORM_CPU_ARM64: [
             "src/impl_aarch64_cpuid.c",
             "src/impl_aarch64_linux_or_android.c",
             "src/impl_aarch64_macos_or_iphone.c",
             "src/impl_aarch64_windows.c",
             "src/impl_aarch64_freebsd_or_openbsd.c",
         ],
-        "@platforms//cpu:mips64": ["src/impl_mips_linux_or_android.c"],
-        "@platforms//cpu:ppc": ["src/impl_ppc_linux.c"],
-        ("@platforms//cpu:riscv32", "@platforms//cpu:riscv64"): ["src/impl_riscv_linux.c"],
+        PLATFORM_CPU_MIPS: ["src/impl_mips_linux_or_android.c"],
+        PLATFORM_CPU_PPC: ["src/impl_ppc_linux.c"],
+        PLATFORM_CPU_RISCV: ["src/impl_riscv_linux.c"],
     }),
     hdrs = selects.with_or({
-        ("@platforms//cpu:x86_32", "@platforms//cpu:x86_64"): [
+        PLATFORM_CPU_X86: [
             "include/cpuinfo_x86.h",
             "include/internal/cpuid_x86.h",
             "include/internal/windows_utils.h",
         ],
-        "@platforms//cpu:arm": ["include/cpuinfo_arm.h"],
-        "@platforms//cpu:arm64": [
+        PLATFORM_CPU_ARM: ["include/cpuinfo_arm.h"],
+        PLATFORM_CPU_ARM64: [
             "include/cpuinfo_aarch64.h",
             "include/internal/cpuid_aarch64.h",
         ],
-        "@platforms//cpu:mips64": ["include/cpuinfo_mips.h"],
-        "@platforms//cpu:ppc": ["include/cpuinfo_ppc.h"],
-        ("@platforms//cpu:riscv32", "@platforms//cpu:riscv64"): ["include/cpuinfo_riscv.h"],
+        PLATFORM_CPU_MIPS: ["include/cpuinfo_mips.h"],
+        PLATFORM_CPU_PPC: ["include/cpuinfo_ppc.h"],
+        PLATFORM_CPU_RISCV: ["include/cpuinfo_riscv.h"],
     }),
     copts = C99_FLAGS,
     defines = selects.with_or({
-        ("@platforms//cpu:x86_32", "@platforms//cpu:x86_64"): ["CPU_FEATURES_MOCK_CPUID_X86"],
-        "@platforms//cpu:arm64": [
+        PLATFORM_CPU_X86: ["CPU_FEATURES_MOCK_CPUID_X86"],
+        PLATFORM_CPU_ARM64: [
             "CPU_FEATURES_MOCK_CPUID_AARCH64",
             "CPU_FEATURES_MOCK_SYSCTL_AARCH64",
         ],
@@ -328,8 +340,8 @@ cc_library(
     }),
     includes = INCLUDES,
     textual_hdrs = selects.with_or({
-        ("@platforms//cpu:x86_32", "@platforms//cpu:x86_64"): ["src/impl_x86__base_implementation.inl"],
-        "@platforms//cpu:arm64": ["src/impl_aarch64__base_implementation.inl"],
+        PLATFORM_CPU_X86: ["src/impl_x86__base_implementation.inl"],
+        PLATFORM_CPU_ARM64: ["src/impl_aarch64__base_implementation.inl"],
         "//conditions:default": [],
     }) + [
         "src/define_introspection.inl",
@@ -350,12 +362,12 @@ cc_library(
 cc_test(
     name = "cpuinfo_test",
     srcs = selects.with_or({
-        "@platforms//cpu:arm64": ["test/cpuinfo_aarch64_test.cc"],
-        "@platforms//cpu:arm": ["test/cpuinfo_arm_test.cc"],
-        "@platforms//cpu:mips64": ["test/cpuinfo_mips_test.cc"],
-        "@platforms//cpu:ppc": ["test/cpuinfo_ppc_test.cc"],
-        ("@platforms//cpu:riscv32", "@platforms//cpu:riscv64"): ["test/cpuinfo_riscv_test.cc"],
-        ("@platforms//cpu:x86_32", "@platforms//cpu:x86_64"): ["test/cpuinfo_x86_test.cc"],
+        PLATFORM_CPU_ARM64: ["test/cpuinfo_aarch64_test.cc"],
+        PLATFORM_CPU_ARM: ["test/cpuinfo_arm_test.cc"],
+        PLATFORM_CPU_MIPS: ["test/cpuinfo_mips_test.cc"],
+        PLATFORM_CPU_PPC: ["test/cpuinfo_ppc_test.cc"],
+        PLATFORM_CPU_RISCV: ["test/cpuinfo_riscv_test.cc"],
+        PLATFORM_CPU_X86: ["test/cpuinfo_x86_test.cc"],
     }),
     includes = INCLUDES,
     deps = [