Fix freshness when linking is interrupted. #8078
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Cargo was incorrectly determining a build is fresh in the following scenario.
cargo build
cargo build
.cargo run
— Cargo will think it is "fresh" because the output file exists, but will attempt to run a corrupt file.The solution here is to delete the fingerprint when something is determined to be dirty. There are a variety of other possible approaches, but this seemed the simplest.
I was only able to reproduce this with gcc on Linux.
I couldn't think of a good way to write a test for this. I did test this a bit locally, by using the repro steps above. I also did some tests with a custom linker that wrote out an empty file and then went to sleep so I could kill Cargo. I was reluctant to include a test using that technique because it needs to parse the linker command-line flags to find the output filename, and I'm not sure how stable/reliable that would be with different platforms and linker flavors. It is also a bit cumbersome to signal when linking has started.
Fixes #7767