From 25feca605dfa0a768ce8abd61c6ec7b0de3a1d08 Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Tue, 8 Oct 2024 16:40:59 +0200 Subject: [PATCH] build: tools workflow (first draft, to be tested) --- .clang-tidy | 0 .github/workflows/tools.yml | 78 +++++++++++++++++++++++++++++++++++++ CMakeLists.txt | 12 ++++++ uwv.imp | 0 4 files changed, 90 insertions(+) create mode 100644 .clang-tidy create mode 100644 .github/workflows/tools.yml create mode 100644 uwv.imp diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 00000000..e69de29b diff --git a/.github/workflows/tools.yml b/.github/workflows/tools.yml new file mode 100644 index 00000000..a4229f18 --- /dev/null +++ b/.github/workflows/tools.yml @@ -0,0 +1,78 @@ +name: tools + +on: + push: + branches: + - tools + +jobs: + + iwyu: + timeout-minutes: 60 + + env: + IWYU: "0.22" + LLVM: "18" + + runs-on: ubuntu-latest + continue-on-error: true + + steps: + - uses: actions/checkout@v4 + - name: Install llvm/clang + # see: https://apt.llvm.org/ + run: | + wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - + sudo add-apt-repository "deb http://apt.llvm.org/focal/ llvm-toolchain-focal-$LLVM main" + sudo apt update + sudo apt remove -y "llvm*" + sudo apt remove -y "libclang-dev*" + sudo apt remove -y "clang*" + sudo apt install -y llvm-$LLVM-dev + sudo apt install -y libclang-$LLVM-dev + sudo apt install -y clang-$LLVM + - name: Compile iwyu + # see: https://github.com/include-what-you-use/include-what-you-use + working-directory: build + run: | + git clone https://github.com/include-what-you-use/include-what-you-use.git --branch $IWYU --depth 1 + mkdir include-what-you-use/build + cd include-what-you-use/build + cmake -DCMAKE_C_COMPILER=clang-$LLVM \ + -DCMAKE_CXX_COMPILER=clang++-$LLVM \ + -DCMAKE_INSTALL_PREFIX=./ \ + .. + make -j4 + bin/include-what-you-use --version + - name: Compile tests + working-directory: build + run: | + export PATH=$PATH:${GITHUB_WORKSPACE}/build/include-what-you-use/build/bin + cmake -DBUILD_TESTING=ON + -Dlibuv_buildtests=OFF + -DCMAKE_C_COMPILER=clang-$LLVM \ + -DCMAKE_CXX_COMPILER=clang++-$LLVM \ + -DCMAKE_CXX_INCLUDE_WHAT_YOU_USE="include-what-you-use;-Xiwyu;--mapping_file=${GITHUB_WORKSPACE}/uwv.imp;-Xiwyu;--no_fwd_decls;-Xiwyu;--verbose=1" \ + .. + make -j4 + + clang-tidy: + timeout-minutes: 60 + + runs-on: ubuntu-latest + continue-on-error: true + + steps: + - uses: actions/checkout@v4 + - name: Compile tests + working-directory: build + env: + CXX: clang++ + run: | + cmake -DBUILD_TESTING=ON -Dlibuv_buildtests=OFF -DUSE_CLANG_TIDY=ON .. + make -j4 + - name: Run tests + working-directory: build + env: + CTEST_OUTPUT_ON_FAILURE: 1 + run: ctest -C Debug -j4 diff --git a/CMakeLists.txt b/CMakeLists.txt index 75b23e7c..c38c653b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,6 +34,7 @@ endif() option(USE_LIBCPP "Use libc++ by adding -stdlib=libc++ flag if available." ON) option(USE_ASAN "Use address sanitizer by adding -fsanitize=address -fno-omit-frame-pointer flags" OFF) option(USE_UBSAN "Use address sanitizer by adding -fsanitize=undefined -fno-sanitize-recover=all -fno-omit-frame-pointer flags" OFF) +option(USE_CLANG_TIDY "Enable static analysis with clang-tidy" OFF) option(BUILD_UVW_LIBS "Prepare targets for static library rather than for a header-only library." OFF) option(BUILD_UVW_SHARED_LIB "Prepare targets for shared library rather than for a header-only library." OFF) option(FIND_LIBUV "Try finding libuv library development files in the system" OFF) @@ -66,6 +67,13 @@ if(NOT WIN32 AND USE_LIBCPP) cmake_pop_check_state() endif() +if(USE_CLANG_TIDY) + find_program(CLANG_TIDY_EXECUTABLE "clang-tidy") + + if(NOT CLANG_TIDY_EXECUTABLE) + message(VERBOSE "The option USE_CLANG_TIDY is set but clang-tidy executable is not available.") + endif() +endif() # Required minimal libuv version set(LIBUV_VERSION 1.49.0) @@ -157,6 +165,10 @@ else() target_link_libraries(uvw INTERFACE $<$:-fsanitize=undefined>) endif() + if(CLANG_TIDY_EXECUTABLE) + set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_EXECUTABLE};--config-file=${uwv_SOURCE_DIR}/.clang-tidy;--header-filter=${uwv_SOURCE_DIR}/src/uvw/.*") + endif() + if(HAS_LIBCPP) target_compile_options(uvw BEFORE INTERFACE -stdlib=libc++) endif() diff --git a/uwv.imp b/uwv.imp new file mode 100644 index 00000000..e69de29b