diff --git a/CHANGELOG.md b/CHANGELOG.md index 9484e67d..5c9a3560 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)) diff --git a/src/main.rs b/src/main.rs index 5bf74bb6..191d0e7a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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"); } @@ -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"); }