-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
cargo build does not rebuild if a source file was modified during a build #2426
Comments
As an example with the current master of cargo (8fc3fd8):
|
I personally view this as a feature rather than a bug, but it shouldn't be too too hard to fix this. |
Yea I figured this could be a bit philosophical! My personal view is that a build should be a pure function of the build inputs, and that skipping rebuilds is an optimization that is allowed providing it maintains the purity. This is a violation of that. :-) |
(Though the fix to the greater issue would likely require changing from timestamps to hashes to determine if inputs have changed.) |
Right now the mtime we compare against is the This should just be a change to this line |
Anyone working on this? |
I don't believe so, no, feel free to take it! |
@Jimmio92 that sounds distinct from this issue, feel free to open a separate one! |
@alexcrichton The issue I mentioned in the comment has been resolved in the nightly build 20160511. Sorry for the totally unhelpful comment. I was on stable. |
Aha, even better! Glad it worked out :) |
Does the problem exist? Maybe issue should be closed? |
Yes I believe this is still an issue unfortunately |
as this is labeled E-easy, may I ask for some mentor instructions here please? specifically:
|
My understanding is that this essentially requires racing against
Cargo is a stand-alone binary, so just
would work.
|
Oh actually for testing this what I'd recommend is:
|
😨 🤣 |
Sounds ideal but not that E-easy for me ;-) Thank you, I'll share if I make any progress on this. |
Ah yeah sorry this isn't necessarily E-easy any more per se, but if you've got a patch you feel fixes this I don't mind taking care of writing a test! |
I think I disagree on both points :) This behavior comes out in practice in non-esoteric circumstances:
A similar scenario was just reported in the ruRust gitter, with a slight difference that the build is
I might be wrong here, but looks like this won't fix the problem and instead make it worse? So, we have The fundamental problem here is that we know the set of files to fingerprint (the depinfo), only after compilation is finished. So whichever fingerprint we calculate, there won't be a causality edge from it to the compilation, and we'll get a data race. Not even hashes will save us! Action Item: I think a possible solution here is to use "mtime of the compilation process". That is, before we invoke rustc, we touch some file in a target directory and use its modification time, which will be less than I am not sure my solution would always work though. I use touch and not Fundamentally, the problem is that filesystem just can't give us a consistent snapshot of files. It might be interesting to investigate approach which Bazel uses. I am not sure, but I think it copies all sources into the special read-only directory in the equivalent of |
Please note that there's a failed attempt (on my behalf) at fixing this in #5417. In particular I want to point out that it has a test for the desired behaviour, following Alex's guidelines. |
It was me who reported it and I just checked - by default flycheck runs |
Something similar happens with cargo-web. |
Ah good poitns @matklad! I think the solution of touching a file before the build starts should work well. I don't think it's really feasible to do sandboxing/enclaving in Cargo right now, and despite multiple fs issues I suspect that a file in the target directory will be "good enough" to solve the 95% of use cases |
@matklad the fix for this in #6484 made a temporary file and read the mtime of that file. This was done instead of just |
@Eh2406 that was purely a theoretical concern: ideally, we don't rely on times at all and use a logical lamport-style "happens before" relation.
This is not about precision, that is about time skew. Consider two machines, A and B, such that A mounts a folder form B's file system via NFS or something like that. The times on that shared folder may differ from times on other A's files not because of network delay, but because system times on A and B differ (I think in NFS setups local time is written to the filesystem?). I have no idea if a similar scenario works in practice at all. Hm, actually, what happens if you just set the system time (daylight savings, ntpd or manual user intervention)? This won't affect times stored on the disk, right? This seems like a more reasonable scenario to me, though still quite unlikely. |
The fact that the timestamp is not monotonic, is the most convincing argument I have herd for switching to a crypto-hash based system. I can't test it (my admin locked me out of manually setting the clock), but for example I think if you set the clock to the future and do a build, then reset the clock, then change the input file and try to rebuild nothing will happen. (The last build has a larger timestamp then the input file, so no rebuild is needed.) I also can't test (for the same reason) which clock is used when modifying a file on a network drive. Set your clock to the future, add a file to the network drive, does it have a creation time that is accurate (using the hosts clock) or in the future (using your clock). If it uses the hosts clock, and your clock is in the past, then having a target dir on the network drive can leave you in the first scenario. Overall I am convinced that we should move away from relying on the timestamp ware performance allows it. I am not convinced that we solve any of the problems by avoiding |
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as abuse.
This comment was marked as abuse.
@NajeebUllah161 please don't double comment, and don't shout, and avoid sentences that start with "just" they come across as more aggressive then you intended. Also when I was running into these issues my |
This problem is not solved. I read that the problem is because somethin with the timestamp of the file and if the timestamp is always equals it doesn't compile at all. My computer have a problem with the time clock and it always reset after a time pass, so the timestamp of the file is sometimes the same even if it has diferent content and code. |
This comment was marked as abuse.
This comment was marked as abuse.
@otaxhu even if the underlying causes the same, the pattern is different enough to justify a opening a new issue. Cargo does now have mitigations for modifying a file during compilation, so this issue is legitimately closed. Your issue about unreliable clock leading to not rebuilding when needed is legitimate and should be tracked as a new issue. Please open one. |
I haven't checked, but I would guess this is a timestamp issue: the input is modified before the output artifact is created, even though the modified input was not used to build the artifact. This would happen any time after rustc is parsing.
The text was updated successfully, but these errors were encountered: