-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix cargo kcov crashing/generating incorrect reports for proc-macros #3207
Conversation
# However, if we use the RUSTC_WRAPPER environment variable to make cargo run out script, the output will | ||
# contain the lines "Running /firecracker/tests/rustc", and thus cargo kcov will fail to resolve the paths of the | ||
# binaries compiled. | ||
os.environ["PATH"] = "/firecracker/tests" + os.pathsep + os.environ["PATH"] | ||
cmd = ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you try using CARGO_TARGET_x86_64_unknown_linux_musl_RUSTFLAGS=-Clink-dead-code
as an alternative?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, those flags only affect the code that is actually compiled to run on the specified target, and thus also excludes proc macros and build scripts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually it should be CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_RUSTFLAGS=-Clink-dead-code
(uppercased), but if it's not going to apply by design then probably not worth trying again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did try both! (if you use the lowercase option then cargo will tell you to use the uppercase one instead)
Signed-off-by: Patrick Roy <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it is quite hacky. Were you not able to find another way to pass the correct combination of flags?
In any case, it is always nice to have a meaningful commit body, describing the problem and the solution
Sadly no, the only way to set codegen options is either to use (one of the variations of) 'RUSTFLAGS' (which cargo ignores for proc-macro crates if a target is set (either via |
Do we have to define |
We can specify a no target, in which case everything would work out-of-the-box. We'd be collecting the coverage results for |
Sure, but I guess that's not an issue for us, right? We run the same code, regardless if we target gnu or musl libc. |
I honestly don't know if it's an issue. In the last meeting it was said that we'd prefer to run the coverage on musl. @mattschlebusch do you have any insight on this? |
I think that was because the binaries we publish in releases are musl-built, but indeed the coverage we care about is run strictly on firecracker code irrespective or architecture. |
I will defer to those with more code coverage tooling experience. The wildcard for me here is that generated code like macros built by proc_macro2 could be different depending on the build target. But I don't believe this should ever be true. In which case using the *-gnu target should be logically sufficient albeit a bit less legible. |
What we could do is collect code coverage for all non-proc-macro crates on This would require some minor changes to the test script (instead of invoking |
Closing as we switched to grcov in #3173 |
Signed-off-by: Patrick Roy [email protected]
Changes
Introduces a hack that forces every invocation of
rustc
from within thetests/test_coverage.py
integration test to include the-Clink-dead-code
option, which is required for gathering meaningful coverage reportsReason
When cross-compiling,
cargo
does not pass the value of theRUSTFLAGS
environment variable torustc
invocations for build scripts, proc-macros and plugins: https://doc.rust-lang.org/cargo/reference/config.html#buildrustflags. The second case here is a problem, as we will (most likely) start introducing procedural macros into our workspace via upcoming PRs. On these PRs, the CI has been either crashing (due to a bug in rustc relating to incorrect debug information being generated for proc-macro crates compiled without-Clink-dead-code
option), or generating incorrect coverage reports (since due to the way proc-macro crates are built, uncovered code gets eliminated during linking, meaning it will not show up as "uncovered" in the resulting report (this is kcov specific behavior)).Alternatives considered
--target
flag in relation toRUSTFLAGS
by passing the--target
option viaRUSTFLAGS
. This generally works, but causes problems inseccompiler-bin
License Acceptance
By submitting this pull request, I confirm that my contribution is made under
the terms of the Apache 2.0 license.
PR Checklist
git commit -s
).unsafe
code is documented.CHANGELOG.md
.rust-vmm
.