Closed smoelius closed 6 months ago
TR; DR: The workaround is using --coverage-target-only
flag.
Is it possible
cargo-llvm-cov
doesn't yet supporttarget.'cfg(all())'.rustflags
?
No. cfg(all()) is evaluated to true correctly https://github.com/taiki-e/cargo-config2/blob/e64df187d824d2dbca3afcfc256ae370d224e2d6/src/cfg_expr/tests/eval.rs#L32.
The problem is that the config (that sets linker=dylint-link
) is not the config of the workspace or package being compiled by cargo-llvm-cov, but a local config of a crate compiled by internally invoked (by test) commands. This is not taken into account where cargo-llvm-cov is invoked; cargo-llvm-cov passes rustflags as an environment variable (RUSTFLAGS
by default) rather than config so that internally invoked commands can also participate in coverage, but because RUSTFLAGS
environment variable take precedence over config files, internally invoked commands will ignore their local config will be ignored.
The workaround here is to have the cargo-llvm-cov set the TARGET_*_RUSTFLAGS
instead of RUSTFLAGS
to be merged with target.'cfg(,..)'.rustflags
, which can be done by passing the --coverage-target-only
flag (https://github.com/taiki-e/cargo-llvm-cov/pull/167).
Ideally, I would like Cargo to support merging of rustflags by environment variables (https://github.com/rust-lang/cargo/issues/5376)...
Thanks for the detailed explanation, @taiki-e. Your solution worked perfectly.
I have a test that involves the following
.cargo/config.toml
file:The test works fine when run under
cargo test
, but fails when run undercargo-llvm-cov
.On the other hand, if you comment out the
rustflags...
line in the above, and uncomment the the# linker...
line, the test works undercargo-llvm-cov
.Is it possible
cargo-llvm-cov
doesn't yet supporttarget.'cfg(all())'.rustflags
?The following commands should reproduce the issue: