1# cpuinfo, a library to detect information about the host CPU 2package(default_visibility = ["//visibility:public"]) 3 4licenses(["notice"]) 5 6exports_files(["LICENSE"]) 7 8C99OPTS = [ 9 "-std=gnu99", # gnu99, not c99, because dprintf is used 10 "-Wno-vla", 11 "-D_GNU_SOURCE=1", # to use CPU_SETSIZE 12 "-DCPUINFO_INTERNAL=", 13 "-DCPUINFO_PRIVATE=", 14] 15 16# Source code common to all platforms. 17COMMON_SRCS = [ 18 "src/api.c", 19 "src/init.c", 20 "src/cache.c", 21] 22 23# Architecture-specific sources and headers. 24X86_SRCS = [ 25 "src/x86/cache/descriptor.c", 26 "src/x86/cache/deterministic.c", 27 "src/x86/cache/init.c", 28 "src/x86/info.c", 29 "src/x86/init.c", 30 "src/x86/isa.c", 31 "src/x86/name.c", 32 "src/x86/topology.c", 33 "src/x86/uarch.c", 34 "src/x86/vendor.c", 35] 36 37ARM_SRCS = [ 38 "src/arm/cache.c", 39 "src/arm/uarch.c", 40] 41 42# Platform-specific sources and headers 43LINUX_SRCS = [ 44 "src/linux/cpulist.c", 45 "src/linux/multiline.c", 46 "src/linux/processors.c", 47 "src/linux/smallfile.c", 48] 49 50MOCK_LINUX_SRCS = [ 51 "src/linux/mockfile.c", 52] 53 54MACH_SRCS = [ 55 "src/mach/topology.c", 56] 57 58EMSCRIPTEN_SRCS = [ 59 "src/emscripten/init.c", 60] 61 62LINUX_X86_SRCS = [ 63 "src/x86/linux/cpuinfo.c", 64 "src/x86/linux/init.c", 65] 66 67LINUX_ARM_SRCS = [ 68 "src/arm/linux/chipset.c", 69 "src/arm/linux/clusters.c", 70 "src/arm/linux/cpuinfo.c", 71 "src/arm/linux/hwcap.c", 72 "src/arm/linux/init.c", 73 "src/arm/linux/midr.c", 74] 75 76LINUX_ARM32_SRCS = LINUX_ARM_SRCS + ["src/arm/linux/aarch32-isa.c"] 77 78LINUX_ARM64_SRCS = LINUX_ARM_SRCS + ["src/arm/linux/aarch64-isa.c"] 79 80ANDROID_ARM_SRCS = [ 81 "src/arm/android/properties.c", 82] 83 84WINDOWS_X86_SRCS = [ 85 "src/x86/windows/init.c", 86] 87 88MACH_X86_SRCS = [ 89 "src/x86/mach/init.c", 90] 91 92MACH_ARM_SRCS = [ 93 "src/arm/mach/init.c", 94] 95 96cc_library( 97 name = "clog", 98 srcs = [ 99 "deps/clog/src/clog.c", 100 ], 101 hdrs = [ 102 "deps/clog/include/clog.h", 103 ], 104 copts = select({ 105 ":windows_x86_64": [], 106 "//conditions:default": ["-Wno-unused-result"], 107 }), 108 linkopts = select({ 109 ":android": ["-llog"], 110 "//conditions:default": [], 111 }), 112 linkstatic = select({ 113 # https://github.com/bazelbuild/bazel/issues/11552 114 ":macos_x86_64": False, 115 "//conditions:default": True, 116 }), 117 defines = select({ 118 # When linkstatic=False, we need default visibility 119 ":macos_x86_64": ["CLOG_VISIBILITY="], 120 "//conditions:default": [], 121 }), 122 strip_include_prefix = "deps/clog/include", 123) 124 125cc_library( 126 name = "cpuinfo_impl", 127 srcs = select({ 128 ":linux_x86_64": COMMON_SRCS + X86_SRCS + LINUX_SRCS + LINUX_X86_SRCS, 129 ":linux_arm": COMMON_SRCS + ARM_SRCS + LINUX_SRCS + LINUX_ARM32_SRCS, 130 ":linux_armhf": COMMON_SRCS + ARM_SRCS + LINUX_SRCS + LINUX_ARM32_SRCS, 131 ":linux_armv7a": COMMON_SRCS + ARM_SRCS + LINUX_SRCS + LINUX_ARM32_SRCS, 132 ":linux_armeabi": COMMON_SRCS + ARM_SRCS + LINUX_SRCS + LINUX_ARM32_SRCS, 133 ":linux_aarch64": COMMON_SRCS + ARM_SRCS + LINUX_SRCS + LINUX_ARM64_SRCS, 134 ":macos_x86_64": COMMON_SRCS + X86_SRCS + MACH_SRCS + MACH_X86_SRCS, 135 ":windows_x86_64": COMMON_SRCS + X86_SRCS + WINDOWS_X86_SRCS, 136 ":android_armv7": COMMON_SRCS + ARM_SRCS + LINUX_SRCS + LINUX_ARM32_SRCS + ANDROID_ARM_SRCS, 137 ":android_arm64": COMMON_SRCS + ARM_SRCS + LINUX_SRCS + LINUX_ARM64_SRCS + ANDROID_ARM_SRCS, 138 ":android_x86": COMMON_SRCS + X86_SRCS + LINUX_SRCS + LINUX_X86_SRCS, 139 ":android_x86_64": COMMON_SRCS + X86_SRCS + LINUX_SRCS + LINUX_X86_SRCS, 140 ":ios_x86_64": COMMON_SRCS + X86_SRCS + MACH_SRCS + MACH_X86_SRCS, 141 ":ios_x86": COMMON_SRCS + X86_SRCS + MACH_SRCS + MACH_X86_SRCS, 142 ":ios_armv7": COMMON_SRCS + MACH_SRCS + MACH_ARM_SRCS, 143 ":ios_arm64": COMMON_SRCS + MACH_SRCS + MACH_ARM_SRCS, 144 ":ios_arm64e": COMMON_SRCS + MACH_SRCS + MACH_ARM_SRCS, 145 ":watchos_x86_64": COMMON_SRCS + X86_SRCS + MACH_SRCS + MACH_X86_SRCS, 146 ":watchos_x86": COMMON_SRCS + X86_SRCS + MACH_SRCS + MACH_X86_SRCS, 147 ":watchos_armv7k": COMMON_SRCS + MACH_SRCS + MACH_ARM_SRCS, 148 ":watchos_arm64_32": COMMON_SRCS + MACH_SRCS + MACH_ARM_SRCS, 149 ":tvos_x86_64": COMMON_SRCS + X86_SRCS + MACH_SRCS + MACH_X86_SRCS, 150 ":tvos_arm64": COMMON_SRCS + MACH_SRCS + MACH_ARM_SRCS, 151 ":emscripten": COMMON_SRCS + EMSCRIPTEN_SRCS, 152 }), 153 copts = select({ 154 ":windows_x86_64": [], 155 "//conditions:default": C99OPTS, 156 }) + [ 157 "-Iexternal/cpuinfo/include", 158 "-Iexternal/cpuinfo/src", 159 ], 160 linkstatic = select({ 161 # https://github.com/bazelbuild/bazel/issues/11552 162 ":macos_x86_64": False, 163 "//conditions:default": True, 164 }), 165 # Headers must be in textual_hdrs to allow us to set the standard to C99 166 textual_hdrs = [ 167 "include/cpuinfo.h", 168 "src/linux/api.h", 169 "src/mach/api.h", 170 "src/cpuinfo/common.h", 171 "src/cpuinfo/internal-api.h", 172 "src/cpuinfo/log.h", 173 "src/cpuinfo/utils.h", 174 "src/x86/api.h", 175 "src/x86/cpuid.h", 176 "src/x86/linux/api.h", 177 "src/arm/android/api.h", 178 "src/arm/linux/api.h", 179 "src/arm/linux/cp.h", 180 "src/arm/api.h", 181 "src/arm/midr.h", 182 ], 183 deps = [ 184 ":clog", 185 ], 186) 187 188cc_library( 189 name = "cpuinfo", 190 hdrs = [ 191 "include/cpuinfo.h", 192 ], 193 strip_include_prefix = "include", 194 deps = [ 195 ":cpuinfo_impl", 196 ], 197) 198 199cc_library( 200 name = "cpuinfo_with_unstripped_include_path", 201 hdrs = [ 202 "include/cpuinfo.h", 203 ], 204 deps = [ 205 ":cpuinfo_impl", 206 ], 207) 208 209############################# Build configurations ############################# 210 211config_setting( 212 name = "linux_x86_64", 213 values = {"cpu": "k8"}, 214) 215 216config_setting( 217 name = "linux_arm", 218 values = {"cpu": "arm"}, 219) 220 221config_setting( 222 name = "linux_armhf", 223 values = {"cpu": "armhf"}, 224) 225 226config_setting( 227 name = "linux_armv7a", 228 values = {"cpu": "armv7a"}, 229) 230 231config_setting( 232 name = "linux_armeabi", 233 values = {"cpu": "armeabi"}, 234) 235 236config_setting( 237 name = "linux_aarch64", 238 values = {"cpu": "aarch64"}, 239) 240 241config_setting( 242 name = "macos_x86_64", 243 values = { 244 "apple_platform_type": "macos", 245 "cpu": "darwin", 246 }, 247) 248 249config_setting( 250 name = "android", 251 values = {"crosstool_top": "//external:android/crosstool"}, 252) 253 254config_setting( 255 name = "windows_x86_64", 256 values = {"cpu": "x64_windows"}, 257) 258 259config_setting( 260 name = "android_armv7", 261 values = { 262 "crosstool_top": "//external:android/crosstool", 263 "cpu": "armeabi-v7a", 264 }, 265 visibility = ["//visibility:public"], 266) 267 268config_setting( 269 name = "android_arm64", 270 values = { 271 "crosstool_top": "//external:android/crosstool", 272 "cpu": "arm64-v8a", 273 }, 274 visibility = ["//visibility:public"], 275) 276 277config_setting( 278 name = "android_x86", 279 values = { 280 "crosstool_top": "//external:android/crosstool", 281 "cpu": "x86", 282 }, 283 visibility = ["//visibility:public"], 284) 285 286config_setting( 287 name = "android_x86_64", 288 values = { 289 "crosstool_top": "//external:android/crosstool", 290 "cpu": "x86_64", 291 }, 292 visibility = ["//visibility:public"], 293) 294 295config_setting( 296 name = "ios_armv7", 297 values = { 298 "apple_platform_type": "ios", 299 "cpu": "ios_armv7", 300 }, 301) 302 303config_setting( 304 name = "ios_arm64", 305 values = { 306 "apple_platform_type": "ios", 307 "cpu": "ios_arm64", 308 }, 309) 310 311config_setting( 312 name = "ios_arm64e", 313 values = { 314 "apple_platform_type": "ios", 315 "cpu": "ios_arm64e", 316 }, 317) 318 319config_setting( 320 name = "ios_x86", 321 values = { 322 "apple_platform_type": "ios", 323 "cpu": "ios_i386", 324 }, 325) 326 327config_setting( 328 name = "ios_x86_64", 329 values = { 330 "apple_platform_type": "ios", 331 "cpu": "ios_x86_64", 332 }, 333) 334 335config_setting( 336 name = "watchos_armv7k", 337 values = { 338 "apple_platform_type": "watchos", 339 "cpu": "watchos_armv7k", 340 }, 341) 342 343config_setting( 344 name = "watchos_arm64_32", 345 values = { 346 "apple_platform_type": "watchos", 347 "cpu": "watchos_arm64_32", 348 }, 349) 350 351config_setting( 352 name = "watchos_x86", 353 values = { 354 "apple_platform_type": "watchos", 355 "cpu": "watchos_i386", 356 }, 357) 358 359config_setting( 360 name = "watchos_x86_64", 361 values = { 362 "apple_platform_type": "watchos", 363 "cpu": "watchos_x86_64", 364 }, 365) 366 367config_setting( 368 name = "tvos_arm64", 369 values = { 370 "apple_platform_type": "tvos", 371 "cpu": "tvos_arm64", 372 }, 373) 374 375config_setting( 376 name = "tvos_x86_64", 377 values = { 378 "apple_platform_type": "tvos", 379 "cpu": "tvos_x86_64", 380 }, 381) 382 383config_setting( 384 name = "emscripten", 385 values = {"crosstool_top": "//toolchain:emscripten"}, 386) 387