Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/google/cpu_features.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Chatelet <gchatelet@google.com>2022-02-03 15:56:31 +0300
committerGitHub <noreply@github.com>2022-02-03 15:56:31 +0300
commite38dc6d2a8a855dc4bcea421c23eaf68ddd671e6 (patch)
tree2241a7bbe6b86b92dba09849460618eb8c91f962 /BUILD.bazel
parent5f5e6d620f67063651a511afbf72439888fe3bf2 (diff)
[NFC] Add bazel support to cpu_features (#222)
Diffstat (limited to 'BUILD.bazel')
-rw-r--r--BUILD.bazel320
1 files changed, 320 insertions, 0 deletions
diff --git a/BUILD.bazel b/BUILD.bazel
new file mode 100644
index 0000000..e60e1c4
--- /dev/null
+++ b/BUILD.bazel
@@ -0,0 +1,320 @@
+# cpu_features, a cross platform C99 library to get cpu features at runtime.
+
+load("@bazel_skylib//lib:selects.bzl", "selects")
+load("//:bazel/platforms.bzl", "PLATFORM_CPU_ARM", "PLATFORM_CPU_ARM64", "PLATFORM_CPU_MIPS", "PLATFORM_CPU_PPC", "PLATFORM_CPU_X86_64")
+
+package(
+ default_visibility = ["//visibility:public"],
+ licenses = ["notice"],
+)
+
+exports_files(["LICENSE"])
+
+CC_FLAGS = [
+ "-Iinclude",
+]
+
+C99_FLAGS = CC_FLAGS + [
+ "-std=c99",
+ "-Wall",
+ "-Wextra",
+ "-Wmissing-declarations",
+ "-Wmissing-prototypes",
+ "-Wno-implicit-fallthrough",
+ "-Wno-unused-function",
+ "-Wold-style-definition",
+ "-Wshadow",
+ "-Wsign-compare",
+ "-Wstrict-prototypes",
+]
+
+cc_library(
+ name = "cpu_features_macros",
+ hdrs = ["include/cpu_features_macros.h"],
+ copts = C99_FLAGS,
+)
+
+cc_library(
+ name = "cpu_features_cache_info",
+ hdrs = ["include/cpu_features_cache_info.h"],
+ copts = C99_FLAGS,
+ deps = [":cpu_features_macros"],
+)
+
+cc_library(
+ name = "bit_utils",
+ hdrs = ["include/internal/bit_utils.h"],
+ copts = C99_FLAGS,
+ deps = [":cpu_features_macros"],
+)
+
+cc_test(
+ name = "bit_utils_test",
+ srcs = ["test/bit_utils_test.cc"],
+ copts = CC_FLAGS,
+ deps = [
+ ":bit_utils",
+ "@com_google_googletest//:gtest_main",
+ ],
+)
+
+cc_library(
+ name = "memory_utils",
+ copts = C99_FLAGS,
+ textual_hdrs = [
+ "src/copy.inl",
+ "src/equals.inl",
+ ],
+)
+
+cc_library(
+ name = "string_view",
+ srcs = [
+ "src/string_view.c",
+ ],
+ hdrs = ["include/internal/string_view.h"],
+ copts = C99_FLAGS,
+ deps = [
+ ":cpu_features_macros",
+ ":memory_utils",
+ ],
+)
+
+cc_test(
+ name = "string_view_test",
+ srcs = ["test/string_view_test.cc"],
+ copts = CC_FLAGS,
+ deps = [
+ ":string_view",
+ "@com_google_googletest//:gtest_main",
+ ],
+)
+
+cc_library(
+ name = "filesystem",
+ srcs = ["src/filesystem.c"],
+ hdrs = ["include/internal/filesystem.h"],
+ copts = C99_FLAGS,
+ deps = [":cpu_features_macros"],
+)
+
+cc_library(
+ name = "filesystem_for_testing",
+ testonly = 1,
+ srcs = [
+ "src/filesystem.c",
+ "test/filesystem_for_testing.cc",
+ ],
+ hdrs = [
+ "include/internal/filesystem.h",
+ "test/filesystem_for_testing.h",
+ ],
+ copts = CC_FLAGS,
+ defines = ["CPU_FEATURES_MOCK_FILESYSTEM"],
+ deps = [
+ ":cpu_features_macros",
+ ],
+)
+
+cc_library(
+ name = "stack_line_reader",
+ srcs = ["src/stack_line_reader.c"],
+ hdrs = ["include/internal/stack_line_reader.h"],
+ copts = C99_FLAGS,
+ defines = ["STACK_LINE_READER_BUFFER_SIZE=1024"],
+ deps = [
+ ":cpu_features_macros",
+ ":filesystem",
+ ":string_view",
+ ],
+)
+
+cc_test(
+ name = "stack_line_reader_test",
+ srcs = [
+ "include/internal/stack_line_reader.h",
+ "src/stack_line_reader.c",
+ "test/stack_line_reader_test.cc",
+ ],
+ copts = CC_FLAGS,
+ defines = ["STACK_LINE_READER_BUFFER_SIZE=16"],
+ deps = [
+ ":cpu_features_macros",
+ ":filesystem_for_testing",
+ ":string_view",
+ "@com_google_googletest//:gtest_main",
+ ],
+)
+
+cc_library(
+ name = "stack_line_reader_to_use_with_filesystem_for_testing",
+ testonly = 1,
+ srcs = ["src/stack_line_reader.c"],
+ hdrs = ["include/internal/stack_line_reader.h"],
+ copts = C99_FLAGS,
+ defines = ["STACK_LINE_READER_BUFFER_SIZE=1024"],
+ deps = [
+ ":cpu_features_macros",
+ ":filesystem_for_testing",
+ ":string_view",
+ ],
+)
+
+cc_library(
+ name = "hwcaps",
+ srcs = ["src/hwcaps.c"],
+ hdrs = ["include/internal/hwcaps.h"],
+ copts = C99_FLAGS,
+ defines = ["HAVE_STRONG_GETAUXVAL"],
+ deps = [
+ ":cpu_features_macros",
+ ":filesystem",
+ ":string_view",
+ ],
+)
+
+cc_library(
+ name = "hwcaps_for_testing",
+ testonly = 1,
+ srcs = [
+ "src/hwcaps.c",
+ "test/hwcaps_for_testing.cc",
+ ],
+ hdrs = [
+ "include/internal/hwcaps.h",
+ "test/hwcaps_for_testing.h",
+ ],
+ copts = CC_FLAGS,
+ defines = [
+ "CPU_FEATURES_MOCK_GET_ELF_HWCAP_FROM_GETAUXVAL",
+ "CPU_FEATURES_TEST",
+ ],
+ deps = [
+ ":cpu_features_macros",
+ ":filesystem_for_testing",
+ ":string_view",
+ ],
+)
+
+cc_library(
+ name = "cpuinfo",
+ srcs = selects.with_or({
+ PLATFORM_CPU_X86_64: [
+ "src/impl_x86_freebsd.c",
+ "src/impl_x86_linux_or_android.c",
+ "src/impl_x86_macos.c",
+ "src/impl_x86_windows.c",
+ ],
+ PLATFORM_CPU_ARM: ["src/impl_arm_linux_or_android.c"],
+ PLATFORM_CPU_ARM64: ["src/impl_aarch64_linux_or_android.c"],
+ PLATFORM_CPU_MIPS: ["src/impl_mips_linux_or_android.c"],
+ PLATFORM_CPU_PPC: ["src/impl_ppc_linux.c"],
+ }),
+ hdrs = selects.with_or({
+ PLATFORM_CPU_X86_64: [
+ "include/cpuinfo_x86.h",
+ "include/internal/cpuid_x86.h",
+ ],
+ PLATFORM_CPU_ARM: ["include/cpuinfo_arm.h"],
+ PLATFORM_CPU_ARM64: ["include/cpuinfo_aarch64.h"],
+ PLATFORM_CPU_MIPS: ["include/cpuinfo_mips.h"],
+ PLATFORM_CPU_PPC: ["include/cpuinfo_ppc.h"],
+ }),
+ copts = C99_FLAGS,
+ textual_hdrs = selects.with_or({
+ PLATFORM_CPU_X86_64: ["src/impl_x86__base_implementation.inl"],
+ "//conditions:default": [],
+ }) + [
+ "src/define_introspection.inl",
+ "src/define_introspection_and_hwcaps.inl",
+ ],
+ deps = [
+ ":bit_utils",
+ ":cpu_features_cache_info",
+ ":cpu_features_macros",
+ ":filesystem",
+ ":hwcaps",
+ ":memory_utils",
+ ":stack_line_reader",
+ ":string_view",
+ ],
+)
+
+cc_library(
+ name = "cpuinfo_for_testing",
+ testonly = 1,
+ srcs = selects.with_or({
+ PLATFORM_CPU_X86_64: [
+ "src/impl_x86_freebsd.c",
+ "src/impl_x86_linux_or_android.c",
+ "src/impl_x86_macos.c",
+ "src/impl_x86_windows.c",
+ ],
+ PLATFORM_CPU_ARM: ["src/impl_arm_linux_or_android.c"],
+ PLATFORM_CPU_ARM64: ["src/impl_aarch64_linux_or_android.c"],
+ PLATFORM_CPU_MIPS: ["src/impl_mips_linux_or_android.c"],
+ PLATFORM_CPU_PPC: ["src/impl_ppc_linux.c"],
+ }),
+ hdrs = selects.with_or({
+ PLATFORM_CPU_X86_64: [
+ "include/cpuinfo_x86.h",
+ "include/internal/cpuid_x86.h",
+ ],
+ PLATFORM_CPU_ARM: ["include/cpuinfo_arm.h"],
+ PLATFORM_CPU_ARM64: ["include/cpuinfo_aarch64.h"],
+ PLATFORM_CPU_MIPS: ["include/cpuinfo_mips.h"],
+ PLATFORM_CPU_PPC: ["include/cpuinfo_ppc.h"],
+ }),
+ copts = C99_FLAGS,
+ defines = selects.with_or({
+ PLATFORM_CPU_X86_64: ["CPU_FEATURES_MOCK_CPUID_X86"],
+ "//conditions:default": [],
+ }),
+ textual_hdrs = selects.with_or({
+ PLATFORM_CPU_X86_64: ["src/impl_x86__base_implementation.inl"],
+ "//conditions:default": [],
+ }) + [
+ "src/define_introspection.inl",
+ "src/define_introspection_and_hwcaps.inl",
+ ],
+ deps = [
+ ":bit_utils",
+ ":cpu_features_cache_info",
+ ":cpu_features_macros",
+ ":filesystem_for_testing",
+ ":hwcaps_for_testing",
+ ":memory_utils",
+ ":stack_line_reader_to_use_with_filesystem_for_testing",
+ ":string_view",
+ ],
+)
+
+cc_test(
+ name = "cpuinfo_test",
+ srcs = selects.with_or({
+ 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_X86_64: ["test/cpuinfo_x86_test.cc"],
+ }),
+ copts = CC_FLAGS,
+ deps = [
+ ":cpuinfo_for_testing",
+ ":filesystem_for_testing",
+ ":hwcaps_for_testing",
+ ":string_view",
+ "@com_google_googletest//:gtest_main",
+ ],
+)
+
+cc_binary(
+ name = "list_cpu_features",
+ srcs = ["src/utils/list_cpu_features.c"],
+ copts = C99_FLAGS,
+ deps = [
+ ":bit_utils",
+ ":cpu_features_macros",
+ ":cpuinfo",
+ ],
+)