-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Fix cargo check --lib
not emitting warnings on subsequent runs
#4318
Fix cargo check --lib
not emitting warnings on subsequent runs
#4318
Conversation
`cargo check` for binaries will always emit warnings, even when the files in the project haven't changed. For `cargo check --lib`, warnings were emitted on the first run, but subsequent runs would not trigger a recompilation of the library when no files have changed, hence preventing warnings to appear. This commit forces a recompilation of the library top-level target (*not* library dependencies) when using the `check` command. Closes rust-langGH-3624.
r? @matklad (rust_highfive has picked a reviewer for you, use r? to override) |
As stated in #3624, this seems to fix the issue at the cost of a longer turn around. Running It's up to you whether this tradeoff is worth it. Also, I would very much like a double check on whether the fix as any unintended side-effects, as I am not familiar with cargo internals. |
I certainly sympathize with the problem here, but I am afraid that the real fix unfortunately needs to be much more involved. I think the issue of missing warnings affects not only So ideally we want to record rustc's warnings during dirty compilations and then replay them for fresh ones. That said, perhaps a hack to always rebuild crates specifically for |
@matklad I'm all for making the correct fix, but I will need some guidance on what to target and how to tackle it.
In this situation, would a
That sounds like a definitive solution, yes. That way, we wouldn't even have to recompile fresh binary targets. How exactly would we cache the results? Since it's between runs, we have to save them somewhere. Do we extend the existing At what granularity should we cache these warnings? For each crate (a unit here is associated to a crate, right?)? For each file? |
Sorry for the long reply @fmdkdd !
Denying warnings would help in a sense that code with warnings would just fail to compile. However there's a workflow (which I personally use) when you allow warnings during development, and check before commit that there are no warnings left.
I think we can store new "compiler_output.txt" files, because the info here is not essential, and we should not fail if these files are missing. However, I don't have an idea how these files should look like, especially if we take into account colored output, which, on windows, is achieved via syscalls and not via escape codes.
unit (crate) looks like a right granularity here. Per file storage won't work really well because compiler itself works on the crate level granularity. @alexcrichton do you have any suggestions here? I would love to have this feature, because I want to know that my code is warning free without resorting to |
Ah yeah I think I do agree with your thoughts @matklad in that the "what to fix here" is a bit deeper, especially in the multiple crate workspace scenario. It does seem like the best option here is for Cargo to record the compiler's output and replay it back, but this definitely isn't easily done today. The theory is that with JSON messages Cargo should be able to recreate rustc's output but that's unfortunately not currently the case as it would have to reimplement a significant amount of logic. In the meantime though I'd personally prefer to stick to what future Cargo will continue to do, which is not executing rustc at all on "fresh" crates and simply moving to the next crate. Perhaps though we can push more on the upstream design for json messages to get this implemented? |
Yeah, perhaps we can extract a
|
Can't we just intercept |
Sounds great!
This is plausible, yes, but doesn't work on Windows yeah due to how colors work today. That's the only bug that needs to get fixed to make it work though! (AFAIK) |
I would prefer it to not do that. It needs to honor the |
@ehuss my thinking is that Cargo understands the workflow at a high level, so it'd be able to react and "do the right thing" in that sort of situation. In that if you run |
How would that work? Since those flags cause rustc to be called with different flags, would the cached output need to keep track of which flags were used and re-run rustc if they are different? Or use the |
Heh well we haven't implemented it so I'm not sure! Regardless sounds like a bug to avoid. |
So, the current plan would be for Since Is this functionality something we want to see implemented soon? (As in, should I start working on a proof of concept?) Or are there any other tasks that must be tackled before fixing this becomes a reality? Maybe extracting printing of diagnostics to a |
@fmdkdd that's the basic thinking I believe so, yeah. Unfortunately much of this doesn't exist (e.g. rustc won't tell cargo about colors in "machine readable" mode) so the timeline is probably not in the very near future. Moving to extract a crate though would be a great start! |
I'm going to close this for now due to inactivity, but we can of course reconsider with diagnostics captured and such! |
cargo check
for binaries will always emit warnings, even when the files in theproject haven't changed.
For
cargo check --lib
, warnings were emitted on the first run, but subsequentruns would not trigger a recompilation of the library when no files have
changed, hence preventing warnings to appear.
This commit forces a recompilation of the library top-level target (not
library dependencies) when using the
check
command.Closes GH-3624.