1
1
# cpu_features, a cross platform C99 library to get cpu features at runtime.
2
2
3
3
load ("@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" )
6
4
7
5
package (
8
6
default_visibility = ["//visibility:public" ],
@@ -14,7 +12,7 @@ exports_files(["LICENSE"])
14
12
INCLUDES = ["include" ]
15
13
16
14
C99_FLAGS = select ({
17
- PLATFORM_OS_WINDOWS : [],
15
+ "@platforms//os:windows" : [],
18
16
"//conditions:default" : [
19
17
"-Wall" ,
20
18
"-Wextra" ,
@@ -178,11 +176,9 @@ cc_library(
178
176
],
179
177
copts = C99_FLAGS ,
180
178
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" ],
186
182
"//conditions:default" : [],
187
183
}),
188
184
includes = INCLUDES ,
@@ -222,50 +218,48 @@ cc_library(
222
218
cc_library (
223
219
name = "cpuinfo" ,
224
220
srcs = selects .with_or ({
225
- PLATFORM_CPU_X86_64 : [
221
+ ( "@platforms//cpu:x86_32" , "@platforms//cpu:x86_64" ) : [
226
222
"src/impl_x86_freebsd.c" ,
227
223
"src/impl_x86_linux_or_android.c" ,
228
224
"src/impl_x86_macos.c" ,
229
225
"src/impl_x86_windows.c" ,
230
226
],
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" : [
233
229
"src/impl_aarch64_cpuid.c" ,
234
230
"src/impl_aarch64_linux_or_android.c" ,
235
231
"src/impl_aarch64_macos_or_iphone.c" ,
236
232
"src/impl_aarch64_windows.c" ,
237
233
"src/impl_aarch64_freebsd_or_openbsd.c" ,
238
234
],
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" ],
243
238
}),
244
239
hdrs = selects .with_or ({
245
- PLATFORM_CPU_X86_64 : [
240
+ ( "@platforms//cpu:x86_32" , "@platforms//cpu:x86_64" ) : [
246
241
"include/cpuinfo_x86.h" ,
247
242
"include/internal/cpuid_x86.h" ,
248
243
"include/internal/windows_utils.h" ,
249
244
],
250
- PLATFORM_CPU_ARM : ["include/cpuinfo_arm.h" ],
251
- PLATFORM_CPU_ARM64 : [
245
+ "@platforms//cpu:arm" : ["include/cpuinfo_arm.h" ],
246
+ "@platforms//cpu:arm64" : [
252
247
"include/cpuinfo_aarch64.h" ,
253
248
"include/internal/cpuid_aarch64.h" ,
254
249
],
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" ],
259
253
}),
260
254
copts = C99_FLAGS ,
261
255
defines = selects .with_or ({
262
- PLATFORM_OS_MACOS : ["HAVE_SYSCTLBYNAME" ],
256
+ "@platforms//os:macos" : ["HAVE_SYSCTLBYNAME" ],
263
257
"//conditions:default" : [],
264
258
}),
265
259
includes = INCLUDES ,
266
260
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" ],
269
263
"//conditions:default" : [],
270
264
}) + [
271
265
"src/define_introspection.inl" ,
@@ -287,57 +281,55 @@ cc_library(
287
281
name = "cpuinfo_for_testing" ,
288
282
testonly = 1 ,
289
283
srcs = selects .with_or ({
290
- PLATFORM_CPU_X86_64 : [
284
+ ( "@platforms//cpu:x86_32" , "@platforms//cpu:x86_64" ) : [
291
285
"src/impl_x86_freebsd.c" ,
292
286
"src/impl_x86_linux_or_android.c" ,
293
287
"src/impl_x86_macos.c" ,
294
288
"src/impl_x86_windows.c" ,
295
289
],
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" : [
298
292
"src/impl_aarch64_cpuid.c" ,
299
293
"src/impl_aarch64_linux_or_android.c" ,
300
294
"src/impl_aarch64_macos_or_iphone.c" ,
301
295
"src/impl_aarch64_windows.c" ,
302
296
"src/impl_aarch64_freebsd_or_openbsd.c" ,
303
297
],
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" ],
308
301
}),
309
302
hdrs = selects .with_or ({
310
- PLATFORM_CPU_X86_64 : [
303
+ ( "@platforms//cpu:x86_32" , "@platforms//cpu:x86_64" ) : [
311
304
"include/cpuinfo_x86.h" ,
312
305
"include/internal/cpuid_x86.h" ,
313
306
"include/internal/windows_utils.h" ,
314
307
],
315
- PLATFORM_CPU_ARM : ["include/cpuinfo_arm.h" ],
316
- PLATFORM_CPU_ARM64 : [
308
+ "@platforms//cpu:arm" : ["include/cpuinfo_arm.h" ],
309
+ "@platforms//cpu:arm64" : [
317
310
"include/cpuinfo_aarch64.h" ,
318
311
"include/internal/cpuid_aarch64.h" ,
319
312
],
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" ],
324
316
}),
325
317
copts = C99_FLAGS ,
326
318
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" : [
329
321
"CPU_FEATURES_MOCK_CPUID_AARCH64" ,
330
322
"CPU_FEATURES_MOCK_SYSCTL_AARCH64" ,
331
323
],
332
324
"//conditions:default" : [],
333
325
}) + selects .with_or ({
334
- PLATFORM_OS_MACOS : ["HAVE_SYSCTLBYNAME" ],
326
+ "@platforms//os:macos" : ["HAVE_SYSCTLBYNAME" ],
335
327
"//conditions:default" : [],
336
328
}),
337
329
includes = INCLUDES ,
338
330
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" ],
341
333
"//conditions:default" : [],
342
334
}) + [
343
335
"src/define_introspection.inl" ,
@@ -358,13 +350,12 @@ cc_library(
358
350
cc_test (
359
351
name = "cpuinfo_test" ,
360
352
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" ],
368
359
}),
369
360
includes = INCLUDES ,
370
361
deps = [
@@ -394,7 +385,7 @@ cc_library(
394
385
copts = C99_FLAGS ,
395
386
includes = INCLUDES + ["ndk_compat" ],
396
387
target_compatible_with = select ({
397
- PLATFORM_OS_WINDOWS : ["@platforms//:incompatible" ],
388
+ "@platforms//os:windows" : ["@platforms//:incompatible" ],
398
389
"//conditions:default" : [],
399
390
}),
400
391
textual_hdrs = ["ndk_compat/cpu-features.h" ],
0 commit comments