xref: /aosp_15_r20/external/angle/third_party/abseil-cpp/absl/copts/copts.py (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
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    "-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    "-Woverlength-strings",
61    "-Wpointer-arith",
62    "-Wself-assign",
63    "-Wshadow-all",
64    "-Wshorten-64-to-32",
65    "-Wsign-conversion",
66    "-Wstring-conversion",
67    "-Wtautological-overlap-compare",
68    "-Wtautological-unsigned-zero-compare",
69    "-Wundef",
70    "-Wuninitialized",
71    "-Wunreachable-code",
72    "-Wunused-comparison",
73    "-Wunused-local-typedefs",
74    "-Wunused-result",
75    "-Wvla",
76    "-Wwrite-strings",
77    # Warnings that are enabled by group warning flags like -Wall that we
78    # explicitly disable.
79    "-Wno-float-conversion",
80    "-Wno-implicit-float-conversion",
81    "-Wno-implicit-int-float-conversion",
82    # Disable warnings on unknown warning flags (when warning flags are
83    # unknown on older compiler versions)
84    "-Wno-unknown-warning-option",
85    # Don't define min and max macros (Build on Windows using clang)
86    "-DNOMINMAX",
87]
88
89ABSL_LLVM_TEST_ADDITIONAL_FLAGS = [
90    "-Wno-deprecated-declarations",
91    "-Wno-implicit-int-conversion",
92    "-Wno-missing-prototypes",
93    "-Wno-missing-variable-declarations",
94    "-Wno-shadow",
95    "-Wno-shorten-64-to-32",
96    "-Wno-sign-compare",
97    "-Wno-sign-conversion",
98    "-Wno-unreachable-code-loop-increment",
99    "-Wno-unused-function",
100    "-Wno-unused-member-function",
101    "-Wno-unused-parameter",
102    "-Wno-unused-private-field",
103    "-Wno-unused-template",
104    "-Wno-used-but-marked-unused",
105    # gtest depends on this GNU extension being offered.
106    "-Wno-gnu-zero-variadic-macro-arguments",
107]
108
109# /Wall with msvc includes unhelpful warnings such as C4711, C4710, ...
110MSVC_BIG_WARNING_FLAGS = [
111    "/W3",
112]
113
114MSVC_WARNING_FLAGS = [
115    # Increase the number of sections available in object files
116    "/bigobj",
117    "/wd4005",  # macro-redefinition
118    "/wd4068",  # unknown pragma
119    # qualifier applied to function type has no meaning; ignored
120    "/wd4180",
121    # conversion from 'type1' to 'type2', possible loss of data
122    "/wd4244",
123    # conversion from 'size_t' to 'type', possible loss of data
124    "/wd4267",
125    # The decorated name was longer than the compiler limit
126    "/wd4503",
127    # forcing value to bool 'true' or 'false' (performance warning)
128    "/wd4800",
129]
130
131MSVC_DEFINES = [
132    "/DNOMINMAX",  # Don't define min and max macros (windows.h)
133    # Don't bloat namespace with incompatible winsock versions.
134    "/DWIN32_LEAN_AND_MEAN",
135    # Don't warn about usage of insecure C functions.
136    "/D_CRT_SECURE_NO_WARNINGS",
137    "/D_SCL_SECURE_NO_WARNINGS",
138    # Introduced in VS 2017 15.8, allow overaligned types in aligned_storage
139    "/D_ENABLE_EXTENDED_ALIGNED_STORAGE",
140]
141
142
143def GccStyleFilterAndCombine(default_flags, test_flags):
144  """Merges default_flags and test_flags for GCC and LLVM.
145
146  Args:
147    default_flags: A list of default compiler flags
148    test_flags: A list of flags that are only used in tests
149
150  Returns:
151    A combined list of default_flags and test_flags, but with all flags of the
152    form '-Wwarning' removed if test_flags contains a flag of the form
153    '-Wno-warning'
154  """
155  remove = set(["-W" + f[5:] for f in test_flags if f[:5] == "-Wno-"])
156  return [f for f in default_flags if f not in remove] + test_flags
157
158COPT_VARS = {
159    "ABSL_GCC_FLAGS": ABSL_GCC_FLAGS,
160    "ABSL_GCC_TEST_FLAGS": GccStyleFilterAndCombine(
161        ABSL_GCC_FLAGS, ABSL_GCC_TEST_ADDITIONAL_FLAGS),
162    "ABSL_LLVM_FLAGS": ABSL_LLVM_FLAGS,
163    "ABSL_LLVM_TEST_FLAGS": GccStyleFilterAndCombine(
164        ABSL_LLVM_FLAGS, ABSL_LLVM_TEST_ADDITIONAL_FLAGS),
165    "ABSL_CLANG_CL_FLAGS":
166        MSVC_BIG_WARNING_FLAGS + MSVC_DEFINES,
167    "ABSL_CLANG_CL_TEST_FLAGS":
168        MSVC_BIG_WARNING_FLAGS + MSVC_DEFINES + ABSL_LLVM_TEST_ADDITIONAL_FLAGS,
169    "ABSL_MSVC_FLAGS":
170        MSVC_BIG_WARNING_FLAGS + MSVC_WARNING_FLAGS + MSVC_DEFINES,
171    "ABSL_MSVC_TEST_FLAGS":
172        MSVC_BIG_WARNING_FLAGS + MSVC_WARNING_FLAGS + MSVC_DEFINES + [
173            "/wd4018",  # signed/unsigned mismatch
174            "/wd4101",  # unreferenced local variable
175            "/wd4503",  # decorated name length exceeded, name was truncated
176            "/wd4996",  # use of deprecated symbol
177            "/DNOMINMAX",  # disable the min() and max() macros from <windows.h>
178        ],
179    "ABSL_MSVC_LINKOPTS": [
180        # Object file doesn't export any previously undefined symbols
181        "-ignore:4221",
182    ],
183    # "HWAES" is an abbreviation for "hardware AES" (AES - Advanced Encryption
184    # Standard). These flags are used for detecting whether or not the target
185    # architecture has hardware support for AES instructions which can be used
186    # to improve performance of some random bit generators.
187    "ABSL_RANDOM_HWAES_ARM64_FLAGS": ["-march=armv8-a+crypto"],
188    "ABSL_RANDOM_HWAES_ARM32_FLAGS": ["-mfpu=neon"],
189    "ABSL_RANDOM_HWAES_X64_FLAGS": [
190        "-maes",
191        "-msse4.1",
192    ],
193    "ABSL_RANDOM_HWAES_MSVC_X64_FLAGS": [],
194}
195