Skip to content

Commit 665a897

Browse files
committed
Fix cargo kcov crashing/generating incorrect reports for proc-macros
Signed-off-by: Patrick Roy <[email protected]>
1 parent 87e0613 commit 665a897

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

tests/integration_tests/build/test_coverage.py

+7
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@ def test_coverage(test_fc_session_root_path, test_session_tmp_path):
8181
exclude_region = "'mod tests {'"
8282
target = "{}-unknown-linux-musl".format(platform.machine())
8383

84+
# Temporarily modify PATH so that "rustc" resolved to our wrapper script
85+
# This is required as cargo kcov parses cargo's verbose output, and looking for lines starting with "Running `rustc":
86+
# https://github.com/kennytm/cargo-kcov/blob/7a6bd499a1f9d4719a20cc9a37b6600fa1c9f68a/src/target_finder.rs#L44
87+
# However, if we use the RUSTC_WRAPPER environment variable to make cargo run out script, the output will
88+
# contain the lines "Running /firecracker/tests/rustc", and thus cargo kcov will fail to resolve the paths of the
89+
# binaries compiled.
90+
os.environ["PATH"] = "/firecracker/tests" + os.pathsep + os.environ["PATH"]
8491
cmd = (
8592
'CARGO_WRAPPER="kcov" RUSTFLAGS="{}" CARGO_TARGET_DIR={} '
8693
"cargo kcov --all "

tests/rustc

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
3+
# We have to fully qualify the path to rustc here, as we modified $PATH in a way that this script is founds before
4+
# the actual rust executable.
5+
# Then we invoke normal rustc, but force the 'link-dead-code' codegen option. This option is required for gathering
6+
# coverage reports on proc-macros during cross-compilation, as the 'RUSTFLAGS' environment variable is ignored by cargo
7+
# for build-scripts, plugins and proc-macros in this case.
8+
# See also https://doc.rust-lang.org/cargo/reference/config.html#buildrustflags
9+
/usr/local/rust/bin/rustc $@ -Clink-dead-code

0 commit comments

Comments
 (0)