Skip to content

Commit 1583e63

Browse files
committed
Try to add code coverage support for Rust projects
Support for LLVM-based code coverage for Rust was implemented awhile back (and has a [nice blog post][post] with [documentation]), and we ran across this internally today. I'm curious if this change is all that's needed to enable source coverage for Rust builds! I'm not 100% sure how coverage is all set up in oss-fuzz but I figured this might be a good place to get the ball rolling. cc google#3469 [post]: https://blog.rust-lang.org/inside-rust/2020/11/12/source-based-code-coverage.html [documentation]: https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/source-based-code-coverage.html
1 parent e518f6e commit 1583e63

File tree

1 file changed

+5
-6
lines changed
  • infra/base-images/base-builder

1 file changed

+5
-6
lines changed

infra/base-images/base-builder/compile

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,11 @@ fi
8080

8181
# Rust does not support sanitizers and coverage flags via CFLAGS/CXXFLAGS, so
8282
# use RUSTFLAGS.
83-
# FIXME: Support code coverage once support is in.
84-
# See https://github.com/rust-lang/rust/issues/34701.
85-
if [ "$SANITIZER" != "undefined" ] && [ "$SANITIZER" != "coverage" ] && [ "$ARCHITECTURE" != 'i386' ]; then
86-
export RUSTFLAGS="--cfg fuzzing -Zsanitizer=${SANITIZER} -Cdebuginfo=1 -Cforce-frame-pointers"
87-
else
88-
export RUSTFLAGS="--cfg fuzzing -Cdebuginfo=1 -Cforce-frame-pointers"
83+
export RUSTFLAGS="--cfg fuzzing -Cdebuginfo=1 -Cforce-frame-pointers"
84+
if [ "$SANITIZER" = "coverage" ]; then
85+
export RUSTFLAGS="${RUSTFLAGS} -Zinstrument-coverage"
86+
elif [ "$SANITIZER" != "undefined" ] && [ "$ARCHITECTURE" != 'i386' ]; then
87+
export RUSTFLAGS="${RUSTFLAGS} -Zsanitizer=${SANITIZER}"
8988
fi
9089

9190
# Add Rust libfuzzer flags.

0 commit comments

Comments
 (0)