diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ed3153a..2dfd6f3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -35,7 +35,7 @@ jobs: - name: Build tests run: | cd core/build-tests - cmake .. -DENABLE_TESTS=ON + cmake .. -DENABLE_TESTS=ON -DCODSPEED_STRICT_WARNINGS=ON make -j - name: Run tests @@ -79,7 +79,7 @@ jobs: - name: Build benchmark example run: | cd examples/google_benchmark_cmake/build - cmake -DCODSPEED_MODE=${{ matrix.codspeed-mode }} .. + cmake -DCODSPEED_MODE=${{ matrix.codspeed-mode }} -DCODSPEED_STRICT_WARNINGS=ON .. make -j - name: Run the benchmarks @@ -118,14 +118,14 @@ jobs: - name: Build and run benchmarks run: | - bazel build //examples/google_benchmark_bazel:my_benchmark --//core:codspeed_mode=${{ matrix.codspeed-mode }} + bazel build //examples/google_benchmark_bazel:my_benchmark --//core:codspeed_mode=${{ matrix.codspeed-mode }} --//core:strict_warnings=on - name: Run the benchmarks uses: CodSpeedHQ/action@main if: matrix.codspeed-mode != 'off' with: mode: ${{ matrix.codspeed-mode }} - run: bazel run //examples/google_benchmark_bazel:my_benchmark --//core:codspeed_mode=${{ matrix.codspeed-mode }} + run: bazel run //examples/google_benchmark_bazel:my_benchmark --//core:codspeed_mode=${{ matrix.codspeed-mode }} --//core:strict_warnings=on token: ${{ secrets.CODSPEED_TOKEN }} cmake-build: @@ -193,4 +193,4 @@ jobs: - name: Build benchmark example run: | - bazel build //examples/google_benchmark_bazel:my_benchmark --//core:codspeed_mode=${{ matrix.codspeed-mode }} + bazel build //examples/google_benchmark_bazel:my_benchmark --//core:codspeed_mode=${{ matrix.codspeed-mode }} --//core:strict_warnings=on diff --git a/core/BUILD b/core/BUILD index 1390823..4c91d3d 100644 --- a/core/BUILD +++ b/core/BUILD @@ -8,6 +8,50 @@ config_setting( constraint_values = ["@platforms//os:windows"], ) +# Strict warnings mode +string_flag( + name = "strict_warnings", + build_setting_default = "off", + values = [ + "off", + "on", + ], +) + +config_setting( + name = "strict_warnings_enabled", + flag_values = {":strict_warnings": "on"}, +) + +config_setting( + name = "windows_strict_warnings", + constraint_values = ["@platforms//os:windows"], + flag_values = {":strict_warnings": "on"}, +) + +# IMPORTANT: Keep in sync with instrument-hooks/ci.yml (COMMON_CFLAGS) +instrument_hooks_cflags = [ + "-Wno-format", + "-Wno-format-security", + "-Wno-unused-but-set-variable", + "-Wno-unused-const-variable", + "-Wno-type-limits", + "-Wno-uninitialized", + # When cross-compiling: + "-Wno-constant-conversion", + "-Wno-incompatible-pointer-types", + "-Wno-unused-function", +] + +instrument_hooks_cflags_windows = [ + "/wd4101", # unreferenced local variable (equivalent to -Wno-unused-variable) + "/wd4189", # local variable is initialized but not referenced (equivalent to -Wno-unused-but-set-variable) + "/wd4100", # unreferenced formal parameter (equivalent to -Wno-unused-parameter) + "/wd4245", # signed/unsigned mismatch + "/wd4132", # const object should be initialized + "/wd4146", # unary minus operator applied to unsigned type +] + # Instrument-hooks library with warning suppressions cc_library( name = "instrument_hooks", @@ -15,23 +59,10 @@ cc_library( hdrs = glob(["instrument-hooks/includes/*.h"]), includes = ["instrument-hooks/includes"], copts = select({ - ":windows": [ - "/wd4101", # unreferenced local variable (equivalent to -Wno-unused-variable) - "/wd4189", # local variable is initialized but not referenced (equivalent to -Wno-unused-but-set-variable) - "/wd4100", # unreferenced formal parameter (equivalent to -Wno-unused-parameter) - "/wd4245", # signed/unsigned mismatch - "/wd4132", # const object should be initialized - "/wd4146", # unary minus operator applied to unsigned type - ], - "//conditions:default": [ - "-Wno-maybe-uninitialized", - "-Wno-unused-variable", - "-Wno-unused-parameter", - "-Wno-unused-but-set-variable", - "-Wno-type-limits", - "-Wno-format", - "-Wno-format-security", - ], + ":windows_strict_warnings": ["/W4","/WX"] + instrument_hooks_cflags_windows, + ":windows": instrument_hooks_cflags_windows, + ":strict_warnings_enabled": ["-Wall", "-Werror"] + instrument_hooks_cflags, + "//conditions:default": instrument_hooks_cflags, }), visibility = ["//visibility:public"], ) diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 21b2639..6a8c6ab 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -11,32 +11,60 @@ set(CMAKE_CXX_STANDARD_REQUIRED True) # Add the include directory include_directories(include) +include(FetchContent) +FetchContent_Declare( + instrument_hooks_repo + GIT_REPOSITORY https://github.com/CodSpeedHQ/instrument-hooks + GIT_TAG b1e401a4d031ad308edb22ed59a52253a1ebe924 +) +FetchContent_MakeAvailable(instrument_hooks_repo) +FetchContent_GetProperties(instrument_hooks_repo) +if(NOT instrument_hooks_repo_POPULATED) + FetchContent_Populate(instrument_hooks_repo) +endif() +set(instrument_hooks_SOURCE_DIR ${instrument_hooks_repo_SOURCE_DIR}) + # Add the instrument_hooks library add_library( instrument_hooks STATIC - instrument-hooks/dist/core.c + ${instrument_hooks_SOURCE_DIR}/dist/core.c ) target_include_directories( instrument_hooks PUBLIC - $ + $ $ ) +# Option to enable strict warnings (for CI builds) +option(CODSPEED_STRICT_WARNINGS "Enable strict warnings" OFF) + # Suppress warnings for the instrument_hooks library if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") + # IMPORTANT: Keep in sync with instrument-hooks/ci.yml (COMMON_CFLAGS) + set(INSTRUMENT_HOOKS_CFLAGS + -Wno-format + -Wno-format-security + -Wno-unused-but-set-variable + -Wno-unused-const-variable + -Wno-type-limits + -Wno-uninitialized + # When cross-compiling: + -Wno-constant-conversion + -Wno-incompatible-pointer-types + -Wno-unused-function + ) + + if(CODSPEED_STRICT_WARNINGS) + list(PREPEND INSTRUMENT_HOOKS_CFLAGS -Wall -Werror) + endif() + target_compile_options( instrument_hooks PRIVATE - -Wno-maybe-uninitialized - -Wno-unused-variable - -Wno-unused-parameter - -Wno-unused-but-set-variable - -Wno-type-limits - -Wno-format - -Wno-format-security + ${INSTRUMENT_HOOKS_CFLAGS} ) elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") target_compile_options( @@ -72,7 +100,7 @@ add_compile_definitions(CODSPEED_VERSION="${CODSPEED_VERSION}") target_include_directories( codspeed PUBLIC $ - $ + $ ) # Disable valgrind compilation errors diff --git a/core/instrument-hooks b/core/instrument-hooks index b1e401a..b260b17 160000 --- a/core/instrument-hooks +++ b/core/instrument-hooks @@ -1 +1 @@ -Subproject commit b1e401a4d031ad308edb22ed59a52253a1ebe924 +Subproject commit b260b17f1eb5a2e292c112c9d399c9cd5b42c65c