11# cpu_features, a cross platform C99 library to get cpu features at runtime.
22
33load ("@bazel_skylib//lib:selects.bzl" , "selects" )
4- load ("//:bazel/platforms.bzl" , "PLATFORM_CPU_ARM" , "PLATFORM_CPU_ARM64" , "PLATFORM_CPU_MIPS" , "PLATFORM_CPU_PPC" , "PLATFORM_CPU_RISCV32" , "PLATFORM_CPU_RISCV64" , "PLATFORM_CPU_X86_64" )
5- load ("//:bazel/platforms.bzl" , "PLATFORM_OS_MACOS" , "PLATFORM_OS_LINUX" , "PLATFORM_OS_FREEBSD" , "PLATFORM_OS_OPENBSD" , "PLATFORM_OS_ANDROID" , "PLATFORM_OS_WINDOWS" )
64
75package (
86 default_visibility = ["//visibility:public" ],
@@ -14,7 +12,7 @@ exports_files(["LICENSE"])
1412INCLUDES = ["include" ]
1513
1614C99_FLAGS = select ({
17- PLATFORM_OS_WINDOWS : [],
15+ "@platforms//os:windows" : [],
1816 "//conditions:default" : [
1917 "-Wall" ,
2018 "-Wextra" ,
@@ -178,11 +176,9 @@ cc_library(
178176 ],
179177 copts = C99_FLAGS ,
180178 defines = selects .with_or ({
181- PLATFORM_OS_MACOS : ["HAVE_DLFCN_H" ],
182- PLATFORM_OS_FREEBSD : ["HAVE_STRONG_ELF_AUX_INFO" ],
183- PLATFORM_OS_OPENBSD : ["HAVE_STRONG_ELF_AUX_INFO" ],
184- PLATFORM_OS_LINUX : ["HAVE_STRONG_GETAUXVAL" ],
185- PLATFORM_OS_ANDROID : ["HAVE_STRONG_GETAUXVAL" ],
179+ "@platforms//os:macos" : ["HAVE_DLFCN_H" ],
180+ ("@platforms//os:freebsd" , "@platforms//os:openbsd" ): ["HAVE_STRONG_ELF_AUX_INFO" ],
181+ ("@platforms//os:android" , "@platforms//os:linux" ): ["HAVE_STRONG_GETAUXVAL" ],
186182 "//conditions:default" : [],
187183 }),
188184 includes = INCLUDES ,
@@ -222,50 +218,48 @@ cc_library(
222218cc_library (
223219 name = "cpuinfo" ,
224220 srcs = selects .with_or ({
225- PLATFORM_CPU_X86_64 : [
221+ ( "@platforms//cpu:x86_32" , "@platforms//cpu:x86_64" ) : [
226222 "src/impl_x86_freebsd.c" ,
227223 "src/impl_x86_linux_or_android.c" ,
228224 "src/impl_x86_macos.c" ,
229225 "src/impl_x86_windows.c" ,
230226 ],
231- PLATFORM_CPU_ARM : ["src/impl_arm_linux_or_android.c" ],
232- PLATFORM_CPU_ARM64 : [
227+ "@platforms//cpu:arm" : ["src/impl_arm_linux_or_android.c" ],
228+ "@platforms//cpu:arm64" : [
233229 "src/impl_aarch64_cpuid.c" ,
234230 "src/impl_aarch64_linux_or_android.c" ,
235231 "src/impl_aarch64_macos_or_iphone.c" ,
236232 "src/impl_aarch64_windows.c" ,
237233 "src/impl_aarch64_freebsd_or_openbsd.c" ,
238234 ],
239- PLATFORM_CPU_MIPS : ["src/impl_mips_linux_or_android.c" ],
240- PLATFORM_CPU_PPC : ["src/impl_ppc_linux.c" ],
241- PLATFORM_CPU_RISCV32 : ["src/impl_riscv_linux.c" ],
242- PLATFORM_CPU_RISCV64 : ["src/impl_riscv_linux.c" ],
235+ "@platforms//cpu:mips64" : ["src/impl_mips_linux_or_android.c" ],
236+ "@platforms//cpu:ppc" : ["src/impl_ppc_linux.c" ],
237+ ("@platforms//cpu:riscv32" , "@platforms//cpu:riscv64" ): ["src/impl_riscv_linux.c" ],
243238 }),
244239 hdrs = selects .with_or ({
245- PLATFORM_CPU_X86_64 : [
240+ ( "@platforms//cpu:x86_32" , "@platforms//cpu:x86_64" ) : [
246241 "include/cpuinfo_x86.h" ,
247242 "include/internal/cpuid_x86.h" ,
248243 "include/internal/windows_utils.h" ,
249244 ],
250- PLATFORM_CPU_ARM : ["include/cpuinfo_arm.h" ],
251- PLATFORM_CPU_ARM64 : [
245+ "@platforms//cpu:arm" : ["include/cpuinfo_arm.h" ],
246+ "@platforms//cpu:arm64" : [
252247 "include/cpuinfo_aarch64.h" ,
253248 "include/internal/cpuid_aarch64.h" ,
254249 ],
255- PLATFORM_CPU_MIPS : ["include/cpuinfo_mips.h" ],
256- PLATFORM_CPU_PPC : ["include/cpuinfo_ppc.h" ],
257- PLATFORM_CPU_RISCV32 : ["include/cpuinfo_riscv.h" ],
258- PLATFORM_CPU_RISCV64 : ["include/cpuinfo_riscv.h" ],
250+ "@platforms//cpu:mips64" : ["include/cpuinfo_mips.h" ],
251+ "@platforms//cpu:ppc" : ["include/cpuinfo_ppc.h" ],
252+ ("@platforms//cpu:riscv32" , "@platforms//cpu:riscv64" ): ["include/cpuinfo_riscv.h" ],
259253 }),
260254 copts = C99_FLAGS ,
261255 defines = selects .with_or ({
262- PLATFORM_OS_MACOS : ["HAVE_SYSCTLBYNAME" ],
256+ "@platforms//os:macos" : ["HAVE_SYSCTLBYNAME" ],
263257 "//conditions:default" : [],
264258 }),
265259 includes = INCLUDES ,
266260 textual_hdrs = selects .with_or ({
267- PLATFORM_CPU_X86_64 : ["src/impl_x86__base_implementation.inl" ],
268- PLATFORM_CPU_ARM64 : ["src/impl_aarch64__base_implementation.inl" ],
261+ ( "@platforms//cpu:x86_32" , "@platforms//cpu:x86_64" ) : ["src/impl_x86__base_implementation.inl" ],
262+ "@platforms//cpu:arm64" : ["src/impl_aarch64__base_implementation.inl" ],
269263 "//conditions:default" : [],
270264 }) + [
271265 "src/define_introspection.inl" ,
@@ -287,57 +281,55 @@ cc_library(
287281 name = "cpuinfo_for_testing" ,
288282 testonly = 1 ,
289283 srcs = selects .with_or ({
290- PLATFORM_CPU_X86_64 : [
284+ ( "@platforms//cpu:x86_32" , "@platforms//cpu:x86_64" ) : [
291285 "src/impl_x86_freebsd.c" ,
292286 "src/impl_x86_linux_or_android.c" ,
293287 "src/impl_x86_macos.c" ,
294288 "src/impl_x86_windows.c" ,
295289 ],
296- PLATFORM_CPU_ARM : ["src/impl_arm_linux_or_android.c" ],
297- PLATFORM_CPU_ARM64 : [
290+ "@platforms//cpu:arm" : ["src/impl_arm_linux_or_android.c" ],
291+ "@platforms//cpu:arm64" : [
298292 "src/impl_aarch64_cpuid.c" ,
299293 "src/impl_aarch64_linux_or_android.c" ,
300294 "src/impl_aarch64_macos_or_iphone.c" ,
301295 "src/impl_aarch64_windows.c" ,
302296 "src/impl_aarch64_freebsd_or_openbsd.c" ,
303297 ],
304- PLATFORM_CPU_MIPS : ["src/impl_mips_linux_or_android.c" ],
305- PLATFORM_CPU_PPC : ["src/impl_ppc_linux.c" ],
306- PLATFORM_CPU_RISCV32 : ["src/impl_riscv_linux.c" ],
307- PLATFORM_CPU_RISCV64 : ["src/impl_riscv_linux.c" ],
298+ "@platforms//cpu:mips64" : ["src/impl_mips_linux_or_android.c" ],
299+ "@platforms//cpu:ppc" : ["src/impl_ppc_linux.c" ],
300+ ("@platforms//cpu:riscv32" , "@platforms//cpu:riscv64" ): ["src/impl_riscv_linux.c" ],
308301 }),
309302 hdrs = selects .with_or ({
310- PLATFORM_CPU_X86_64 : [
303+ ( "@platforms//cpu:x86_32" , "@platforms//cpu:x86_64" ) : [
311304 "include/cpuinfo_x86.h" ,
312305 "include/internal/cpuid_x86.h" ,
313306 "include/internal/windows_utils.h" ,
314307 ],
315- PLATFORM_CPU_ARM : ["include/cpuinfo_arm.h" ],
316- PLATFORM_CPU_ARM64 : [
308+ "@platforms//cpu:arm" : ["include/cpuinfo_arm.h" ],
309+ "@platforms//cpu:arm64" : [
317310 "include/cpuinfo_aarch64.h" ,
318311 "include/internal/cpuid_aarch64.h" ,
319312 ],
320- PLATFORM_CPU_MIPS : ["include/cpuinfo_mips.h" ],
321- PLATFORM_CPU_PPC : ["include/cpuinfo_ppc.h" ],
322- PLATFORM_CPU_RISCV32 : ["include/cpuinfo_riscv.h" ],
323- PLATFORM_CPU_RISCV64 : ["include/cpuinfo_riscv.h" ],
313+ "@platforms//cpu:mips64" : ["include/cpuinfo_mips.h" ],
314+ "@platforms//cpu:ppc" : ["include/cpuinfo_ppc.h" ],
315+ ("@platforms//cpu:riscv32" , "@platforms//cpu:riscv64" ): ["include/cpuinfo_riscv.h" ],
324316 }),
325317 copts = C99_FLAGS ,
326318 defines = selects .with_or ({
327- PLATFORM_CPU_X86_64 : ["CPU_FEATURES_MOCK_CPUID_X86" ],
328- PLATFORM_CPU_ARM64 : [
319+ ( "@platforms//cpu:x86_32" , "@platforms//cpu:x86_64" ) : ["CPU_FEATURES_MOCK_CPUID_X86" ],
320+ "@platforms//cpu:arm64" : [
329321 "CPU_FEATURES_MOCK_CPUID_AARCH64" ,
330322 "CPU_FEATURES_MOCK_SYSCTL_AARCH64" ,
331323 ],
332324 "//conditions:default" : [],
333325 }) + selects .with_or ({
334- PLATFORM_OS_MACOS : ["HAVE_SYSCTLBYNAME" ],
326+ "@platforms//os:macos" : ["HAVE_SYSCTLBYNAME" ],
335327 "//conditions:default" : [],
336328 }),
337329 includes = INCLUDES ,
338330 textual_hdrs = selects .with_or ({
339- PLATFORM_CPU_X86_64 : ["src/impl_x86__base_implementation.inl" ],
340- PLATFORM_CPU_ARM64 : ["src/impl_aarch64__base_implementation.inl" ],
331+ ( "@platforms//cpu:x86_32" , "@platforms//cpu:x86_64" ) : ["src/impl_x86__base_implementation.inl" ],
332+ "@platforms//cpu:arm64" : ["src/impl_aarch64__base_implementation.inl" ],
341333 "//conditions:default" : [],
342334 }) + [
343335 "src/define_introspection.inl" ,
@@ -358,13 +350,12 @@ cc_library(
358350cc_test (
359351 name = "cpuinfo_test" ,
360352 srcs = selects .with_or ({
361- PLATFORM_CPU_ARM64 : ["test/cpuinfo_aarch64_test.cc" ],
362- PLATFORM_CPU_ARM : ["test/cpuinfo_arm_test.cc" ],
363- PLATFORM_CPU_MIPS : ["test/cpuinfo_mips_test.cc" ],
364- PLATFORM_CPU_PPC : ["test/cpuinfo_ppc_test.cc" ],
365- PLATFORM_CPU_RISCV32 : ["test/cpuinfo_riscv_test.cc" ],
366- PLATFORM_CPU_RISCV64 : ["test/cpuinfo_riscv_test.cc" ],
367- PLATFORM_CPU_X86_64 : ["test/cpuinfo_x86_test.cc" ],
353+ "@platforms//cpu:arm64" : ["test/cpuinfo_aarch64_test.cc" ],
354+ "@platforms//cpu:arm" : ["test/cpuinfo_arm_test.cc" ],
355+ "@platforms//cpu:mips64" : ["test/cpuinfo_mips_test.cc" ],
356+ "@platforms//cpu:ppc" : ["test/cpuinfo_ppc_test.cc" ],
357+ ("@platforms//cpu:riscv32" , "@platforms//cpu:riscv64" ): ["test/cpuinfo_riscv_test.cc" ],
358+ ("@platforms//cpu:x86_32" , "@platforms//cpu:x86_64" ): ["test/cpuinfo_x86_test.cc" ],
368359 }),
369360 includes = INCLUDES ,
370361 deps = [
@@ -394,7 +385,7 @@ cc_library(
394385 copts = C99_FLAGS ,
395386 includes = INCLUDES + ["ndk_compat" ],
396387 target_compatible_with = select ({
397- PLATFORM_OS_WINDOWS : ["@platforms//:incompatible" ],
388+ "@platforms//os:windows" : ["@platforms//:incompatible" ],
398389 "//conditions:default" : [],
399390 }),
400391 textual_hdrs = ["ndk_compat/cpu-features.h" ],
0 commit comments