Skip to content
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: add --coverage-target-only, to use rustflags only for target #167

Merged
merged 1 commit into from
May 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,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 @@ -357,6 +357,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 @@ -274,7 +274,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 @@ -180,6 +180,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 @@ -137,6 +137,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