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