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