diff --git a/.github/workflows/clang-tidy.yaml b/.github/workflows/clang-tidy.yaml index 1be6d5d743..5ffc3abaa2 100644 --- a/.github/workflows/clang-tidy.yaml +++ b/.github/workflows/clang-tidy.yaml @@ -11,7 +11,15 @@ permissions: jobs: clang-tidy: - runs-on: ubuntu-24.04 + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + include: + - cmake_options: all-options-abiv1-preview + warning_limit: 215 + - cmake_options: all-options-abiv2-preview + warning_limit: 216 steps: - name: Harden the runner (Audit all outbound calls) uses: step-security/harden-runner@002fdce3c6a235733a90a27c80493a3241e56863 # v2.12.1 @@ -23,19 +31,20 @@ jobs: submodules: recursive - name: Setup Environment - env: - PROTOBUF_VERSION: '23.3' - ABSEIL_CPP_VERSION: '20230125.3' - CXX_STANDARD: '14' run: | sudo apt update -y sudo apt install -y --no-install-recommends --no-install-suggests \ build-essential \ cmake \ + zlib1g-dev \ libssl-dev \ libcurl4-openssl-dev \ + nlohmann-json3-dev \ + libabsl-dev \ libprotobuf-dev \ + libgrpc++-dev \ protobuf-compiler \ + protobuf-compiler-grpc \ libgmock-dev \ libgtest-dev \ libbenchmark-dev @@ -47,42 +56,43 @@ jobs: echo "Using clang-tidy version: $(clang-tidy --version)" echo "clang-tidy installed at: $(which clang-tidy)" - - name: Prepare CMake env: CC: clang CXX: clang++ run: | echo "Running cmake..." - cmake -B build \ + cmake -B build-${{ matrix.cmake_options }} \ + -C ./test_common/cmake/${{ matrix.cmake_options }}.cmake \ -DCMAKE_CXX_STANDARD=14 \ -DWITH_STL=CXX14 \ - -DWITH_OTLP_HTTP=ON \ - -DWITH_OTLP_FILE=ON \ - -DWITH_PROMETHEUS=ON \ - -DWITH_ZIPKIN=ON \ - -DWITH_ELASTICSEARCH=ON \ - -DWITH_OTLP_HTTP_COMPRESSION=ON \ - -DWITH_EXAMPLES=ON \ - -DWITH_EXAMPLES_HTTP=ON \ - -DBUILD_W3CTRACECONTEXT_TEST=ON \ - -DWITH_METRICS_EXEMPLAR_PREVIEW=ON \ - -DWITH_ASYNC_EXPORT_PREVIEW=ON \ - -DCMAKE_EXPORT_COMPILE_COMMANDS=ON + -DWITH_OPENTRACING=OFF \ + -DCMAKE_CXX_FLAGS="-Wno-deprecated-declarations" \ + -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ + -DCMAKE_CXX_CLANG_TIDY="clang-tidy;--quiet;-p;build-${{ matrix.cmake_options }}" - name: Run clang-tidy run: | - cmake --build build --target opentelemetry_proto - jq -r .[].file build/compile_commands.json | grep -vE '/(generated|third_party)/' | xargs -P $(nproc) -n 1 clang-tidy --quiet -p build 2>&1 | tee -a clang-tidy.log + cmake --build build-${{ matrix.cmake_options }} -- -j$(nproc) 2>&1 | tee clang-tidy-${{ matrix.cmake_options }}.log - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 with: - name: Logs (clang-tidy) - path: ./clang-tidy.log + name: Logs-clang-tidy-${{ matrix.cmake_options }} + path: ./clang-tidy-${{ matrix.cmake_options }}.log - name: Count warnings run: | - COUNT=$(grep -c "warning:" clang-tidy.log) - echo "clang-tidy reported ${COUNT} warning(s)" + COUNT=$(grep -c "warning:" clang-tidy-${{ matrix.cmake_options }}.log) + echo "clang-tidy reported ${COUNT} warning(s) with cmake options preset '${{ matrix.cmake_options }}'" + + readonly WARNING_LIMIT=${{ matrix.warning_limit }} + + # FAIL the build if COUNT > WARNING_LIMIT + if [ $COUNT -gt $WARNING_LIMIT ] ; then + echo "clang-tidy reported ${COUNT} warning(s) exceeding the existing warning limit of ${WARNING_LIMIT} with cmake options preset '${{ matrix.cmake_options }}'" + exit 1 + # WARN in annotations if COUNT > 0 + elif [ $COUNT -gt 0 ] ; then + echo "::warning::clang-tidy reported ${COUNT} warning(s) with cmake options preset '${{ matrix.cmake_options }}'" + fi -# TODO: include WITH_OTLP_GRPC flags. diff --git a/.github/workflows/iwyu.yml b/.github/workflows/iwyu.yml index 8c6ba11f7b..823813ea65 100644 --- a/.github/workflows/iwyu.yml +++ b/.github/workflows/iwyu.yml @@ -13,6 +13,17 @@ permissions: jobs: iwyu: runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + include: + - cmake_options: all-options-abiv1 + warning_limit: 5 + - cmake_options: all-options-abiv1-preview + warning_limit: 28 + - cmake_options: all-options-abiv2-preview + warning_limit: 48 + steps: - name: Harden the runner (Audit all outbound calls) uses: step-security/harden-runner@002fdce3c6a235733a90a27c80493a3241e56863 # v2.12.1 @@ -46,52 +57,42 @@ jobs: run: | sudo ./ci/install_iwyu.sh - name: Prepare CMake + env: + CC: clang + CXX: clang++ run: | TOPDIR=`pwd` - mkdir build && cd build - CC="clang" CXX="clang++" cmake \ + cmake -B build-${{ matrix.cmake_options }} \ + -C ./test_common/cmake/${{ matrix.cmake_options }}.cmake \ -DCMAKE_CXX_STANDARD=14 \ -DWITH_STL=CXX14 \ - -DCMAKE_CXX_INCLUDE_WHAT_YOU_USE="include-what-you-use;-w;-Xiwyu;--mapping_file=${TOPDIR}/.iwyu.imp;" \ - -DBUILD_TESTING=ON \ - -DWITH_EXAMPLES=ON \ - -DWITH_EXAMPLES_HTTP=ON \ - -DBUILD_W3CTRACECONTEXT_TEST=ON \ - -DWITH_OTLP_GRPC=ON \ - -DWITH_OTLP_HTTP=ON \ - -DWITH_OTLP_FILE=ON \ - -DWITH_OPENTRACING=ON \ - -DWITH_OTLP_HTTP_COMPRESSION=ON \ - -DWITH_THREAD_INSTRUMENTATION=ON \ - -DWITH_ZIPKIN=ON \ - -DWITH_PROMETHEUS=ON \ - .. + -DCMAKE_CXX_FLAGS="-Wno-deprecated-declarations" \ + -DCMAKE_CXX_INCLUDE_WHAT_YOU_USE="include-what-you-use;-w;-Xiwyu;--mapping_file=${TOPDIR}/.iwyu.imp;" - name: iwyu_tool run: | - cd build - make -k 2>&1 | tee -a iwyu.log + cmake --build build-${{ matrix.cmake_options }} -- -j$(nproc) -k 2>&1 | tee -a iwyu-${{ matrix.cmake_options }}.log - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 if: success() || failure() with: - name: Logs (include-what-you-use) - path: ./build/*.log + name: Logs-iwyu-${{ matrix.cmake_options }} + path: ./iwyu-${{ matrix.cmake_options }}.log - name: count warnings run: | set +e echo "include-what-you-use version:" include-what-you-use --version - cd build - readonly WARNING_COUNT=`grep -c "include-what-you-use reported diagnostics:" iwyu.log` - echo "include-what-you-use reported ${WARNING_COUNT} warning(s)" + readonly WARNING_COUNT=`grep -c "include-what-you-use reported diagnostics:" iwyu-${{ matrix.cmake_options }}.log` + echo "include-what-you-use reported ${WARNING_COUNT} warning(s) with cmake options preset '${{ matrix.cmake_options }}'" # Acceptable limit, to decrease over time down to 0 - readonly WARNING_LIMIT=0 + readonly WARNING_LIMIT=${{ matrix.warning_limit }} # FAIL the build if WARNING_COUNT > WARNING_LIMIT if [ $WARNING_COUNT -gt $WARNING_LIMIT ] ; then + echo "include-what-you-use reported ${WARNING_COUNT} warning(s) exceeding the existing warning limit of ${WARNING_LIMIT} with cmake options preset '${{ matrix.cmake_options }}'" exit 1 # WARN in annotations if WARNING_COUNT > 0 elif [ $WARNING_COUNT -gt 0 ] ; then - echo "::warning::include-what-you-use reported ${WARNING_COUNT} warning(s)" + echo "::warning::include-what-you-use reported ${WARNING_COUNT} warning(s) with cmake options preset '${{ matrix.cmake_options }}'" fi diff --git a/cmake/opentelemetry-proto.cmake b/cmake/opentelemetry-proto.cmake index 5aad69495b..8a04fedee4 100644 --- a/cmake/opentelemetry-proto.cmake +++ b/cmake/opentelemetry-proto.cmake @@ -318,9 +318,9 @@ target_include_directories( PUBLIC "$" "$") -# Disable include-what-you-use on generated code. +# Disable include-what-you-use and clang-tidy on generated code. set_target_properties(opentelemetry_proto PROPERTIES CXX_INCLUDE_WHAT_YOU_USE - "") + "" CXX_CLANG_TIDY "") if(NOT Protobuf_INCLUDE_DIRS AND TARGET protobuf::libprotobuf) get_target_property(Protobuf_INCLUDE_DIRS protobuf::libprotobuf INTERFACE_INCLUDE_DIRECTORIES) @@ -338,9 +338,9 @@ if(WITH_OTLP_GRPC) ${LOGS_SERVICE_GRPC_PB_CPP_FILE} ${METRICS_SERVICE_GRPC_PB_CPP_FILE}) set_target_version(opentelemetry_proto_grpc) - # Disable include-what-you-use on generated code. + # Disable include-what-you-use and clang-tidy on generated code. set_target_properties(opentelemetry_proto_grpc - PROPERTIES CXX_INCLUDE_WHAT_YOU_USE "") + PROPERTIES CXX_INCLUDE_WHAT_YOU_USE "" CXX_CLANG_TIDY "") list(APPEND OPENTELEMETRY_PROTO_TARGETS opentelemetry_proto_grpc) target_link_libraries(opentelemetry_proto_grpc PUBLIC opentelemetry_proto) diff --git a/examples/grpc/CMakeLists.txt b/examples/grpc/CMakeLists.txt index 4f87bc3b89..78d5f7823b 100644 --- a/examples/grpc/CMakeLists.txt +++ b/examples/grpc/CMakeLists.txt @@ -41,8 +41,9 @@ add_custom_command( add_library(example_grpc_proto ${example_grpc_srcs} ${example_grpc_hdrs} ${example_proto_srcs} ${example_proto_hdrs}) -# Disable include-what-you-use on generated code. -set_target_properties(example_grpc_proto PROPERTIES CXX_INCLUDE_WHAT_YOU_USE "") +# Disable include-what-you-use and clang-tidy on generated code. +set_target_properties(example_grpc_proto PROPERTIES CXX_INCLUDE_WHAT_YOU_USE "" + CXX_CLANG_TIDY "") target_include_directories( example_grpc_proto PUBLIC "$") diff --git a/test_common/cmake/all-options-abiv1-preview.cmake b/test_common/cmake/all-options-abiv1-preview.cmake new file mode 100644 index 0000000000..16c21c29d1 --- /dev/null +++ b/test_common/cmake/all-options-abiv1-preview.cmake @@ -0,0 +1,10 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +# Enable all options with ABI V1 including preview features + +set(WITH_ABI_VERSION_1 ON CACHE BOOL "" FORCE) +set(WITH_ABI_VERSION_2 OFF CACHE BOOL "" FORCE) + +set(ENABLE_PREVIEW ON) +include(${CMAKE_CURRENT_LIST_DIR}/all-options.cmake) diff --git a/test_common/cmake/all-options-abiv1.cmake b/test_common/cmake/all-options-abiv1.cmake new file mode 100644 index 0000000000..212faf4866 --- /dev/null +++ b/test_common/cmake/all-options-abiv1.cmake @@ -0,0 +1,10 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +# Enable all options with ABI V1 except preview features + +set(WITH_ABI_VERSION_1 ON CACHE BOOL "" FORCE) +set(WITH_ABI_VERSION_2 OFF CACHE BOOL "" FORCE) + +set(ENABLE_PREVIEW OFF) +include(${CMAKE_CURRENT_LIST_DIR}/all-options.cmake) diff --git a/test_common/cmake/all-options-abiv2-preview.cmake b/test_common/cmake/all-options-abiv2-preview.cmake new file mode 100644 index 0000000000..984524a4ae --- /dev/null +++ b/test_common/cmake/all-options-abiv2-preview.cmake @@ -0,0 +1,10 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +# Enable all options with ABI V2 including preview features + +set(WITH_ABI_VERSION_1 OFF CACHE BOOL "" FORCE) +set(WITH_ABI_VERSION_2 ON CACHE BOOL "" FORCE) + +set(ENABLE_PREVIEW ON) +include(${CMAKE_CURRENT_LIST_DIR}/all-options.cmake) diff --git a/test_common/cmake/all-options-abiv2.cmake b/test_common/cmake/all-options-abiv2.cmake new file mode 100644 index 0000000000..5210b4f659 --- /dev/null +++ b/test_common/cmake/all-options-abiv2.cmake @@ -0,0 +1,10 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +# Enable all options with ABI V2 except preview features + +set(WITH_ABI_VERSION_1 OFF CACHE BOOL "" FORCE) +set(WITH_ABI_VERSION_2 ON CACHE BOOL "" FORCE) + +set(ENABLE_PREVIEW OFF) +include(${CMAKE_CURRENT_LIST_DIR}/all-options.cmake) diff --git a/test_common/cmake/all-options.cmake b/test_common/cmake/all-options.cmake new file mode 100644 index 0000000000..213a28996b --- /dev/null +++ b/test_common/cmake/all-options.cmake @@ -0,0 +1,9 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +# All options for the opentelemetry-cpp project. + +include(${CMAKE_CURRENT_LIST_DIR}/component-options.cmake) +include(${CMAKE_CURRENT_LIST_DIR}/example-options.cmake) +include(${CMAKE_CURRENT_LIST_DIR}/testing-options.cmake) +include(${CMAKE_CURRENT_LIST_DIR}/preview-options.cmake) diff --git a/test_common/cmake/component-options.cmake b/test_common/cmake/component-options.cmake new file mode 100644 index 0000000000..489f84596b --- /dev/null +++ b/test_common/cmake/component-options.cmake @@ -0,0 +1,24 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +# All components options + +if(NOT DEFINED ENABLE_COMPONENTS) + set(ENABLE_COMPONENTS ON) +endif() + +set(WITH_OTLP_GRPC ${ENABLE_COMPONENTS} CACHE BOOL "" FORCE) +set(WITH_OTLP_HTTP ${ENABLE_COMPONENTS} CACHE BOOL "" FORCE) +set(WITH_OTLP_FILE ${ENABLE_COMPONENTS} CACHE BOOL "" FORCE) + +set(WITH_PROMETHEUS ${ENABLE_COMPONENTS} CACHE BOOL "" FORCE) +set(WITH_ZIPKIN ${ENABLE_COMPONENTS} CACHE BOOL "" FORCE) +set(WITH_ELASTICSEARCH ${ENABLE_COMPONENTS} CACHE BOOL "" FORCE) + +if(WIN32) + set(WITH_ETW ${ENABLE_COMPONENTS} CACHE BOOL "" FORCE) +endif() + +if(WITH_ABI_VERSION_1) + set(WITH_OPENTRACING ${ENABLE_COMPONENTS} CACHE BOOL "" FORCE) +endif() diff --git a/test_common/cmake/example-options.cmake b/test_common/cmake/example-options.cmake new file mode 100644 index 0000000000..4249f59531 --- /dev/null +++ b/test_common/cmake/example-options.cmake @@ -0,0 +1,11 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +# All examples options + +if(NOT DEFINED ENABLE_EXAMPLES) + set(ENABLE_EXAMPLES ON) +endif() + +set(WITH_EXAMPLES ${ENABLE_EXAMPLES} CACHE BOOL "" FORCE) +set(WITH_EXAMPLES_HTTP ${ENABLE_EXAMPLES} CACHE BOOL "" FORCE) diff --git a/test_common/cmake/preview-options.cmake b/test_common/cmake/preview-options.cmake new file mode 100644 index 0000000000..88acf7a187 --- /dev/null +++ b/test_common/cmake/preview-options.cmake @@ -0,0 +1,17 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +# All preview feature options + +if(NOT DEFINED ENABLE_PREVIEW) + set(ENABLE_PREVIEW ON) +endif() + +set(WITH_METRICS_EXEMPLAR_PREVIEW ${ENABLE_PREVIEW} CACHE BOOL "" FORCE) +set(WITH_ASYNC_EXPORT_PREVIEW ${ENABLE_PREVIEW} CACHE BOOL "" FORCE) +set(WITH_THREAD_INSTRUMENTATION_PREVIEW ${ENABLE_PREVIEW} CACHE BOOL "" FORCE) +set(WITH_OTLP_GRPC_SSL_MTLS_PREVIEW ${ENABLE_PREVIEW} CACHE BOOL "" FORCE) +set(WITH_OTLP_GRPC_CREDENTIAL_PREVIEW ${ENABLE_PREVIEW} CACHE BOOL "" FORCE) +set(WITH_OTLP_RETRY_PREVIEW ${ENABLE_PREVIEW} CACHE BOOL "" FORCE) +set(WITH_OTLP_HTTP_COMPRESSION ${ENABLE_PREVIEW} CACHE BOOL "" FORCE) +set(WITH_CURL_LOGGING ${ENABLE_PREVIEW} CACHE BOOL "" FORCE) diff --git a/test_common/cmake/testing-options.cmake b/test_common/cmake/testing-options.cmake new file mode 100644 index 0000000000..fc64493a18 --- /dev/null +++ b/test_common/cmake/testing-options.cmake @@ -0,0 +1,13 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +# All testing options + +if(NOT DEFINED ENABLE_TESTS) + set(ENABLE_TESTS ON) +endif() + +set(BUILD_TESTING ${ENABLE_TESTS} CACHE BOOL "" FORCE) +set(BUILD_W3CTRACECONTEXT_TEST ${ENABLE_TESTS} CACHE BOOL "" FORCE) +set(WITH_BENCHMARK ${ENABLE_TESTS} CACHE BOOL "" FORCE) +set(WITH_FUNC_TESTS ${ENABLE_TESTS} CACHE BOOL "" FORCE)