tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

copts.py (5837B)


      1 """Abseil compiler options.
      2 
      3 This is the source of truth for Abseil compiler options.  To modify Abseil
      4 compilation 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 
     10 The generated copts are consumed by configure_copts.bzl and
     11 AbseilConfigureCopts.cmake.
     12 """
     13 
     14 ABSL_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 
     34 ABSL_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 
     44 ABSL_LLVM_FLAGS = [
     45    "-Wall",
     46    "-Wextra",
     47    "-Wc++98-compat-extra-semi",
     48    "-Wcast-qual",
     49    "-Wconversion",
     50    "-Wdeprecated-pragma",
     51    "-Wfloat-overflow-conversion",
     52    "-Wfloat-zero-conversion",
     53    "-Wfor-loop-analysis",
     54    "-Wformat-security",
     55    "-Wgnu-redeclared-enum",
     56    "-Winfinite-recursion",
     57    "-Winvalid-constexpr",
     58    "-Wliteral-conversion",
     59    "-Wmissing-declarations",
     60    "-Wnullability-completeness",
     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    "-Wthread-safety",
     71    "-Wundef",
     72    "-Wuninitialized",
     73    "-Wunreachable-code",
     74    "-Wunused-comparison",
     75    "-Wunused-local-typedefs",
     76    "-Wunused-result",
     77    "-Wvla",
     78    "-Wwrite-strings",
     79    # Warnings that are enabled by group warning flags like -Wall that we
     80    # explicitly disable.
     81    "-Wno-float-conversion",
     82    "-Wno-implicit-float-conversion",
     83    "-Wno-implicit-int-float-conversion",
     84    # Disable warnings on unknown warning flags (when warning flags are
     85    # unknown on older compiler versions)
     86    "-Wno-unknown-warning-option",
     87    # Don't define min and max macros (Build on Windows using clang)
     88    "-DNOMINMAX",
     89 ]
     90 
     91 ABSL_LLVM_TEST_ADDITIONAL_FLAGS = [
     92    "-Wno-deprecated-declarations",
     93    "-Wno-implicit-int-conversion",
     94    "-Wno-missing-prototypes",
     95    "-Wno-missing-variable-declarations",
     96    "-Wno-shadow",
     97    "-Wno-shorten-64-to-32",
     98    "-Wno-sign-compare",
     99    "-Wno-sign-conversion",
    100    "-Wno-unreachable-code-loop-increment",
    101    "-Wno-unused-function",
    102    "-Wno-unused-member-function",
    103    "-Wno-unused-parameter",
    104    "-Wno-unused-private-field",
    105    "-Wno-unused-template",
    106    "-Wno-used-but-marked-unused",
    107    # gtest depends on this GNU extension being offered.
    108    "-Wno-gnu-zero-variadic-macro-arguments",
    109 ]
    110 
    111 # /Wall with msvc includes unhelpful warnings such as C4711, C4710, ...
    112 MSVC_BIG_WARNING_FLAGS = [
    113    "/W3",
    114 ]
    115 
    116 MSVC_WARNING_FLAGS = [
    117    # Increase the number of sections available in object files
    118    "/bigobj",
    119    "/wd4005",  # macro-redefinition
    120    "/wd4068",  # unknown pragma
    121    # qualifier applied to function type has no meaning; ignored
    122    "/wd4180",
    123    # The decorated name was longer than the compiler limit
    124    "/wd4503",
    125    # forcing value to bool 'true' or 'false' (performance warning)
    126    "/wd4800",
    127 ]
    128 
    129 MSVC_DEFINES = [
    130    "/DNOMINMAX",  # Don't define min and max macros (windows.h)
    131    # Don't bloat namespace with incompatible winsock versions.
    132    "/DWIN32_LEAN_AND_MEAN",
    133    # Don't warn about usage of insecure C functions.
    134    "/D_CRT_SECURE_NO_WARNINGS",
    135    "/D_SCL_SECURE_NO_WARNINGS",
    136    # Introduced in VS 2017 15.8, allow overaligned types in aligned_storage
    137    "/D_ENABLE_EXTENDED_ALIGNED_STORAGE",
    138 ]
    139 
    140 
    141 def GccStyleFilterAndCombine(default_flags, test_flags):
    142  """Merges default_flags and test_flags for GCC and LLVM.
    143 
    144  Args:
    145    default_flags: A list of default compiler flags
    146    test_flags: A list of flags that are only used in tests
    147 
    148  Returns:
    149    A combined list of default_flags and test_flags, but with all flags of the
    150    form '-Wwarning' removed if test_flags contains a flag of the form
    151    '-Wno-warning'
    152  """
    153  remove = set(["-W" + f[5:] for f in test_flags if f[:5] == "-Wno-"])
    154  return [f for f in default_flags if f not in remove] + test_flags
    155 
    156 COPT_VARS = {
    157    "ABSL_GCC_FLAGS": ABSL_GCC_FLAGS,
    158    "ABSL_GCC_TEST_FLAGS": GccStyleFilterAndCombine(
    159        ABSL_GCC_FLAGS, ABSL_GCC_TEST_ADDITIONAL_FLAGS
    160    ),
    161    "ABSL_LLVM_FLAGS": ABSL_LLVM_FLAGS,
    162    "ABSL_LLVM_TEST_FLAGS": GccStyleFilterAndCombine(
    163        ABSL_LLVM_FLAGS, ABSL_LLVM_TEST_ADDITIONAL_FLAGS
    164    ),
    165    "ABSL_CLANG_CL_FLAGS": MSVC_BIG_WARNING_FLAGS + MSVC_DEFINES,
    166    "ABSL_CLANG_CL_TEST_FLAGS": (
    167        MSVC_BIG_WARNING_FLAGS + MSVC_DEFINES + ABSL_LLVM_TEST_ADDITIONAL_FLAGS
    168    ),
    169    "ABSL_MSVC_FLAGS": (
    170        MSVC_BIG_WARNING_FLAGS + MSVC_WARNING_FLAGS + MSVC_DEFINES
    171    ),
    172    "ABSL_MSVC_TEST_FLAGS": (
    173        MSVC_BIG_WARNING_FLAGS
    174        + MSVC_WARNING_FLAGS
    175        + MSVC_DEFINES
    176        + [
    177            "/wd4018",  # signed/unsigned mismatch
    178            "/wd4101",  # unreferenced local variable
    179            "/wd4244",  # shortening conversion
    180            "/wd4267",  # shortening conversion
    181            "/wd4503",  # decorated name length exceeded, name was truncated
    182            "/wd4996",  # use of deprecated symbol
    183            "/DNOMINMAX",  # disable the min() and max() macros from <windows.h>
    184        ]
    185    ),
    186    "ABSL_MSVC_LINKOPTS": [
    187        # Object file doesn't export any previously undefined symbols
    188        "-ignore:4221",
    189    ],
    190 }