Skip to content

Commit ff47278

Browse files
build: align Bazel cxxopts with CMake warning flags
Add the same -Wno-* and -fsized-deallocation flags used in CMakeLists for non-MSVC toolchains; cross-reference in CMake comment.
1 parent ed16c2d commit ff47278

2 files changed

Lines changed: 42 additions & 18 deletions

File tree

CMakeLists.txt

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -119,23 +119,30 @@ if (MSVC)
119119
# Make sure Windows doesn't define min/max macros that interfere with STL
120120
add_definitions(-DNOMINMAX)
121121
else()
122-
# Avoid megabytes of warnings like:
123-
# util/math/vector.h:178:16: warning: optimization attribute on
124-
# ‘double sqrt(double)’ follows definition but the attribute doesn’t
125-
# match [-Wattributes]
126-
add_definitions(-Wno-attributes)
127-
add_definitions(-Wno-deprecated-declarations)
128-
add_definitions(-Wno-nullability-completeness)
129-
# Suppress noisy AArch64 ABI notes about parameter passing changes in
130-
# GCC 10.1. Irrelevant since we don't mix objects from old compilers.
131-
# TODO: Use check_cxx_compiler_flag(-Wno-psabi) to guard this.
132-
add_compile_options(-Wno-psabi)
133-
# Some files use sized deallocation, which should be enabled by
134-
# default for C++14 and later. There appears to be a bug with clang
135-
# < 19 causing this not to be enabled.
136-
# https://github.com/google/s2geometry/issues/411#issuecomment-2726949607
137-
# This can be removed when clang19 is the minimum supported version.
138-
add_compile_options(-fsized-deallocation)
122+
# OSS #458: silence only observed warning churn, guarded by toolchain support.
123+
124+
check_cxx_compiler_flag(-Wno-attributes S2_CXX_SUPPORTS_WNO_ATTRIBUTES)
125+
if (S2_CXX_SUPPORTS_WNO_ATTRIBUTES)
126+
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-Wno-attributes>)
127+
endif()
128+
129+
check_cxx_compiler_flag(-Wno-nullability-completeness
130+
S2_CXX_SUPPORTS_WNO_NULLABILITY_COMPLETENESS)
131+
if (S2_CXX_SUPPORTS_WNO_NULLABILITY_COMPLETENESS)
132+
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-Wno-nullability-completeness>)
133+
endif()
134+
135+
check_cxx_compiler_flag(-Wno-psabi S2_CXX_SUPPORTS_WNO_PSABI)
136+
if (S2_CXX_SUPPORTS_WNO_PSABI)
137+
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-Wno-psabi>)
138+
endif()
139+
140+
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
141+
check_cxx_compiler_flag(-fsized-deallocation S2_CXX_SUPPORTS_FSIZED_DEALLOCATION)
142+
if (S2_CXX_SUPPORTS_FSIZED_DEALLOCATION)
143+
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fsized-deallocation>)
144+
endif()
145+
endif()
139146
endif()
140147

141148
# If OpenSSL is installed in a non-standard location, configure with

src/.bazelrc

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,27 @@ common --enable_bzlmod
33
common --cxxopt=-std=c++20
44
common --announce_rc
55

6+
# OSS #458: compiler-specific warning/c++ flags (keep in conceptual sync with the
7+
# `check_cxx_compiler_flag` gate in CMakeLists.txt). Typical usage:
8+
# bazel test --config=dev --config=clang # AppleClang / explicit Clang
9+
# bazel test --config=dev --config=gcc # host GCC on Linux CI
10+
#
11+
# Keep these minimal: entries should correspond to churn we deliberately silence.
12+
13+
# Host GCC toolchains (typical ubuntu-latest CI).
14+
build:gcc --cxxopt=-Wno-attributes
15+
build:gcc --cxxopt=-Wno-psabi
16+
17+
# Clang toolchains (typical Darwin / explicit clang setups).
18+
build:clang --cxxopt=-Wno-attributes
19+
build:clang --cxxopt=-Wno-nullability-completeness
20+
build:clang --cxxopt=-fsized-deallocation
21+
622
# Faster tests than fastbuild (-O0).
723
build:dev --copt=-O1
824

9-
# CI-specific flags
25+
# CI-specific flags (also select the GCC-aligned warning config).
1026
common:ci --color=yes
27+
common:ci --config=gcc
1128
build:ci --show_progress_rate_limit=10
1229
test:ci --test_output=errors

0 commit comments

Comments
 (0)