Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lto = true causes dependency rebuilds when alternating cargo build and cargo build --tests #8669

Closed
jonas-schievink opened this issue Sep 1, 2020 · 3 comments · Fixed by #8755
Labels
A-lto Area: link-time optimization A-rebuild-detection Area: rebuild detection and fingerprinting C-bug Category: bug

Comments

@jonas-schievink
Copy link
Contributor

Problem

When setting lto = true in the dev profile, Cargo will rebuild all dependencies when switching between cargo build to cargo build --tests (and vice-versa).

Steps

  1. Check out https://github.com/jonas-schievink/cargo-lto-bug
  2. Run cargo build
  3. Run cargo build --tests
  4. Observe that Cargo rebuild the bitflags dependency

Notes

Output of cargo version: cargo 1.46.0 (149022b1d 2020-07-17)

Also happens on the current nightly, which is cargo 1.47.0-nightly (51b66125b 2020-08-19)

@ehuss
Copy link
Contributor

ehuss commented Sep 1, 2020

Thanks for creating the repro! I did note that this would happen at #8192 (comment), though at the time I was unsure why someone would do that. Is there a particular reason you would run cargo build in an rlib-only project?

One workaround is to also set LTO in [profile.test]. I'm uncertain why you would set LTO in an rlib-only project, though, since it doesn't perform linking.

Another option is that Cargo could include the LTO status in the metadata hash. @alexcrichton, was there a specific reason to only put it in the fingerprint?

@ehuss ehuss added A-lto Area: link-time optimization A-rebuild-detection Area: rebuild detection and fingerprinting labels Sep 1, 2020
@jonas-schievink
Copy link
Contributor Author

Hmm, this was reduced from https://github.com/knurling-rs/app-template, where I noticed that this would happen when trying to run the tests in testsuite. There, the main package is an rlib, but has optional binaries, so enabling LTO makes sense (as it reduces binary size, and this is a template for embedded projects). I'm not sure which commands you need exactly to reproduce this in the full setting though.

@alexcrichton
Copy link
Member

This seems fine to me to inclue the lto setting into the metadata, and seems reasonable to avoid thrashing in a case like this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lto Area: link-time optimization A-rebuild-detection Area: rebuild detection and fingerprinting C-bug Category: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants