1"""Abseil compiler options. 2 3This is the source of truth for Abseil compiler options. To modify Abseil 4compilation options: 5 6 (1) Edit the appropriate list in this file based on the platform the flag is 7 needed on. 8 (2) Run `<path_to_absl>/copts/generate_copts.py`. 9 10The generated copts are consumed by configure_copts.bzl and 11AbseilConfigureCopts.cmake. 12""" 13 14ABSL_GCC_FLAGS = [ 15 "-Wall", 16 "-Wextra", 17 "-Wcast-qual", 18 "-Wconversion-null", 19 "-Wformat-security", 20 "-Wmissing-declarations", 21 "-Wnon-virtual-dtor", 22 "-Woverlength-strings", 23 "-Wpointer-arith", 24 "-Wundef", 25 "-Wunused-local-typedefs", 26 "-Wunused-result", 27 "-Wvarargs", 28 "-Wvla", # variable-length array 29 "-Wwrite-strings", 30 # Don't define min and max macros (Build on Windows using gcc) 31 "-DNOMINMAX", 32] 33 34ABSL_GCC_TEST_ADDITIONAL_FLAGS = [ 35 "-Wno-deprecated-declarations", 36 "-Wno-missing-declarations", 37 "-Wno-self-move", 38 "-Wno-sign-compare", 39 "-Wno-unused-function", 40 "-Wno-unused-parameter", 41 "-Wno-unused-private-field", 42] 43 44ABSL_LLVM_FLAGS = [ 45 "-Wall", 46 "-Wextra", 47 "-Wc++98-compat-extra-semi", 48 "-Wcast-qual", 49 "-Wconversion", 50 "-Wdead-code-aggressive", 51 "-Wdeprecated-pragma", 52 "-Wfloat-overflow-conversion", 53 "-Wfloat-zero-conversion", 54 "-Wfor-loop-analysis", 55 "-Wformat-security", 56 "-Wgnu-redeclared-enum", 57 "-Winfinite-recursion", 58 "-Winvalid-constexpr", 59 "-Wliteral-conversion", 60 "-Wmissing-declarations", 61 "-Woverlength-strings", 62 "-Wpointer-arith", 63 "-Wself-assign", 64 "-Wshadow-all", 65 "-Wshorten-64-to-32", 66 "-Wsign-conversion", 67 "-Wstring-conversion", 68 "-Wtautological-overlap-compare", 69 "-Wtautological-unsigned-zero-compare", 70 "-Wundef", 71 "-Wuninitialized", 72 "-Wunreachable-code", 73 "-Wunused-comparison", 74 "-Wunused-local-typedefs", 75 "-Wunused-result", 76 "-Wvla", 77 "-Wwrite-strings", 78 # Warnings that are enabled by group warning flags like -Wall that we 79 # explicitly disable. 80 "-Wno-float-conversion", 81 "-Wno-implicit-float-conversion", 82 "-Wno-implicit-int-float-conversion", 83 # Disable warnings on unknown warning flags (when warning flags are 84 # unknown on older compiler versions) 85 "-Wno-unknown-warning-option", 86 # Don't define min and max macros (Build on Windows using clang) 87 "-DNOMINMAX", 88] 89 90ABSL_LLVM_TEST_ADDITIONAL_FLAGS = [ 91 "-Wno-deprecated-declarations", 92 "-Wno-implicit-int-conversion", 93 "-Wno-missing-prototypes", 94 "-Wno-missing-variable-declarations", 95 "-Wno-shadow", 96 "-Wno-shorten-64-to-32", 97 "-Wno-sign-compare", 98 "-Wno-sign-conversion", 99 "-Wno-unreachable-code-loop-increment", 100 "-Wno-unused-function", 101 "-Wno-unused-member-function", 102 "-Wno-unused-parameter", 103 "-Wno-unused-private-field", 104 "-Wno-unused-template", 105 "-Wno-used-but-marked-unused", 106 # gtest depends on this GNU extension being offered. 107 "-Wno-gnu-zero-variadic-macro-arguments", 108] 109 110# /Wall with msvc includes unhelpful warnings such as C4711, C4710, ... 111MSVC_BIG_WARNING_FLAGS = [ 112 "/W3", 113] 114 115MSVC_WARNING_FLAGS = [ 116 # Increase the number of sections available in object files 117 "/bigobj", 118 "/wd4005", # macro-redefinition 119 "/wd4068", # unknown pragma 120 # qualifier applied to function type has no meaning; ignored 121 "/wd4180", 122 # conversion from 'type1' to 'type2', possible loss of data 123 "/wd4244", 124 # conversion from 'size_t' to 'type', possible loss of data 125 "/wd4267", 126 # The decorated name was longer than the compiler limit 127 "/wd4503", 128 # forcing value to bool 'true' or 'false' (performance warning) 129 "/wd4800", 130] 131 132MSVC_DEFINES = [ 133 "/DNOMINMAX", # Don't define min and max macros (windows.h) 134 # Don't bloat namespace with incompatible winsock versions. 135 "/DWIN32_LEAN_AND_MEAN", 136 # Don't warn about usage of insecure C functions. 137 "/D_CRT_SECURE_NO_WARNINGS", 138 "/D_SCL_SECURE_NO_WARNINGS", 139 # Introduced in VS 2017 15.8, allow overaligned types in aligned_storage 140 "/D_ENABLE_EXTENDED_ALIGNED_STORAGE", 141] 142 143 144def GccStyleFilterAndCombine(default_flags, test_flags): 145 """Merges default_flags and test_flags for GCC and LLVM. 146 147 Args: 148 default_flags: A list of default compiler flags 149 test_flags: A list of flags that are only used in tests 150 151 Returns: 152 A combined list of default_flags and test_flags, but with all flags of the 153 form '-Wwarning' removed if test_flags contains a flag of the form 154 '-Wno-warning' 155 """ 156 remove = set(["-W" + f[5:] for f in test_flags if f[:5] == "-Wno-"]) 157 return [f for f in default_flags if f not in remove] + test_flags 158 159COPT_VARS = { 160 "ABSL_GCC_FLAGS": ABSL_GCC_FLAGS, 161 "ABSL_GCC_TEST_FLAGS": GccStyleFilterAndCombine( 162 ABSL_GCC_FLAGS, ABSL_GCC_TEST_ADDITIONAL_FLAGS), 163 "ABSL_LLVM_FLAGS": ABSL_LLVM_FLAGS, 164 "ABSL_LLVM_TEST_FLAGS": GccStyleFilterAndCombine( 165 ABSL_LLVM_FLAGS, ABSL_LLVM_TEST_ADDITIONAL_FLAGS), 166 "ABSL_CLANG_CL_FLAGS": 167 MSVC_BIG_WARNING_FLAGS + MSVC_DEFINES, 168 "ABSL_CLANG_CL_TEST_FLAGS": 169 MSVC_BIG_WARNING_FLAGS + MSVC_DEFINES + ABSL_LLVM_TEST_ADDITIONAL_FLAGS, 170 "ABSL_MSVC_FLAGS": 171 MSVC_BIG_WARNING_FLAGS + MSVC_WARNING_FLAGS + MSVC_DEFINES, 172 "ABSL_MSVC_TEST_FLAGS": 173 MSVC_BIG_WARNING_FLAGS + MSVC_WARNING_FLAGS + MSVC_DEFINES + [ 174 "/wd4018", # signed/unsigned mismatch 175 "/wd4101", # unreferenced local variable 176 "/wd4503", # decorated name length exceeded, name was truncated 177 "/wd4996", # use of deprecated symbol 178 "/DNOMINMAX", # disable the min() and max() macros from <windows.h> 179 ], 180 "ABSL_MSVC_LINKOPTS": [ 181 # Object file doesn't export any previously undefined symbols 182 "-ignore:4221", 183 ], 184 # "HWAES" is an abbreviation for "hardware AES" (AES - Advanced Encryption 185 # Standard). These flags are used for detecting whether or not the target 186 # architecture has hardware support for AES instructions which can be used 187 # to improve performance of some random bit generators. 188 "ABSL_RANDOM_HWAES_ARM64_FLAGS": ["-march=armv8-a+crypto"], 189 "ABSL_RANDOM_HWAES_ARM32_FLAGS": ["-mfpu=neon"], 190 "ABSL_RANDOM_HWAES_X64_FLAGS": [ 191 "-maes", 192 "-msse4.1", 193 ], 194 "ABSL_RANDOM_HWAES_MSVC_X64_FLAGS": [], 195} 196