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_X86_64" )
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_ANDROID" )
56
67package (
78 default_visibility = ["//visibility:public" ],
@@ -168,9 +169,19 @@ cc_library(
168169
169170cc_library (
170171 name = "hwcaps" ,
171- srcs = ["src/hwcaps.c" ],
172+ srcs = [
173+ "src/hwcaps.c" ,
174+ "src/hwcaps_freebsd.c" ,
175+ "src/hwcaps_linux_or_android.c" ,
176+ ],
172177 copts = C99_FLAGS ,
173- defines = ["HAVE_STRONG_GETAUXVAL" ],
178+ defines = selects .with_or ({
179+ PLATFORM_OS_MACOS : ["HAVE_DLFCN_H" ],
180+ PLATFORM_OS_FREEBSD : ["HAVE_STRONG_ELF_AUX_INFO" ],
181+ PLATFORM_OS_LINUX : ["HAVE_STRONG_GETAUXVAL" ],
182+ PLATFORM_OS_ANDROID : ["HAVE_STRONG_GETAUXVAL" ],
183+ "//conditions:default" : [],
184+ }),
174185 includes = INCLUDES ,
175186 textual_hdrs = ["include/internal/hwcaps.h" ],
176187 deps = [
@@ -185,6 +196,8 @@ cc_library(
185196 testonly = 1 ,
186197 srcs = [
187198 "src/hwcaps.c" ,
199+ "src/hwcaps_freebsd.c" ,
200+ "src/hwcaps_linux_or_android.c" ,
188201 "test/hwcaps_for_testing.cc" ,
189202 ],
190203 hdrs = [
@@ -213,26 +226,47 @@ cc_library(
213226 "src/impl_x86_windows.c" ,
214227 ],
215228 PLATFORM_CPU_ARM : ["src/impl_arm_linux_or_android.c" ],
216- PLATFORM_CPU_ARM64 : ["src/impl_aarch64_linux_or_android.c" ],
229+ PLATFORM_CPU_ARM64 : [
230+ "src/impl_aarch64_cpuid.c" ,
231+ "src/impl_aarch64_linux_or_android.c" ,
232+ "src/impl_aarch64_macos_or_iphone.c" ,
233+ "src/impl_aarch64_windows.c" ,
234+ "src/impl_aarch64_freebsd.c" ,
235+ ],
217236 PLATFORM_CPU_MIPS : ["src/impl_mips_linux_or_android.c" ],
218237 PLATFORM_CPU_PPC : [
219238 "src/impl_ppc_freebsd.c" ,
220239 "src/impl_ppc_linux.c" ,
221240 ],
241+ PLATFORM_CPU_RISCV32 : ["src/impl_riscv_linux.c" ],
242+ PLATFORM_CPU_RISCV64 : ["src/impl_riscv_linux.c" ],
222243 }),
223- copts = C99_FLAGS ,
224- includes = INCLUDES ,
225- textual_hdrs = selects .with_or ({
244+ hdrs = selects .with_or ({
226245 PLATFORM_CPU_X86_64 : [
227- "src/impl_x86__base_implementation.inl" ,
228246 "include/cpuinfo_x86.h" ,
229247 "include/internal/cpuid_x86.h" ,
230248 "include/internal/windows_utils.h" ,
231249 ],
232250 PLATFORM_CPU_ARM : ["include/cpuinfo_arm.h" ],
233- PLATFORM_CPU_ARM64 : ["include/cpuinfo_aarch64.h" ],
251+ PLATFORM_CPU_ARM64 : [
252+ "include/cpuinfo_aarch64.h" ,
253+ "include/internal/cpuid_aarch64.h" ,
254+ ],
234255 PLATFORM_CPU_MIPS : ["include/cpuinfo_mips.h" ],
235256 PLATFORM_CPU_PPC : ["include/cpuinfo_ppc.h" ],
257+ PLATFORM_CPU_RISCV32 : ["include/cpuinfo_riscv.h" ],
258+ PLATFORM_CPU_RISCV64 : ["include/cpuinfo_riscv.h" ],
259+ }),
260+ copts = C99_FLAGS ,
261+ defines = selects .with_or ({
262+ PLATFORM_OS_MACOS : ["HAVE_SYSCTLBYNAME" ],
263+ "//conditions:default" : [],
264+ }),
265+ includes = INCLUDES ,
266+ 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" ],
269+ "//conditions:default" : [],
236270 }) + [
237271 "src/define_introspection.inl" ,
238272 "src/define_introspection_and_hwcaps.inl" ,
@@ -260,12 +294,20 @@ cc_library(
260294 "src/impl_x86_windows.c" ,
261295 ],
262296 PLATFORM_CPU_ARM : ["src/impl_arm_linux_or_android.c" ],
263- PLATFORM_CPU_ARM64 : ["src/impl_aarch64_linux_or_android.c" ],
297+ PLATFORM_CPU_ARM64 : [
298+ "src/impl_aarch64_cpuid.c" ,
299+ "src/impl_aarch64_linux_or_android.c" ,
300+ "src/impl_aarch64_macos_or_iphone.c" ,
301+ "src/impl_aarch64_windows.c" ,
302+ "src/impl_aarch64_freebsd.c" ,
303+ ],
264304 PLATFORM_CPU_MIPS : ["src/impl_mips_linux_or_android.c" ],
265305 PLATFORM_CPU_PPC : [
266306 "src/impl_ppc_freebsd.c" ,
267307 "src/impl_ppc_linux.c" ,
268308 ],
309+ PLATFORM_CPU_RISCV32 : ["src/impl_riscv_linux.c" ],
310+ PLATFORM_CPU_RISCV64 : ["src/impl_riscv_linux.c" ],
269311 }),
270312 hdrs = selects .with_or ({
271313 PLATFORM_CPU_X86_64 : [
@@ -274,18 +316,27 @@ cc_library(
274316 "include/internal/windows_utils.h" ,
275317 ],
276318 PLATFORM_CPU_ARM : ["include/cpuinfo_arm.h" ],
277- PLATFORM_CPU_ARM64 : ["include/cpuinfo_aarch64.h" ],
319+ PLATFORM_CPU_ARM64 : [
320+ "include/cpuinfo_aarch64.h" ,
321+ "include/internal/cpuid_aarch64.h"
322+ ],
278323 PLATFORM_CPU_MIPS : ["include/cpuinfo_mips.h" ],
279324 PLATFORM_CPU_PPC : ["include/cpuinfo_ppc.h" ],
325+ PLATFORM_CPU_RISCV32 : ["include/cpuinfo_riscv.h" ],
326+ PLATFORM_CPU_RISCV64 : ["include/cpuinfo_riscv.h" ],
280327 }),
281328 copts = C99_FLAGS ,
282329 defines = selects .with_or ({
283330 PLATFORM_CPU_X86_64 : ["CPU_FEATURES_MOCK_CPUID_X86" ],
284331 "//conditions:default" : [],
332+ }) + selects .with_or ({
333+ PLATFORM_OS_MACOS : ["HAVE_SYSCTLBYNAME" ],
334+ "//conditions:default" : [],
285335 }),
286336 includes = INCLUDES ,
287337 textual_hdrs = selects .with_or ({
288338 PLATFORM_CPU_X86_64 : ["src/impl_x86__base_implementation.inl" ],
339+ PLATFORM_CPU_ARM64 : ["src/impl_aarch64__base_implementation.inl" ],
289340 "//conditions:default" : [],
290341 }) + [
291342 "src/define_introspection.inl" ,
@@ -310,6 +361,8 @@ cc_test(
310361 PLATFORM_CPU_ARM : ["test/cpuinfo_arm_test.cc" ],
311362 PLATFORM_CPU_MIPS : ["test/cpuinfo_mips_test.cc" ],
312363 PLATFORM_CPU_PPC : ["test/cpuinfo_ppc_test.cc" ],
364+ PLATFORM_CPU_RISCV32 : ["test/cpuinfo_riscv_test.cc" ],
365+ PLATFORM_CPU_RISCV64 : ["test/cpuinfo_riscv_test.cc" ],
313366 PLATFORM_CPU_X86_64 : ["test/cpuinfo_x86_test.cc" ],
314367 }),
315368 includes = INCLUDES ,
@@ -333,3 +386,18 @@ cc_binary(
333386 ":cpuinfo" ,
334387 ],
335388)
389+
390+ cc_library (
391+ name = "ndk_compat" ,
392+ srcs = ["ndk_compat/cpu-features.c" ],
393+ copts = C99_FLAGS ,
394+ includes = INCLUDES + ["ndk_compat" ],
395+ textual_hdrs = ["ndk_compat/cpu-features.h" ],
396+ deps = [
397+ ":cpu_features_macros" ,
398+ ":cpuinfo" ,
399+ ":filesystem" ,
400+ ":stack_line_reader" ,
401+ ":string_view" ,
402+ ],
403+ )
0 commit comments