Skip to content

Commit bdbf665

Browse files
committed
fix: sync compiler flags with instrument-hooks; add strict mode
1 parent efb7802 commit bdbf665

File tree

2 files changed

+68
-24
lines changed

2 files changed

+68
-24
lines changed

core/BUILD

Lines changed: 47 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,60 @@ config_setting(
88
constraint_values = ["@platforms//os:windows"],
99
)
1010

11+
# Strict warnings mode
12+
string_flag(
13+
name = "strict_warnings",
14+
build_setting_default = "off",
15+
values = [
16+
"off",
17+
"on",
18+
],
19+
)
20+
21+
config_setting(
22+
name = "strict_warnings_enabled",
23+
flag_values = {":strict_warnings": "on"},
24+
)
25+
26+
config_setting(
27+
name = "windows_strict_warnings",
28+
constraint_values = ["@platforms//os:windows"],
29+
flag_values = {":strict_warnings": "on"},
30+
)
31+
32+
# IMPORTANT: Keep in sync with instrument-hooks/ci.yml (COMMON_CFLAGS)
33+
instrument_hooks_cflags = [
34+
"-Wno-format-security",
35+
"-Wno-unused-but-set-variable",
36+
"-Wno-unused-const-variable",
37+
"-Wno-type-limits",
38+
"-Wno-uninitialized",
39+
# When cross-compiling:
40+
"-Wno-constant-conversion",
41+
"-Wno-incompatible-pointer-types",
42+
"-Wno-unused-function",
43+
]
44+
45+
instrument_hooks_cflags_windows = [
46+
"/wd4101", # unreferenced local variable (equivalent to -Wno-unused-variable)
47+
"/wd4189", # local variable is initialized but not referenced (equivalent to -Wno-unused-but-set-variable)
48+
"/wd4100", # unreferenced formal parameter (equivalent to -Wno-unused-parameter)
49+
"/wd4245", # signed/unsigned mismatch
50+
"/wd4132", # const object should be initialized
51+
"/wd4146", # unary minus operator applied to unsigned type
52+
]
53+
1154
# Instrument-hooks library with warning suppressions
1255
cc_library(
1356
name = "instrument_hooks",
1457
srcs = ["instrument-hooks/dist/core.c"],
1558
hdrs = glob(["instrument-hooks/includes/*.h"]),
1659
includes = ["instrument-hooks/includes"],
1760
copts = select({
18-
":windows": [
19-
"/wd4101", # unreferenced local variable (equivalent to -Wno-unused-variable)
20-
"/wd4189", # local variable is initialized but not referenced (equivalent to -Wno-unused-but-set-variable)
21-
"/wd4100", # unreferenced formal parameter (equivalent to -Wno-unused-parameter)
22-
"/wd4245", # signed/unsigned mismatch
23-
"/wd4132", # const object should be initialized
24-
"/wd4146", # unary minus operator applied to unsigned type
25-
],
26-
"//conditions:default": [
27-
"-Wno-maybe-uninitialized",
28-
"-Wno-unused-variable",
29-
"-Wno-unused-parameter",
30-
"-Wno-unused-but-set-variable",
31-
"-Wno-type-limits",
32-
"-Wno-format",
33-
"-Wno-format-security",
34-
],
61+
":windows_strict_warnings": ["/W4","/WX"] + instrument_hooks_cflags_windows,
62+
":windows": instrument_hooks_cflags_windows,
63+
":strict_warnings_enabled": ["-Wall", "-Werror"] + instrument_hooks_cflags,
64+
"//conditions:default": instrument_hooks_cflags,
3565
}),
3666
visibility = ["//visibility:public"],
3767
)

core/CMakeLists.txt

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,32 @@ target_include_directories(
3838
$<INSTALL_INTERFACE:includes>
3939
)
4040

41+
# Option to enable strict warnings (for CI builds)
42+
option(CODSPEED_STRICT_WARNINGS "Enable strict warnings" OFF)
43+
4144
# Suppress warnings for the instrument_hooks library
4245
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
46+
# IMPORTANT: Keep in sync with instrument-hooks/ci.yml (COMMON_CFLAGS)
47+
set(INSTRUMENT_HOOKS_CFLAGS
48+
-Wno-format-security
49+
-Wno-unused-but-set-variable
50+
-Wno-unused-const-variable
51+
-Wno-type-limits
52+
-Wno-uninitialized
53+
# When cross-compiling:
54+
-Wno-constant-conversion
55+
-Wno-incompatible-pointer-types
56+
-Wno-unused-function
57+
)
58+
59+
if(CODSPEED_STRICT_WARNINGS)
60+
list(PREPEND INSTRUMENT_HOOKS_CFLAGS -Wall -Werror)
61+
endif()
62+
4363
target_compile_options(
4464
instrument_hooks
4565
PRIVATE
46-
-Wno-maybe-uninitialized
47-
-Wno-unused-variable
48-
-Wno-unused-parameter
49-
-Wno-unused-but-set-variable
50-
-Wno-type-limits
51-
-Wno-format
52-
-Wno-format-security
66+
${INSTRUMENT_HOOKS_CFLAGS}
5367
)
5468
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
5569
target_compile_options(

0 commit comments

Comments
 (0)