Skip to content

Commit

Permalink
Merge #101
Browse files Browse the repository at this point in the history
101: Force 1 codegen unit on windows r=taiki-e a=taiki-e

Workaround for rust-lang/rust#85461
See also microsoft/windows-rs#1006 (comment)

Co-authored-by: Taiki Endo <te316e89@gmail.com>
  • Loading branch information
bors[bot] and taiki-e authored Nov 13, 2021
2 parents 4ab165f + 849fc36 commit 36866e5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Note: In this file, do not use the hard wrap in the middle of a sentence for com

## [Unreleased]

- Fix ["conflicting weak extern definition" error](https://github.com/rust-lang/rust/issues/85461) on windows.

## [0.1.10] - 2021-10-24

- Fix a compatibility issue with `cc`. ([#98](https://github.com/taiki-e/cargo-llvm-cov/pull/98))
Expand Down
16 changes: 14 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,21 @@ fn set_env(cx: &Context, cmd: &mut ProcessBuilder) {

let rustflags = &mut cx.ws.config.rustflags().unwrap_or_default();
rustflags.push_str(" -Z instrument-coverage");
// --remap-path-prefix is needed because sometimes macros are displayed with absolute path
rustflags.push_str(&format!(" --remap-path-prefix {}/=", cx.ws.metadata.workspace_root));
if cfg!(windows) {
// `-C codegen-units=1` is needed to work around link error on windows
// https://github.com/rust-lang/rust/issues/85461
// https://github.com/microsoft/windows-rs/issues/1006#issuecomment-887789950
rustflags.push_str(" -C codegen-units=1");
}
if !cx.cov.no_cfg_coverage {
rustflags.push_str(" --cfg coverage");
}
// --remap-path-prefix is needed because sometimes macros are displayed with absolute path
rustflags.push_str(&format!(" --remap-path-prefix {}/=", cx.ws.metadata.workspace_root));
if cx.build.target.is_none() {
// https://github.com/dtolnay/trybuild/pull/121
// https://github.com/dtolnay/trybuild/issues/122
// https://github.com/dtolnay/trybuild/pull/123
rustflags.push_str(" --cfg trybuild_no_target");
}

Expand All @@ -170,6 +179,9 @@ fn set_env(cx: &Context, cmd: &mut ProcessBuilder) {
" -Z instrument-coverage -Z unstable-options --persist-doctests {}",
cx.ws.doctests_dir
));
if cfg!(windows) {
rustdocflags.push_str(" -C codegen-units=1");
}
if !cx.cov.no_cfg_coverage {
rustdocflags.push_str(" --cfg coverage");
}
Expand Down

0 comments on commit 36866e5

Please sign in to comment.