blob: e39184ccc116e1260de272f8dd3bb824e5a9dfff [file] [log] [blame]
This file contains flags for the C++ compiler, referred to by Bazel as copts.
The copts in a cc_library to not flow to the children (dependencies) nor the parents
(dependents), so we cannot define them alongside the defines in //bazel/BUILD.bazel.
We cannot (easily) define them in the C++ toolchain configuration
(e.g. //toolchain/linux_amd64_toolchain_config.bzl), because that does not support listening
to arbitrary Bazel flags (e.g. those defined in //bazel/common_config_settings). If we wanted
to implement these flags in the toolchain, we would need to group them into features [1],
but we don't control the features implemented by the G3 toolchain. Because we want to
automatically roll into G3 with minimal changes, the copts cannot go in the toolchain,
Thus, they go here, so we can use select statements to conditionally control them and
override what they do (if necessary) in G3.
They are divided into several lists/selects and were initially created to be identical to the
GN ones [2][3].
The flags here are *not* used when compiling our third_party libraries (although the flags will
impact the included public headers of those third_party libraries). If we need a flag to impact
both Skia and a third party dep, it should probably go in the toolchain_config. If that is not
possible (e.g. the setting depends on a custom flag), we can define a subworkspace and have both
Skia and the third party dep depend on that.
"-fno-rtti", # Reduces code size
] + select({
# SkRawCodec catches any exceptions thrown by dng_sdk, insulating the rest of Skia.
"//bazel/common_config_settings:raw_decode_codec": [],
"//conditions:default": ["-fno-exceptions"],
OPT_LEVEL = select({
"//bazel/common_config_settings:debug_build": [
"//bazel/common_config_settings:release_build": [
# Strip dead code (in conjunction with linkopts)
"//bazel/common_config_settings:fast_build": [
#### Warnings we are unlikely to fix ####
"-Wno-psabi", # noisy
"-Wno-unused-parameter", # It is common to have unused parameters in src/
"-Wno-zero-as-null-pointer-constant", # VK_NULL_HANDLE is defined as 0
#### Warnings we would like to fix ####
"-Wno-conversion", # -Wsign-conversion re-enabled for header sources
"-Wno-exit-time-destructors", # TODO: OK outside libskia
"-Wno-global-constructors", # TODO: OK outside libskia
"-Wno-weak-template-vtables", # This was deprecated in Clang 14 and removed in Clang 15.
# Wno-range-loop-analysis turns off the whole group, but this warning was later split into
# range-loop-construct and range-loop-bind-reference. We want the former but not the latter.
# Created from
# Wno-deprecated turns off the whole group, but also has its own warnings like
# out-of-line definition of constexpr static data member is redundant in C++17 and is deprecated [-Werror,-Wdeprecated]
# but we would like others. Created from