tarpaulin: Compile error: linking with `cc` failed
Info
running tarpaulin in a docker for gitlab-ci
Error
I get the following error on step cargo +nightly tarpaulin --all-features
error: build failed
[ERROR tarpaulin] Failed to compile tests! Error: linking with `cc` failed: exit code: 1
Error: "Failed to compile tests! Error: linking with `cc` failed: exit code: 1"
About this issue
- Original URL
- State: open
- Created 4 years ago
- Comments: 21 (4 by maintainers)
Commits related to this issue
- ISSUE-16 - Remove cargo core usage: * Remove cargo core usage from scan module * Remove cargo core usage from traversal module * Remove cargo core usage from format module * Remove cargo core usage fr... — committed to jmcconnell26/cargo-geiger by jmcconnell26 4 years ago
- fix: Downgrade cargo-tarpaulin as a workaround It's a workaround for https://github.com/xd009642/tarpaulin/issues/517 — committed to devzbysiu/transition by devzbysiu 4 years ago
- ci: remove codecov due to https://github.com/xd009642/tarpaulin/issues/517 — committed to haqq-network/haqq-clients by onsails 7 months ago
Okay took me quite a few hours fixing and testing everything, but I fixed it. Let me explain thing for other people that have similar issues. For initial problems I had see: https://github.com/xd009642/tarpaulin/issues/517#issuecomment-874089885 But I’ll summarize below as well.
After checking the issue out again I stumbled on this problem again:
Note that before testing I upgraded to
cargo-tarpaulin v0.18.2
My CI got stuck while compiling/linking (at end of compiling) but returned no errors. Locally it seemed to work just fine.
After testing I found out that the CI docker container was running out of RAM. This is the reason the compiler (mainly the linker) got stuck. Because when compiling a lot of test modules in parallel it starts multiple linking jobs. Each linking job was using about 2 GB or memory (don’t know why, but it did, this was with GNU
ld
). So 2 GB*8 = 16GB, this was to much for the CI. I switched to thelld
(LLVM linker) to see if this fixed the issue, it did change some thing and I fixed some issues with this in the past.To switch to
lld
I used:.cargo/config.toml
:Add this file to the root of your project. So:
This might solve or create new problems. But could be a way out if you are stuck.
Switching back to
ld
linker did solve theBroken pipe (os error 32)
withcc
in this case (I know this did not solve issue in the past, but it did now). I also started the coverage test in a machine with more RAM and after some other fixes I got it working again. 🎉In my case, my lib referencing an external library, while
cargo build
succeeds,cargo tarpaulin
fails.My lib.rs:
Running command
rustc --crate-name adc ...
reports error:Summary for solving this (and maybe other) issues: These fixes can be used independently. (are in rough order of how best to check)
cargo clean
https://github.com/xd009642/tarpaulin/issues/517#issuecomment-681194362cargo install cargo-tarpaulin
to auto update orcargo install cargo-tarpaulin --version 0.18.0-alpha3
to force a particular version.stable
ornightly
toolchain when possiblecargo +nightly tarpaulin
--verbose
flag set ( fixed in #787)--jobs 2
flag (pick a number less then amount of CPU cores/virtual threads the machine has)ld
(GNU, default) orlld
(LLVM, see this )grcov
a try, this might surface errors that might fix Tarpaulin too. (see below for more info)grcov test
If all else fails you might be able to find out the problem by trying an other coverage tool. When running
grcov
it might detect things that will solve problems for Tarpaulin too.Here are some of the settings I used in order to test things.
Little shout-out to @xd009642 his appearance in Rustacean Station Podcast episode 037. 😃 Check it out if you want to know more about Tarpaulin and its future. Looking forward to LLVM update. 😉
Hmm, interesting. This might be my problem too, but have to test. I got the problem after adding more tests, but might have enabled a feature or something that needed an other lib. This might also explain why it works in my PC but not in CI pipeline.
Thanks for sharing! Will have a look and see if that fixes it.
For a number of people hopefully once this is closed (cargo PR done by alex) and the next cargo is released this issue should go away https://github.com/rust-lang/cargo/issues/9220