diff --git a/.github/workflows/github-cxx-qt-tests.yml b/.github/workflows/github-cxx-qt-tests.yml index 4c77695dc..0032a6cbc 100644 --- a/.github/workflows/github-cxx-qt-tests.yml +++ b/.github/workflows/github-cxx-qt-tests.yml @@ -71,11 +71,22 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v4 + # Note we need to match the LLVM and Rust versions + # + # See versions from the table in this link + # https://github.com/taiki-e/cargo-llvm-cov?tab=readme-ov-file#get-coverage-of-cc-code-linked-to-rust-librarybinary + - name: Install llvm 17 + run: | + sudo apt-get update && sudo apt-get install -y llvm-17 + test -d /usr/lib/llvm-17/bin/ - name: Setup toolchain run: | + # Note that the llvm version needs to match, see the link above rustup default 1.77.2 cargo install grcov - rustup component add llvm-tools rustfmt + rustup component add rustfmt + # Ensure we do not have any existing coverage files + - run: rm -f coverage/*.profraw - name: build env: RUSTFLAGS: -Cinstrument-coverage @@ -87,7 +98,7 @@ jobs: LLVM_PROFILE_FILE: coverage/coverage_data-%p-%m.profraw run: cargo test --lib --package cxx-qt-gen - name: generate-report - run: grcov . -s . --binary-path ./target/debug/ -t lcov --branch --ignore-not-existing -o ./target/debug/lcov.info --excl-start CODECOV_EXCLUDE_START --excl-stop CODECOV_EXCLUDE_STOP + run: grcov . -s . --binary-path ./target/debug/ -t lcov --branch --ignore-not-existing --llvm --llvm-path /usr/lib/llvm-17/bin/ -o ./target/debug/lcov.info --excl-start CODECOV_EXCLUDE_START --excl-stop CODECOV_EXCLUDE_STOP - name: upload-report uses: codecov/codecov-action@v5 with: diff --git a/scripts/grcov_cxx_qt.sh b/scripts/grcov_cxx_qt.sh index 1103d872b..94ffcd0e6 100755 --- a/scripts/grcov_cxx_qt.sh +++ b/scripts/grcov_cxx_qt.sh @@ -5,19 +5,31 @@ # # SPDX-License-Identifier: MIT OR Apache-2.0 -# Assumes you have grcov and llvm-tools +# Assumes you have grcov and llvm in a system path # Install: # cargo install grcov -# rustup component add llvm-tools set -ex + # Ensure we are in the right directory SCRIPT=$(realpath "$0") SCRIPTPATH=$(dirname "$SCRIPT") cd "$SCRIPTPATH/../" +# Ensure coverage folder is cleared +rm -f "$SCRIPTPATH"/coverage/*.profraw + +# Check that the llvm path exists +# +# We can use rustup component add llvm-tools but this can be out of sync +# See versions from the table in this link +# https://github.com/taiki-e/cargo-llvm-cov?tab=readme-ov-file#get-coverage-of-cc-code-linked-to-rust-librarybinary +if [ ! -d /usr/lib/llvm-17/bin/ ]; then + echo "LLVM 17 not found" +fi + export RUSTFLAGS="-Cinstrument-coverage" export LLVM_PROFILE_FILE="$SCRIPTPATH/coverage/coverage_data-%p-%m.profraw" cargo build --package cxx-qt-gen cargo test --package cxx-qt-gen -grcov . -s . --binary-path ./target/debug/ -t html --branch --ignore-not-existing -o ./target/debug/ --excl-start CODECOV_EXCLUDE_START --excl-stop CODECOV_EXCLUDE_STOP -echo "Coverage html report generated in $(realpath "$SCRIPTPATH"/../target/debug/html)" \ No newline at end of file +grcov . -s . --binary-path ./target/debug/ -t html --branch --ignore-not-existing --llvm --llvm-path=/usr/lib/llvm-17/bin/ -o ./target/debug/ --excl-start CODECOV_EXCLUDE_START --excl-stop CODECOV_EXCLUDE_STOP +echo "Coverage html report generated in $(realpath "$SCRIPTPATH"/../target/debug/html)"