Skip to content

Commit 7a93d3e

Browse files
authored
fix: code coverage ci task (#8142)
The installed LLVM tools reside under ``` RUST_SYSROOT="$(rustc --print sysroot)" RUST_HOST="$(rustc --print host-tuple)" LLVM_TOOLS_BIN="${RUST_SYSROOT}/lib/rustlib/${RUST_HOST}/bin" ``` which is different from what we previously expected. Further, splitting up the commands like ``` RUST_SYSROOT="$(rustc +$NIGHTLY_TOOLCHAIN --print sysroot)" RUST_HOST="$(rustc +$NIGHTLY_TOOLCHAIN --print host-tuple)" LLVM_TOOLS_BIN="${RUST_SYSROOT}/lib/rustlib/${RUST_HOST}/bin" ``` leads to non-zero exit code in case any of them fail. This is unlike the previous setup where only the outermost command `dirname` was checked for its exit code which is 0, even if `""` is passed as an argument. Signed-off-by: Alexander Droste <alexander.droste@protonmail.com>
1 parent 7a228aa commit 7a93d3e

2 files changed

Lines changed: 30 additions & 8 deletions

File tree

.github/workflows/fuzz-coverage.yml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,14 @@ jobs:
4040
rustup component add llvm-tools-preview --toolchain $NIGHTLY_TOOLCHAIN
4141
4242
# Verify llvm-profdata is accessible (cargo-fuzz needs it for coverage merging)
43-
LLVM_PROFDATA="$(rustc +$NIGHTLY_TOOLCHAIN --print sysroot)/lib/rustlib/$(rustc +$NIGHTLY_TOOLCHAIN -vV | sed -n 's|host: ||p')/bin/llvm-profdata"
43+
RUST_SYSROOT="$(rustc +$NIGHTLY_TOOLCHAIN --print sysroot)"
44+
RUST_HOST="$(rustc +$NIGHTLY_TOOLCHAIN --print host-tuple)"
45+
LLVM_TOOLS_BIN="${RUST_SYSROOT}/lib/rustlib/${RUST_HOST}/bin"
46+
LLVM_PROFDATA="${LLVM_TOOLS_BIN}/llvm-profdata"
4447
if [ ! -f "$LLVM_PROFDATA" ]; then
4548
echo "ERROR: llvm-profdata not found at $LLVM_PROFDATA"
4649
echo "Listing bin directory:"
47-
ls -la "$(dirname "$LLVM_PROFDATA")" || echo "Directory does not exist"
50+
ls -la "$LLVM_TOOLS_BIN" || echo "Directory does not exist"
4851
exit 1
4952
fi
5053
echo "Found llvm-profdata at $LLVM_PROFDATA"
@@ -84,13 +87,13 @@ jobs:
8487
COVERAGE_DIR="fuzz/coverage/${{ matrix.fuzz_target }}"
8588
8689
# llvm tools are installed via rustup's llvm-tools component
87-
LLVM_TOOLS_BIN="$(rustc +$NIGHTLY_TOOLCHAIN --print sysroot)/lib/rustlib/$(rustc +$NIGHTLY_TOOLCHAIN -vV | sed -n 's|host: ||p')/bin"
88-
89-
TARGET_TRIPLE=$(rustc +$NIGHTLY_TOOLCHAIN -vV | sed -n 's|host: ||p')
90+
RUST_SYSROOT="$(rustc +$NIGHTLY_TOOLCHAIN --print sysroot)"
91+
RUST_HOST="$(rustc +$NIGHTLY_TOOLCHAIN --print host-tuple)"
92+
LLVM_TOOLS_BIN="${RUST_SYSROOT}/lib/rustlib/${RUST_HOST}/bin"
9093
9194
# cargo-fuzz coverage places the binary at:
9295
# target/<triple>/coverage/<triple>/release/<fuzz_target>
93-
FUZZ_BIN="target/${TARGET_TRIPLE}/coverage/${TARGET_TRIPLE}/release/${{ matrix.fuzz_target }}"
96+
FUZZ_BIN="target/${RUST_HOST}/coverage/${RUST_HOST}/release/${{ matrix.fuzz_target }}"
9497
9598
if [ ! -f "$FUZZ_BIN" ]; then
9699
echo "ERROR: Could not find fuzz binary at $FUZZ_BIN"

.github/workflows/rust-instrumented.yml

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,33 @@ jobs:
4747
sccache: s3
4848
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
4949
- uses: ./.github/actions/setup-prebuild
50+
- name: Ensure llvm-tools are installed
51+
run: |
52+
rustup component add llvm-tools || \
53+
rustup component add llvm-tools-preview
54+
55+
# Verify llvm-profdata is accessible (grcov needs it for coverage merging)
56+
RUST_SYSROOT="$(rustc --print sysroot)"
57+
RUST_HOST="$(rustc --print host-tuple)"
58+
LLVM_TOOLS_BIN="${RUST_SYSROOT}/lib/rustlib/${RUST_HOST}/bin"
59+
LLVM_PROFDATA="${LLVM_TOOLS_BIN}/llvm-profdata"
60+
if [ ! -f "$LLVM_PROFDATA" ]; then
61+
echo "ERROR: llvm-profdata not found at $LLVM_PROFDATA"
62+
echo "Listing bin directory:"
63+
ls -la "$LLVM_TOOLS_BIN" || echo "Directory does not exist"
64+
exit 1
65+
fi
66+
echo "Found llvm-profdata at $LLVM_PROFDATA"
67+
5068
- name: Rust Tests
5169
if: ${{ matrix.suite == 'tests' }}
5270
run: |
5371
cargo nextest run --locked --workspace --all-features --no-fail-fast
5472
- name: Generate coverage report
5573
run: |
56-
set -euo pipefail
57-
LLVM_TOOLS_BIN="$(dirname "$(rustup which llvm-profdata)")"
74+
RUST_SYSROOT="$(rustc --print sysroot)"
75+
RUST_HOST="$(rustc --print host-tuple)"
76+
LLVM_TOOLS_BIN="${RUST_SYSROOT}/lib/rustlib/${RUST_HOST}/bin"
5877
grcov . --binary-path target/debug/ -s . -t lcov --llvm --ignore-not-existing \
5978
--llvm-path "${LLVM_TOOLS_BIN}" \
6079
--threads $(nproc) \

0 commit comments

Comments
 (0)