Skip to content

Commit 36866e5

Browse files
bors[bot]taiki-e
andauthored
Merge #101
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 <[email protected]>
2 parents 4ab165f + 849fc36 commit 36866e5

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Note: In this file, do not use the hard wrap in the middle of a sentence for com
1010

1111
## [Unreleased]
1212

13+
- Fix ["conflicting weak extern definition" error](https://github.com/rust-lang/rust/issues/85461) on windows.
14+
1315
## [0.1.10] - 2021-10-24
1416

1517
- Fix a compatibility issue with `cc`. ([#98](https://github.com/taiki-e/cargo-llvm-cov/pull/98))

src/main.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,21 @@ fn set_env(cx: &Context, cmd: &mut ProcessBuilder) {
153153

154154
let rustflags = &mut cx.ws.config.rustflags().unwrap_or_default();
155155
rustflags.push_str(" -Z instrument-coverage");
156+
// --remap-path-prefix is needed because sometimes macros are displayed with absolute path
157+
rustflags.push_str(&format!(" --remap-path-prefix {}/=", cx.ws.metadata.workspace_root));
158+
if cfg!(windows) {
159+
// `-C codegen-units=1` is needed to work around link error on windows
160+
// https://github.com/rust-lang/rust/issues/85461
161+
// https://github.com/microsoft/windows-rs/issues/1006#issuecomment-887789950
162+
rustflags.push_str(" -C codegen-units=1");
163+
}
156164
if !cx.cov.no_cfg_coverage {
157165
rustflags.push_str(" --cfg coverage");
158166
}
159-
// --remap-path-prefix is needed because sometimes macros are displayed with absolute path
160-
rustflags.push_str(&format!(" --remap-path-prefix {}/=", cx.ws.metadata.workspace_root));
161167
if cx.build.target.is_none() {
168+
// https://github.com/dtolnay/trybuild/pull/121
169+
// https://github.com/dtolnay/trybuild/issues/122
170+
// https://github.com/dtolnay/trybuild/pull/123
162171
rustflags.push_str(" --cfg trybuild_no_target");
163172
}
164173

@@ -170,6 +179,9 @@ fn set_env(cx: &Context, cmd: &mut ProcessBuilder) {
170179
" -Z instrument-coverage -Z unstable-options --persist-doctests {}",
171180
cx.ws.doctests_dir
172181
));
182+
if cfg!(windows) {
183+
rustdocflags.push_str(" -C codegen-units=1");
184+
}
173185
if !cx.cov.no_cfg_coverage {
174186
rustdocflags.push_str(" --cfg coverage");
175187
}

0 commit comments

Comments
 (0)