mirror of
https://github.com/google/cpu_features.git
synced 2025-04-27 15:12:30 +02:00
Merge pull request #381 from google/remove_platforms_bzl
[bazel] inline platforms and remove `platforms.bzl` note: replace `PLATFORM_CPU_X86_64` by `"@platforms//cpu:x86_32", "@platforms//cpu:x86_64"`
This commit is contained in:
commit
5cfee57d36
95
BUILD.bazel
95
BUILD.bazel
@ -1,8 +1,6 @@
|
|||||||
# cpu_features, a cross platform C99 library to get cpu features at runtime.
|
# cpu_features, a cross platform C99 library to get cpu features at runtime.
|
||||||
|
|
||||||
load("@bazel_skylib//lib:selects.bzl", "selects")
|
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_RISCV32", "PLATFORM_CPU_RISCV64", "PLATFORM_CPU_X86_64")
|
|
||||||
load("//:bazel/platforms.bzl", "PLATFORM_OS_MACOS", "PLATFORM_OS_LINUX", "PLATFORM_OS_FREEBSD", "PLATFORM_OS_OPENBSD", "PLATFORM_OS_ANDROID", "PLATFORM_OS_WINDOWS")
|
|
||||||
|
|
||||||
package(
|
package(
|
||||||
default_visibility = ["//visibility:public"],
|
default_visibility = ["//visibility:public"],
|
||||||
@ -14,7 +12,7 @@ exports_files(["LICENSE"])
|
|||||||
INCLUDES = ["include"]
|
INCLUDES = ["include"]
|
||||||
|
|
||||||
C99_FLAGS = select({
|
C99_FLAGS = select({
|
||||||
PLATFORM_OS_WINDOWS: [],
|
"@platforms//os:windows": [],
|
||||||
"//conditions:default": [
|
"//conditions:default": [
|
||||||
"-Wall",
|
"-Wall",
|
||||||
"-Wextra",
|
"-Wextra",
|
||||||
@ -178,11 +176,9 @@ cc_library(
|
|||||||
],
|
],
|
||||||
copts = C99_FLAGS,
|
copts = C99_FLAGS,
|
||||||
defines = selects.with_or({
|
defines = selects.with_or({
|
||||||
PLATFORM_OS_MACOS: ["HAVE_DLFCN_H"],
|
"@platforms//os:macos": ["HAVE_DLFCN_H"],
|
||||||
PLATFORM_OS_FREEBSD: ["HAVE_STRONG_ELF_AUX_INFO"],
|
("@platforms//os:freebsd", "@platforms//os:openbsd"): ["HAVE_STRONG_ELF_AUX_INFO"],
|
||||||
PLATFORM_OS_OPENBSD: ["HAVE_STRONG_ELF_AUX_INFO"],
|
("@platforms//os:android", "@platforms//os:linux"): ["HAVE_STRONG_GETAUXVAL"],
|
||||||
PLATFORM_OS_LINUX: ["HAVE_STRONG_GETAUXVAL"],
|
|
||||||
PLATFORM_OS_ANDROID: ["HAVE_STRONG_GETAUXVAL"],
|
|
||||||
"//conditions:default": [],
|
"//conditions:default": [],
|
||||||
}),
|
}),
|
||||||
includes = INCLUDES,
|
includes = INCLUDES,
|
||||||
@ -222,50 +218,48 @@ cc_library(
|
|||||||
cc_library(
|
cc_library(
|
||||||
name = "cpuinfo",
|
name = "cpuinfo",
|
||||||
srcs = selects.with_or({
|
srcs = selects.with_or({
|
||||||
PLATFORM_CPU_X86_64: [
|
("@platforms//cpu:x86_32", "@platforms//cpu:x86_64"): [
|
||||||
"src/impl_x86_freebsd.c",
|
"src/impl_x86_freebsd.c",
|
||||||
"src/impl_x86_linux_or_android.c",
|
"src/impl_x86_linux_or_android.c",
|
||||||
"src/impl_x86_macos.c",
|
"src/impl_x86_macos.c",
|
||||||
"src/impl_x86_windows.c",
|
"src/impl_x86_windows.c",
|
||||||
],
|
],
|
||||||
PLATFORM_CPU_ARM: ["src/impl_arm_linux_or_android.c"],
|
"@platforms//cpu:arm": ["src/impl_arm_linux_or_android.c"],
|
||||||
PLATFORM_CPU_ARM64: [
|
"@platforms//cpu:arm64": [
|
||||||
"src/impl_aarch64_cpuid.c",
|
"src/impl_aarch64_cpuid.c",
|
||||||
"src/impl_aarch64_linux_or_android.c",
|
"src/impl_aarch64_linux_or_android.c",
|
||||||
"src/impl_aarch64_macos_or_iphone.c",
|
"src/impl_aarch64_macos_or_iphone.c",
|
||||||
"src/impl_aarch64_windows.c",
|
"src/impl_aarch64_windows.c",
|
||||||
"src/impl_aarch64_freebsd_or_openbsd.c",
|
"src/impl_aarch64_freebsd_or_openbsd.c",
|
||||||
],
|
],
|
||||||
PLATFORM_CPU_MIPS: ["src/impl_mips_linux_or_android.c"],
|
"@platforms//cpu:mips64": ["src/impl_mips_linux_or_android.c"],
|
||||||
PLATFORM_CPU_PPC: ["src/impl_ppc_linux.c"],
|
"@platforms//cpu:ppc": ["src/impl_ppc_linux.c"],
|
||||||
PLATFORM_CPU_RISCV32: ["src/impl_riscv_linux.c"],
|
("@platforms//cpu:riscv32", "@platforms//cpu:riscv64"): ["src/impl_riscv_linux.c"],
|
||||||
PLATFORM_CPU_RISCV64: ["src/impl_riscv_linux.c"],
|
|
||||||
}),
|
}),
|
||||||
hdrs = selects.with_or({
|
hdrs = selects.with_or({
|
||||||
PLATFORM_CPU_X86_64: [
|
("@platforms//cpu:x86_32", "@platforms//cpu:x86_64"): [
|
||||||
"include/cpuinfo_x86.h",
|
"include/cpuinfo_x86.h",
|
||||||
"include/internal/cpuid_x86.h",
|
"include/internal/cpuid_x86.h",
|
||||||
"include/internal/windows_utils.h",
|
"include/internal/windows_utils.h",
|
||||||
],
|
],
|
||||||
PLATFORM_CPU_ARM: ["include/cpuinfo_arm.h"],
|
"@platforms//cpu:arm": ["include/cpuinfo_arm.h"],
|
||||||
PLATFORM_CPU_ARM64: [
|
"@platforms//cpu:arm64": [
|
||||||
"include/cpuinfo_aarch64.h",
|
"include/cpuinfo_aarch64.h",
|
||||||
"include/internal/cpuid_aarch64.h",
|
"include/internal/cpuid_aarch64.h",
|
||||||
],
|
],
|
||||||
PLATFORM_CPU_MIPS: ["include/cpuinfo_mips.h"],
|
"@platforms//cpu:mips64": ["include/cpuinfo_mips.h"],
|
||||||
PLATFORM_CPU_PPC: ["include/cpuinfo_ppc.h"],
|
"@platforms//cpu:ppc": ["include/cpuinfo_ppc.h"],
|
||||||
PLATFORM_CPU_RISCV32: ["include/cpuinfo_riscv.h"],
|
("@platforms//cpu:riscv32", "@platforms//cpu:riscv64"): ["include/cpuinfo_riscv.h"],
|
||||||
PLATFORM_CPU_RISCV64: ["include/cpuinfo_riscv.h"],
|
|
||||||
}),
|
}),
|
||||||
copts = C99_FLAGS,
|
copts = C99_FLAGS,
|
||||||
defines = selects.with_or({
|
defines = selects.with_or({
|
||||||
PLATFORM_OS_MACOS: ["HAVE_SYSCTLBYNAME"],
|
"@platforms//os:macos": ["HAVE_SYSCTLBYNAME"],
|
||||||
"//conditions:default": [],
|
"//conditions:default": [],
|
||||||
}),
|
}),
|
||||||
includes = INCLUDES,
|
includes = INCLUDES,
|
||||||
textual_hdrs = selects.with_or({
|
textual_hdrs = selects.with_or({
|
||||||
PLATFORM_CPU_X86_64: ["src/impl_x86__base_implementation.inl"],
|
("@platforms//cpu:x86_32", "@platforms//cpu:x86_64"): ["src/impl_x86__base_implementation.inl"],
|
||||||
PLATFORM_CPU_ARM64: ["src/impl_aarch64__base_implementation.inl"],
|
"@platforms//cpu:arm64": ["src/impl_aarch64__base_implementation.inl"],
|
||||||
"//conditions:default": [],
|
"//conditions:default": [],
|
||||||
}) + [
|
}) + [
|
||||||
"src/define_introspection.inl",
|
"src/define_introspection.inl",
|
||||||
@ -287,57 +281,55 @@ cc_library(
|
|||||||
name = "cpuinfo_for_testing",
|
name = "cpuinfo_for_testing",
|
||||||
testonly = 1,
|
testonly = 1,
|
||||||
srcs = selects.with_or({
|
srcs = selects.with_or({
|
||||||
PLATFORM_CPU_X86_64: [
|
("@platforms//cpu:x86_32", "@platforms//cpu:x86_64"): [
|
||||||
"src/impl_x86_freebsd.c",
|
"src/impl_x86_freebsd.c",
|
||||||
"src/impl_x86_linux_or_android.c",
|
"src/impl_x86_linux_or_android.c",
|
||||||
"src/impl_x86_macos.c",
|
"src/impl_x86_macos.c",
|
||||||
"src/impl_x86_windows.c",
|
"src/impl_x86_windows.c",
|
||||||
],
|
],
|
||||||
PLATFORM_CPU_ARM: ["src/impl_arm_linux_or_android.c"],
|
"@platforms//cpu:arm": ["src/impl_arm_linux_or_android.c"],
|
||||||
PLATFORM_CPU_ARM64: [
|
"@platforms//cpu:arm64": [
|
||||||
"src/impl_aarch64_cpuid.c",
|
"src/impl_aarch64_cpuid.c",
|
||||||
"src/impl_aarch64_linux_or_android.c",
|
"src/impl_aarch64_linux_or_android.c",
|
||||||
"src/impl_aarch64_macos_or_iphone.c",
|
"src/impl_aarch64_macos_or_iphone.c",
|
||||||
"src/impl_aarch64_windows.c",
|
"src/impl_aarch64_windows.c",
|
||||||
"src/impl_aarch64_freebsd_or_openbsd.c",
|
"src/impl_aarch64_freebsd_or_openbsd.c",
|
||||||
],
|
],
|
||||||
PLATFORM_CPU_MIPS: ["src/impl_mips_linux_or_android.c"],
|
"@platforms//cpu:mips64": ["src/impl_mips_linux_or_android.c"],
|
||||||
PLATFORM_CPU_PPC: ["src/impl_ppc_linux.c"],
|
"@platforms//cpu:ppc": ["src/impl_ppc_linux.c"],
|
||||||
PLATFORM_CPU_RISCV32: ["src/impl_riscv_linux.c"],
|
("@platforms//cpu:riscv32", "@platforms//cpu:riscv64"): ["src/impl_riscv_linux.c"],
|
||||||
PLATFORM_CPU_RISCV64: ["src/impl_riscv_linux.c"],
|
|
||||||
}),
|
}),
|
||||||
hdrs = selects.with_or({
|
hdrs = selects.with_or({
|
||||||
PLATFORM_CPU_X86_64: [
|
("@platforms//cpu:x86_32", "@platforms//cpu:x86_64"): [
|
||||||
"include/cpuinfo_x86.h",
|
"include/cpuinfo_x86.h",
|
||||||
"include/internal/cpuid_x86.h",
|
"include/internal/cpuid_x86.h",
|
||||||
"include/internal/windows_utils.h",
|
"include/internal/windows_utils.h",
|
||||||
],
|
],
|
||||||
PLATFORM_CPU_ARM: ["include/cpuinfo_arm.h"],
|
"@platforms//cpu:arm": ["include/cpuinfo_arm.h"],
|
||||||
PLATFORM_CPU_ARM64: [
|
"@platforms//cpu:arm64": [
|
||||||
"include/cpuinfo_aarch64.h",
|
"include/cpuinfo_aarch64.h",
|
||||||
"include/internal/cpuid_aarch64.h",
|
"include/internal/cpuid_aarch64.h",
|
||||||
],
|
],
|
||||||
PLATFORM_CPU_MIPS: ["include/cpuinfo_mips.h"],
|
"@platforms//cpu:mips64": ["include/cpuinfo_mips.h"],
|
||||||
PLATFORM_CPU_PPC: ["include/cpuinfo_ppc.h"],
|
"@platforms//cpu:ppc": ["include/cpuinfo_ppc.h"],
|
||||||
PLATFORM_CPU_RISCV32: ["include/cpuinfo_riscv.h"],
|
("@platforms//cpu:riscv32", "@platforms//cpu:riscv64"): ["include/cpuinfo_riscv.h"],
|
||||||
PLATFORM_CPU_RISCV64: ["include/cpuinfo_riscv.h"],
|
|
||||||
}),
|
}),
|
||||||
copts = C99_FLAGS,
|
copts = C99_FLAGS,
|
||||||
defines = selects.with_or({
|
defines = selects.with_or({
|
||||||
PLATFORM_CPU_X86_64: ["CPU_FEATURES_MOCK_CPUID_X86"],
|
("@platforms//cpu:x86_32", "@platforms//cpu:x86_64"): ["CPU_FEATURES_MOCK_CPUID_X86"],
|
||||||
PLATFORM_CPU_ARM64: [
|
"@platforms//cpu:arm64": [
|
||||||
"CPU_FEATURES_MOCK_CPUID_AARCH64",
|
"CPU_FEATURES_MOCK_CPUID_AARCH64",
|
||||||
"CPU_FEATURES_MOCK_SYSCTL_AARCH64",
|
"CPU_FEATURES_MOCK_SYSCTL_AARCH64",
|
||||||
],
|
],
|
||||||
"//conditions:default": [],
|
"//conditions:default": [],
|
||||||
}) + selects.with_or({
|
}) + selects.with_or({
|
||||||
PLATFORM_OS_MACOS: ["HAVE_SYSCTLBYNAME"],
|
"@platforms//os:macos": ["HAVE_SYSCTLBYNAME"],
|
||||||
"//conditions:default": [],
|
"//conditions:default": [],
|
||||||
}),
|
}),
|
||||||
includes = INCLUDES,
|
includes = INCLUDES,
|
||||||
textual_hdrs = selects.with_or({
|
textual_hdrs = selects.with_or({
|
||||||
PLATFORM_CPU_X86_64: ["src/impl_x86__base_implementation.inl"],
|
("@platforms//cpu:x86_32", "@platforms//cpu:x86_64"): ["src/impl_x86__base_implementation.inl"],
|
||||||
PLATFORM_CPU_ARM64: ["src/impl_aarch64__base_implementation.inl"],
|
"@platforms//cpu:arm64": ["src/impl_aarch64__base_implementation.inl"],
|
||||||
"//conditions:default": [],
|
"//conditions:default": [],
|
||||||
}) + [
|
}) + [
|
||||||
"src/define_introspection.inl",
|
"src/define_introspection.inl",
|
||||||
@ -358,13 +350,12 @@ cc_library(
|
|||||||
cc_test(
|
cc_test(
|
||||||
name = "cpuinfo_test",
|
name = "cpuinfo_test",
|
||||||
srcs = selects.with_or({
|
srcs = selects.with_or({
|
||||||
PLATFORM_CPU_ARM64: ["test/cpuinfo_aarch64_test.cc"],
|
"@platforms//cpu:arm64": ["test/cpuinfo_aarch64_test.cc"],
|
||||||
PLATFORM_CPU_ARM: ["test/cpuinfo_arm_test.cc"],
|
"@platforms//cpu:arm": ["test/cpuinfo_arm_test.cc"],
|
||||||
PLATFORM_CPU_MIPS: ["test/cpuinfo_mips_test.cc"],
|
"@platforms//cpu:mips64": ["test/cpuinfo_mips_test.cc"],
|
||||||
PLATFORM_CPU_PPC: ["test/cpuinfo_ppc_test.cc"],
|
"@platforms//cpu:ppc": ["test/cpuinfo_ppc_test.cc"],
|
||||||
PLATFORM_CPU_RISCV32: ["test/cpuinfo_riscv_test.cc"],
|
("@platforms//cpu:riscv32", "@platforms//cpu:riscv64"): ["test/cpuinfo_riscv_test.cc"],
|
||||||
PLATFORM_CPU_RISCV64: ["test/cpuinfo_riscv_test.cc"],
|
("@platforms//cpu:x86_32", "@platforms//cpu:x86_64"): ["test/cpuinfo_x86_test.cc"],
|
||||||
PLATFORM_CPU_X86_64: ["test/cpuinfo_x86_test.cc"],
|
|
||||||
}),
|
}),
|
||||||
includes = INCLUDES,
|
includes = INCLUDES,
|
||||||
deps = [
|
deps = [
|
||||||
@ -394,7 +385,7 @@ cc_library(
|
|||||||
copts = C99_FLAGS,
|
copts = C99_FLAGS,
|
||||||
includes = INCLUDES + ["ndk_compat"],
|
includes = INCLUDES + ["ndk_compat"],
|
||||||
target_compatible_with = select({
|
target_compatible_with = select({
|
||||||
PLATFORM_OS_WINDOWS: ["@platforms//:incompatible"],
|
"@platforms//os:windows": ["@platforms//:incompatible"],
|
||||||
"//conditions:default": [],
|
"//conditions:default": [],
|
||||||
}),
|
}),
|
||||||
textual_hdrs = ["ndk_compat/cpu-features.h"],
|
textual_hdrs = ["ndk_compat/cpu-features.h"],
|
||||||
|
@ -1,28 +0,0 @@
|
|||||||
"""Defines global variables that lists target cpus"""
|
|
||||||
|
|
||||||
PLATFORM_CPU_X86_64 = ("@platforms//cpu:x86_64")
|
|
||||||
|
|
||||||
PLATFORM_CPU_ARM = ("@platforms//cpu:arm")
|
|
||||||
|
|
||||||
PLATFORM_CPU_ARM64 = ("@platforms//cpu:arm64")
|
|
||||||
|
|
||||||
PLATFORM_CPU_MIPS = ("@platforms//cpu:mips64")
|
|
||||||
|
|
||||||
PLATFORM_CPU_PPC = ("@platforms//cpu:ppc")
|
|
||||||
|
|
||||||
PLATFORM_CPU_RISCV32 = ("@platforms//cpu:riscv32")
|
|
||||||
|
|
||||||
PLATFORM_CPU_RISCV64 = ("@platforms//cpu:riscv64")
|
|
||||||
|
|
||||||
|
|
||||||
PLATFORM_OS_MACOS = ("@platforms//os:macos")
|
|
||||||
|
|
||||||
PLATFORM_OS_LINUX = ("@platforms//os:linux")
|
|
||||||
|
|
||||||
PLATFORM_OS_ANDROID = ("@platforms//os:android")
|
|
||||||
|
|
||||||
PLATFORM_OS_FREEBSD = ("@platforms//os:freebsd")
|
|
||||||
|
|
||||||
PLATFORM_OS_OPENBSD = ("@platforms//os:openbsd")
|
|
||||||
|
|
||||||
PLATFORM_OS_WINDOWS = ("@platforms//os:windows")
|
|
Loading…
x
Reference in New Issue
Block a user