mirror of
https://github.com/abseil/abseil-cpp.git
synced 2026-06-04 20:14:23 +08:00
Use Bazel Platforms to support AES-NI compile options for Randen
Bazel has deprecated selecting directly on the --cpu. This change uses platforms to select the appropriate compile options. Fixes https://github.com/abseil/abseil-cpp/issues/1573 Fixes https://github.com/abseil/abseil-cpp/pull/1797 PiperOrigin-RevId: 712638567 Change-Id: Id16e478fe4ff1d27992b263d51c822cce0f7a98c
This commit is contained in:
committed by
Copybara-Service
parent
506f1072c0
commit
4e09561096
@@ -15,10 +15,6 @@ load(
|
||||
"ABSL_MSVC_FLAGS",
|
||||
"ABSL_MSVC_LINKOPTS",
|
||||
"ABSL_MSVC_TEST_FLAGS",
|
||||
"ABSL_RANDOM_HWAES_ARM32_FLAGS",
|
||||
"ABSL_RANDOM_HWAES_ARM64_FLAGS",
|
||||
"ABSL_RANDOM_HWAES_MSVC_X64_FLAGS",
|
||||
"ABSL_RANDOM_HWAES_X64_FLAGS",
|
||||
)
|
||||
|
||||
ABSL_DEFAULT_COPTS = select({
|
||||
@@ -41,42 +37,3 @@ ABSL_DEFAULT_LINKOPTS = select({
|
||||
"//absl:msvc_compiler": ABSL_MSVC_LINKOPTS,
|
||||
"//conditions:default": [],
|
||||
})
|
||||
|
||||
# ABSL_RANDOM_RANDEN_COPTS blaze copts flags which are required by each
|
||||
# environment to build an accelerated RandenHwAes library.
|
||||
ABSL_RANDOM_RANDEN_COPTS = select({
|
||||
# APPLE
|
||||
":cpu_darwin_x86_64": ABSL_RANDOM_HWAES_X64_FLAGS,
|
||||
":cpu_darwin": ABSL_RANDOM_HWAES_X64_FLAGS,
|
||||
":cpu_x64_windows_msvc": ABSL_RANDOM_HWAES_MSVC_X64_FLAGS,
|
||||
":cpu_x64_windows": ABSL_RANDOM_HWAES_MSVC_X64_FLAGS,
|
||||
":cpu_k8": ABSL_RANDOM_HWAES_X64_FLAGS,
|
||||
":cpu_ppc": ["-mcrypto"],
|
||||
":cpu_aarch64": ABSL_RANDOM_HWAES_ARM64_FLAGS,
|
||||
|
||||
# Supported by default or unsupported.
|
||||
"//conditions:default": [],
|
||||
})
|
||||
|
||||
# absl_random_randen_copts_init:
|
||||
# Initialize the config targets based on cpu, os, etc. used to select
|
||||
# the required values for ABSL_RANDOM_RANDEN_COPTS
|
||||
def absl_random_randen_copts_init():
|
||||
"""Initialize the config_settings used by ABSL_RANDOM_RANDEN_COPTS."""
|
||||
|
||||
# CPU configs.
|
||||
# These configs have consistent flags to enable HWAES intsructions.
|
||||
cpu_configs = [
|
||||
"ppc",
|
||||
"k8",
|
||||
"darwin_x86_64",
|
||||
"darwin",
|
||||
"x64_windows_msvc",
|
||||
"x64_windows",
|
||||
"aarch64",
|
||||
]
|
||||
for cpu in cpu_configs:
|
||||
native.config_setting(
|
||||
name = "cpu_%s" % cpu,
|
||||
values = {"cpu": cpu},
|
||||
)
|
||||
|
||||
@@ -180,15 +180,4 @@ COPT_VARS = {
|
||||
# Object file doesn't export any previously undefined symbols
|
||||
"-ignore:4221",
|
||||
],
|
||||
# "HWAES" is an abbreviation for "hardware AES" (AES - Advanced Encryption
|
||||
# Standard). These flags are used for detecting whether or not the target
|
||||
# architecture has hardware support for AES instructions which can be used
|
||||
# to improve performance of some random bit generators.
|
||||
"ABSL_RANDOM_HWAES_ARM64_FLAGS": ["-march=armv8-a+crypto"],
|
||||
"ABSL_RANDOM_HWAES_ARM32_FLAGS": ["-mfpu=neon"],
|
||||
"ABSL_RANDOM_HWAES_X64_FLAGS": [
|
||||
"-maes",
|
||||
"-msse4.1",
|
||||
],
|
||||
"ABSL_RANDOM_HWAES_MSVC_X64_FLAGS": [],
|
||||
}
|
||||
|
||||
@@ -14,14 +14,14 @@
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
load("@bazel_skylib//lib:selects.bzl", "selects")
|
||||
|
||||
# Internal-only implementation classes for Abseil Random
|
||||
load(
|
||||
"//absl:copts/configure_copts.bzl",
|
||||
"ABSL_DEFAULT_COPTS",
|
||||
"ABSL_DEFAULT_LINKOPTS",
|
||||
"ABSL_RANDOM_RANDEN_COPTS",
|
||||
"ABSL_TEST_COPTS",
|
||||
"absl_random_randen_copts_init",
|
||||
)
|
||||
|
||||
default_package_visibility = [
|
||||
@@ -39,6 +39,72 @@ package(
|
||||
|
||||
licenses(["notice"])
|
||||
|
||||
# Used to select on compilers that support GCC-compatible options
|
||||
# (e.g. "-maes").
|
||||
selects.config_setting_group(
|
||||
name = "gcc_compatible",
|
||||
match_any = [
|
||||
"@rules_cc//cc/compiler:clang",
|
||||
"@rules_cc//cc/compiler:gcc",
|
||||
],
|
||||
)
|
||||
|
||||
selects.config_setting_group(
|
||||
name = "gcc_compatible-aarch32",
|
||||
match_all = [
|
||||
":gcc_compatible",
|
||||
"@platforms//cpu:aarch32",
|
||||
],
|
||||
)
|
||||
|
||||
selects.config_setting_group(
|
||||
name = "gcc_compatible-aarch64",
|
||||
match_all = [
|
||||
":gcc_compatible",
|
||||
"@platforms//cpu:aarch64",
|
||||
],
|
||||
)
|
||||
|
||||
selects.config_setting_group(
|
||||
name = "ppc_crypto",
|
||||
match_any = [
|
||||
"@platforms//cpu:ppc",
|
||||
"@platforms//cpu:ppc32",
|
||||
"@platforms//cpu:ppc64le",
|
||||
],
|
||||
)
|
||||
|
||||
selects.config_setting_group(
|
||||
name = "gcc_compatible-ppc_crypto",
|
||||
match_all = [
|
||||
":gcc_compatible",
|
||||
":ppc_crypto",
|
||||
],
|
||||
)
|
||||
|
||||
selects.config_setting_group(
|
||||
name = "gcc_compatible-x86_64",
|
||||
match_all = [
|
||||
":gcc_compatible",
|
||||
"@platforms//cpu:x86_64",
|
||||
],
|
||||
)
|
||||
|
||||
# Some libraries are compiled with options to generate AES-NI
|
||||
# instructions, and runtime dispatch is used to determine if the host
|
||||
# microarchitecture supports AES-NI or if a portable fallback library
|
||||
# should be called.
|
||||
ABSL_RANDOM_RANDEN_COPTS = select({
|
||||
":gcc_compatible-aarch32": ["-mfpu=neon"],
|
||||
":gcc_compatible-aarch64": ["-march=armv8-a+crypto"],
|
||||
":gcc_compatible-ppc_crypto": ["-mcrypto"],
|
||||
":gcc_compatible-x86_64": [
|
||||
"-maes",
|
||||
"-msse4.1",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
})
|
||||
|
||||
cc_library(
|
||||
name = "traits",
|
||||
hdrs = ["traits.h"],
|
||||
@@ -321,8 +387,6 @@ cc_library(
|
||||
],
|
||||
)
|
||||
|
||||
absl_random_randen_copts_init()
|
||||
|
||||
cc_library(
|
||||
name = "randen_hwaes",
|
||||
srcs = [
|
||||
|
||||
Reference in New Issue
Block a user