xref: /aosp_15_r20/external/skia/include/config/copts.bzl (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1*c8dee2aaSAndroid Build Coastguard Worker"""
2*c8dee2aaSAndroid Build Coastguard WorkerTHIS IS THE EXTERNAL-ONLY VERSION OF THIS FILE. G3 HAS ITS OWN.
3*c8dee2aaSAndroid Build Coastguard Worker
4*c8dee2aaSAndroid Build Coastguard WorkerThis file contains flags for the C++ compiler, referred to by Bazel as copts.
5*c8dee2aaSAndroid Build Coastguard Worker
6*c8dee2aaSAndroid Build Coastguard WorkerThe copts in a cc_library to not flow to the children (dependencies) nor the parents
7*c8dee2aaSAndroid Build Coastguard Worker(dependents), so we use skia_cc_library to inject them in every library along the chain.
8*c8dee2aaSAndroid Build Coastguard Worker
9*c8dee2aaSAndroid Build Coastguard WorkerNow that we have a modular build, this file could maybe go away and folded into our toolchains.
10*c8dee2aaSAndroid Build Coastguard Worker
11*c8dee2aaSAndroid Build Coastguard WorkerThey are divided into several lists/selects and were initially created to be identical to the
12*c8dee2aaSAndroid Build Coastguard Worker GN ones [2][3].
13*c8dee2aaSAndroid Build Coastguard Worker
14*c8dee2aaSAndroid Build Coastguard Worker[2] https://github.com/google/skia/blob/2b07cdb07e88f2870260eabac708f31bc7977d08/gn/BUILDCONFIG.gn#L177-L181
15*c8dee2aaSAndroid Build Coastguard Worker[3] https://github.com/google/skia/blob/2b07cdb07e88f2870260eabac708f31bc7977d08/gn/skia/BUILD.gn#L593-L630
16*c8dee2aaSAndroid Build Coastguard Worker"""
17*c8dee2aaSAndroid Build Coastguard Worker
18*c8dee2aaSAndroid Build Coastguard WorkerCORE_COPTS = [
19*c8dee2aaSAndroid Build Coastguard Worker    "-fstrict-aliasing",
20*c8dee2aaSAndroid Build Coastguard Worker] + select({
21*c8dee2aaSAndroid Build Coastguard Worker    "@platforms//os:android": [],
22*c8dee2aaSAndroid Build Coastguard Worker    "//conditions:default": [
23*c8dee2aaSAndroid Build Coastguard Worker        # On Android, this option causes the linker to fail
24*c8dee2aaSAndroid Build Coastguard Worker        # (e.g. "undefined reference to `SkString::data()'").
25*c8dee2aaSAndroid Build Coastguard Worker        "-fvisibility=hidden",
26*c8dee2aaSAndroid Build Coastguard Worker    ],
27*c8dee2aaSAndroid Build Coastguard Worker}) + select({
28*c8dee2aaSAndroid Build Coastguard Worker    "@platforms//os:windows": [],
29*c8dee2aaSAndroid Build Coastguard Worker    "//conditions:default": [
30*c8dee2aaSAndroid Build Coastguard Worker        # In Clang 14, this default was changed. We turn this off to (hopefully) make our
31*c8dee2aaSAndroid Build Coastguard Worker        # GMs more consistent and avoid some floating-point related test failures on M1 macs.
32*c8dee2aaSAndroid Build Coastguard Worker        "-ffp-contract=off",
33*c8dee2aaSAndroid Build Coastguard Worker        # Windows doesn't support position-independent code.
34*c8dee2aaSAndroid Build Coastguard Worker        "-fPIC",
35*c8dee2aaSAndroid Build Coastguard Worker    ],
36*c8dee2aaSAndroid Build Coastguard Worker}) + select({
37*c8dee2aaSAndroid Build Coastguard Worker    # Turning off RTTI reduces code size, but is necessary for connecting C++
38*c8dee2aaSAndroid Build Coastguard Worker    # and Objective-C code.
39*c8dee2aaSAndroid Build Coastguard Worker    "@platforms//os:macos": [],
40*c8dee2aaSAndroid Build Coastguard Worker    "@platforms//os:ios": [],
41*c8dee2aaSAndroid Build Coastguard Worker    "//conditions:default": [
42*c8dee2aaSAndroid Build Coastguard Worker        "-fno-rtti",
43*c8dee2aaSAndroid Build Coastguard Worker    ],
44*c8dee2aaSAndroid Build Coastguard Worker})
45*c8dee2aaSAndroid Build Coastguard Worker
46*c8dee2aaSAndroid Build Coastguard WorkerOPT_LEVEL = select({
47*c8dee2aaSAndroid Build Coastguard Worker    "//bazel/common_config_settings:debug_build": [
48*c8dee2aaSAndroid Build Coastguard Worker        "--optimize=0",
49*c8dee2aaSAndroid Build Coastguard Worker        "--debug",
50*c8dee2aaSAndroid Build Coastguard Worker    ],
51*c8dee2aaSAndroid Build Coastguard Worker    "//bazel/common_config_settings:release_build": [
52*c8dee2aaSAndroid Build Coastguard Worker        "--optimize=3",
53*c8dee2aaSAndroid Build Coastguard Worker        # Strip dead code (in conjunction with linkopts)
54*c8dee2aaSAndroid Build Coastguard Worker        "-fdata-sections",
55*c8dee2aaSAndroid Build Coastguard Worker        "-ffunction-sections",
56*c8dee2aaSAndroid Build Coastguard Worker    ],
57*c8dee2aaSAndroid Build Coastguard Worker    "//bazel/common_config_settings:fast_build": [
58*c8dee2aaSAndroid Build Coastguard Worker        "--optimize=0",
59*c8dee2aaSAndroid Build Coastguard Worker        "-gline-tables-only",
60*c8dee2aaSAndroid Build Coastguard Worker    ],
61*c8dee2aaSAndroid Build Coastguard Worker})
62*c8dee2aaSAndroid Build Coastguard Worker
63*c8dee2aaSAndroid Build Coastguard WorkerWARNINGS = [
64*c8dee2aaSAndroid Build Coastguard Worker    "-fcolor-diagnostics",
65*c8dee2aaSAndroid Build Coastguard Worker    "-Wall",
66*c8dee2aaSAndroid Build Coastguard Worker    "-Werror",
67*c8dee2aaSAndroid Build Coastguard Worker    "-Weverything",
68*c8dee2aaSAndroid Build Coastguard Worker    "-Wextra",
69*c8dee2aaSAndroid Build Coastguard Worker    "-Wpointer-arith",
70*c8dee2aaSAndroid Build Coastguard Worker    "-Wsign-compare",
71*c8dee2aaSAndroid Build Coastguard Worker    "-Wvla",
72*c8dee2aaSAndroid Build Coastguard Worker    #### Warnings we are unlikely to fix ####
73*c8dee2aaSAndroid Build Coastguard Worker    "-Wno-c++98-compat",
74*c8dee2aaSAndroid Build Coastguard Worker    "-Wno-c++98-compat-pedantic",
75*c8dee2aaSAndroid Build Coastguard Worker    "-Wno-covered-switch-default",
76*c8dee2aaSAndroid Build Coastguard Worker    "-Wno-declaration-after-statement",
77*c8dee2aaSAndroid Build Coastguard Worker    "-Wno-deprecated",
78*c8dee2aaSAndroid Build Coastguard Worker    "-Wno-missing-noreturn",
79*c8dee2aaSAndroid Build Coastguard Worker    "-Wno-newline-eof",
80*c8dee2aaSAndroid Build Coastguard Worker    "-Wno-old-style-cast",
81*c8dee2aaSAndroid Build Coastguard Worker    "-Wno-padded",
82*c8dee2aaSAndroid Build Coastguard Worker    "-Wno-psabi",  # noisy
83*c8dee2aaSAndroid Build Coastguard Worker    "-Wno-return-std-move-in-c++11",
84*c8dee2aaSAndroid Build Coastguard Worker    "-Wno-shadow-field-in-constructor",
85*c8dee2aaSAndroid Build Coastguard Worker    "-Wno-shadow-uncaptured-local",
86*c8dee2aaSAndroid Build Coastguard Worker    "-Wno-undefined-func-template",
87*c8dee2aaSAndroid Build Coastguard Worker    "-Wno-unused-parameter",  # It is common to have unused parameters in src/
88*c8dee2aaSAndroid Build Coastguard Worker    "-Wno-zero-as-null-pointer-constant",  # VK_NULL_HANDLE is defined as 0
89*c8dee2aaSAndroid Build Coastguard Worker    "-Wno-unsafe-buffer-usage",
90*c8dee2aaSAndroid Build Coastguard Worker    #### Warnings we would like to fix ####
91*c8dee2aaSAndroid Build Coastguard Worker    "-Wno-abstract-vbase-init",
92*c8dee2aaSAndroid Build Coastguard Worker    "-Wno-cast-align",
93*c8dee2aaSAndroid Build Coastguard Worker    "-Wno-cast-function-type-strict",
94*c8dee2aaSAndroid Build Coastguard Worker    "-Wno-cast-qual",
95*c8dee2aaSAndroid Build Coastguard Worker    "-Wno-class-varargs",
96*c8dee2aaSAndroid Build Coastguard Worker    "-Wno-conversion",  # -Wsign-conversion re-enabled for header sources
97*c8dee2aaSAndroid Build Coastguard Worker    "-Wno-disabled-macro-expansion",
98*c8dee2aaSAndroid Build Coastguard Worker    "-Wno-documentation",
99*c8dee2aaSAndroid Build Coastguard Worker    "-Wno-documentation-unknown-command",
100*c8dee2aaSAndroid Build Coastguard Worker    "-Wno-double-promotion",
101*c8dee2aaSAndroid Build Coastguard Worker    "-Wno-exit-time-destructors",  # TODO: OK outside libskia
102*c8dee2aaSAndroid Build Coastguard Worker    "-Wno-float-equal",
103*c8dee2aaSAndroid Build Coastguard Worker    "-Wno-global-constructors",  # TODO: OK outside libskia
104*c8dee2aaSAndroid Build Coastguard Worker    "-Wno-missing-prototypes",
105*c8dee2aaSAndroid Build Coastguard Worker    "-Wno-missing-variable-declarations",
106*c8dee2aaSAndroid Build Coastguard Worker    "-Wno-pedantic",
107*c8dee2aaSAndroid Build Coastguard Worker    "-Wno-reserved-id-macro",
108*c8dee2aaSAndroid Build Coastguard Worker    "-Wno-reserved-identifier",
109*c8dee2aaSAndroid Build Coastguard Worker    "-Wno-shift-sign-overflow",
110*c8dee2aaSAndroid Build Coastguard Worker    "-Wno-signed-enum-bitfield",
111*c8dee2aaSAndroid Build Coastguard Worker    "-Wno-switch-enum",
112*c8dee2aaSAndroid Build Coastguard Worker    "-Wno-thread-safety-negative",
113*c8dee2aaSAndroid Build Coastguard Worker    "-Wno-undef",
114*c8dee2aaSAndroid Build Coastguard Worker    "-Wno-unreachable-code-break",
115*c8dee2aaSAndroid Build Coastguard Worker    "-Wno-unreachable-code-return",
116*c8dee2aaSAndroid Build Coastguard Worker    "-Wno-unused-macros",
117*c8dee2aaSAndroid Build Coastguard Worker    "-Wno-unused-member-function",
118*c8dee2aaSAndroid Build Coastguard Worker    "-Wno-weak-template-vtables",  # This was deprecated in Clang 14 and removed in Clang 15.
119*c8dee2aaSAndroid Build Coastguard Worker    "-Wno-weak-vtables",
120*c8dee2aaSAndroid Build Coastguard Worker    # https://quuxplusone.github.io/blog/2020/08/26/wrange-loop-analysis/
121*c8dee2aaSAndroid Build Coastguard Worker    # https://bugzilla.mozilla.org/show_bug.cgi?id=1683213
122*c8dee2aaSAndroid Build Coastguard Worker    # https://reviews.llvm.org/D73007
123*c8dee2aaSAndroid Build Coastguard Worker    # May be re-enabled once clang > 12 or XCode > 12 are required.
124*c8dee2aaSAndroid Build Coastguard Worker    # When this line is removed the -Wrange-loop-construct line below can also be removed.
125*c8dee2aaSAndroid Build Coastguard Worker    "-Wno-range-loop-analysis",
126*c8dee2aaSAndroid Build Coastguard Worker    # Wno-range-loop-analysis turns off the whole group, but this warning was later split into
127*c8dee2aaSAndroid Build Coastguard Worker    # range-loop-construct and range-loop-bind-reference. We want the former but not the latter.
128*c8dee2aaSAndroid Build Coastguard Worker    # Created from
129*c8dee2aaSAndroid Build Coastguard Worker    # https://github.com/llvm/llvm-project/blob/bd08f413c089da5a56438cc8902f60df91a08a66/clang/include/clang/Basic/DiagnosticGroups.td
130*c8dee2aaSAndroid Build Coastguard Worker    "-Wrange-loop-construct",
131*c8dee2aaSAndroid Build Coastguard Worker    # Wno-deprecated turns off the whole group, but also has its own warnings like
132*c8dee2aaSAndroid Build Coastguard Worker    # out-of-line definition of constexpr static data member is redundant in C++17 and is deprecated [-Werror,-Wdeprecated]
133*c8dee2aaSAndroid Build Coastguard Worker    # but we would like others. Created from
134*c8dee2aaSAndroid Build Coastguard Worker    # https://github.com/llvm/llvm-project/blob/bd08f413c089da5a56438cc8902f60df91a08a66/clang/include/clang/Basic/DiagnosticGroups.td
135*c8dee2aaSAndroid Build Coastguard Worker    "-Wdeprecated-anon-enum-enum-conversion",
136*c8dee2aaSAndroid Build Coastguard Worker    "-Wdeprecated-array-compare",
137*c8dee2aaSAndroid Build Coastguard Worker    "-Wdeprecated-attributes",
138*c8dee2aaSAndroid Build Coastguard Worker    "-Wdeprecated-comma-subscript",
139*c8dee2aaSAndroid Build Coastguard Worker    "-Wdeprecated-copy",
140*c8dee2aaSAndroid Build Coastguard Worker    "-Wdeprecated-copy-dtor",
141*c8dee2aaSAndroid Build Coastguard Worker    "-Wdeprecated-dynamic-exception-spec",
142*c8dee2aaSAndroid Build Coastguard Worker    "-Wdeprecated-enum-compare",
143*c8dee2aaSAndroid Build Coastguard Worker    "-Wdeprecated-enum-compare-conditional",
144*c8dee2aaSAndroid Build Coastguard Worker    "-Wdeprecated-enum-enum-conversion",
145*c8dee2aaSAndroid Build Coastguard Worker    "-Wdeprecated-enum-float-conversion",
146*c8dee2aaSAndroid Build Coastguard Worker    "-Wdeprecated-increment-bool",
147*c8dee2aaSAndroid Build Coastguard Worker    "-Wdeprecated-register",
148*c8dee2aaSAndroid Build Coastguard Worker    "-Wdeprecated-this-capture",
149*c8dee2aaSAndroid Build Coastguard Worker    "-Wdeprecated-volatile",
150*c8dee2aaSAndroid Build Coastguard Worker    "-Wdeprecated-writable-strings",
151*c8dee2aaSAndroid Build Coastguard Worker    # A catch-all for when the version of clang we are using does not have the prior options
152*c8dee2aaSAndroid Build Coastguard Worker    "-Wno-unknown-warning-option",
153*c8dee2aaSAndroid Build Coastguard Worker] + select({
154*c8dee2aaSAndroid Build Coastguard Worker    "@platforms//os:windows": [
155*c8dee2aaSAndroid Build Coastguard Worker        # skbug.com/14203
156*c8dee2aaSAndroid Build Coastguard Worker        "-Wno-nonportable-system-include-path",
157*c8dee2aaSAndroid Build Coastguard Worker        "-Wno-unknown-argument",
158*c8dee2aaSAndroid Build Coastguard Worker        # Clang warns even when all enum values are covered.
159*c8dee2aaSAndroid Build Coastguard Worker        "-Wno-switch-default",
160*c8dee2aaSAndroid Build Coastguard Worker        # The Windows build fails without these options:
161*c8dee2aaSAndroid Build Coastguard Worker        "-Wno-extra-semi-stmt",
162*c8dee2aaSAndroid Build Coastguard Worker        "-Wno-invalid-constexpr",
163*c8dee2aaSAndroid Build Coastguard Worker        "-D_CRT_USE_BUILTIN_OFFSETOF",
164*c8dee2aaSAndroid Build Coastguard Worker    ],
165*c8dee2aaSAndroid Build Coastguard Worker    "//conditions:default": [],
166*c8dee2aaSAndroid Build Coastguard Worker})
167*c8dee2aaSAndroid Build Coastguard Worker
168*c8dee2aaSAndroid Build Coastguard WorkerDEFAULT_COPTS = CORE_COPTS + OPT_LEVEL + WARNINGS
169*c8dee2aaSAndroid Build Coastguard Worker
170*c8dee2aaSAndroid Build Coastguard WorkerOBJC_COPTS = [
171*c8dee2aaSAndroid Build Coastguard Worker    "-Wno-direct-ivar-access",
172*c8dee2aaSAndroid Build Coastguard Worker    "-Wno-objc-interface-ivars",
173*c8dee2aaSAndroid Build Coastguard Worker]
174*c8dee2aaSAndroid Build Coastguard Worker
175*c8dee2aaSAndroid Build Coastguard WorkerDEFAULT_OBJC_COPTS = DEFAULT_COPTS + OBJC_COPTS
176