LTO can cause dependencies to rebuild between build and test #8762
Labels
A-lto
Area: link-time optimization
A-rebuild-detection
Area: rebuild detection and fingerprinting
S-triage
Status: This issue is waiting on initial triage.
If you have
lto
enabled in the profile, thencargo build
followed bycargo test
can result in all dependencies being rebuilt. This is probably not what people want or expect.The exact scenario depends on the structure of the project and the flags used, but for the above example:
build
builds dependencies with bitcode, because that's all LTO needs.test
builds only with object code, because tests need that to link, but there isn't anything that actually needs LTO.A similar scenario, if you have a
main.rs
in the project, it is slightly different:build
builds dependencies with bitcode, because that's all LTO needs.test
builds dependencies with both bitcode and object code, because the tests need object code, and the binary needs bitcode for LTO.The user can fix this by adding
lto
to the test or bench profile (depending on whether you use the--release
flag). Alternatively, one can just not assume thattest --release
will share artifacts. I guess another option would be to give the user the ability to disable the bitcode-only optimization.This particular scenario will be fixed by named-profiles, because the test/bench profiles implicitly inherit the dev/release profile settings. Of course, that means tests will then be LTO'd, which can be quite expensive.
I think it should be fine to wait for named-profiles to be stabilized to resolve this issue. However, I wanted to file it to track the concern. I also think it might warrant having a higher priority for moving named-profiles forward.
A real-world example of this is rustup's CI setup.
The text was updated successfully, but these errors were encountered: