Skip to content

Commit

Permalink
Merge #167
Browse files Browse the repository at this point in the history
167: fix: add `--coverage-target-only`, to use rustflags only for target r=taiki-e a=haraldh

Use `CARGO_TARGET_{target}_RUSTFLAGS` rather than `RUSTFLAGS`,
if `--target <TRIPLE>` and `--coverage-target-only` is specified.

This is important, if the project uses multiple targets via the cargo
`bindeps` feature, and not all targets can use `instrument-coverage`,
e.g. a microkernel, or an embedded binary.

Signed-off-by: Harald Hoyer <harald@profian.com>

Co-authored-by: Harald Hoyer <harald@profian.com>
  • Loading branch information
bors[bot] and haraldh committed May 21, 2022
2 parents 8d08ce2 + 09a502a commit 6db3a02
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 1 deletion.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,13 @@ OPTIONS:
When this option is used, coverage for proc-macro and build script will not be displayed
because cargo does not pass RUSTFLAGS to them.

--coverage-target-only
Activate coverage reporting only for the target triple

Activate coverage reporting only for the target triple specified via `--target`. This is
important, if the project uses multiple targets via the cargo bindeps feature, and not
all targets can use `instrument-coverage`, e.g. a microkernel, or an embedded binary.

-v, --verbose
Use verbose output

Expand Down
8 changes: 8 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,14 @@ pub(crate) struct BuildOptions {
/// not be displayed because cargo does not pass RUSTFLAGS to them.
#[clap(long, value_name = "TRIPLE")]
pub(crate) target: Option<String>,
/// Activate coverage reporting only for the target triple
///
/// Activate coverage reporting only for the target triple specified via `--target`.
/// This is important, if the project uses multiple targets via the cargo
/// bindeps feature, and not all targets can use `instrument-coverage`,
/// e.g. a microkernel, or an embedded binary.
#[clap(long, requires = "target")]
pub(crate) coverage_target_only: bool,
// TODO: Currently, we are using a subdirectory of the target directory as
// the actual target directory. What effect should this option have
// on its behavior?
Expand Down
9 changes: 8 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,14 @@ fn set_env(cx: &Context, target: &mut impl EnvTarget) {
}
}

target.set("RUSTFLAGS", rustflags);
match (cx.build.coverage_target_only, &cx.build.target) {
(true, Some(coverage_target)) => target.set(
&format!("CARGO_TARGET_{}_RUSTFLAGS", coverage_target.to_uppercase().replace('-', "_")),
rustflags,
),
_ => target.set("RUSTFLAGS", rustflags),
}

if let Some(rustdocflags) = rustdocflags {
target.set("RUSTDOCFLAGS", rustdocflags);
}
Expand Down
7 changes: 7 additions & 0 deletions tests/long-help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,13 @@ OPTIONS:
When this option is used, coverage for proc-macro and build script will not be displayed
because cargo does not pass RUSTFLAGS to them.

--coverage-target-only
Activate coverage reporting only for the target triple

Activate coverage reporting only for the target triple specified via `--target`. This is
important, if the project uses multiple targets via the cargo bindeps feature, and not
all targets can use `instrument-coverage`, e.g. a microkernel, or an embedded binary.

-v, --verbose
Use verbose output

Expand Down
3 changes: 3 additions & 0 deletions tests/short-help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ OPTIONS:
--target <TRIPLE>
Build for the target triple

--coverage-target-only
Activate coverage reporting only for the target triple

-v, --verbose
Use verbose output

Expand Down

0 comments on commit 6db3a02

Please sign in to comment.