cc-rs
cc-rs copied to clipboard
Use `rerun-if` features to detect when code needs rebuilding
I've historically avoided this for a few reasons:
- Right now header files aren't tracked
- If
gccisn't the only thing in a build script the messages printed out would be wrong
The first point is a must-have for this feature and the latter is a "maybe this should be opt in" but probably not.
Header dependency tracking is something of a solved problem AIUI - you just need to invoke the compiler with certain flags, so the real challenge there will be getting a portable solution.
It looks easy enough with MSVC: https://docs.microsoft.com/en-gb/cpp/build/reference/showincludes-list-include-files
And GCC has the -H option: https://stackoverflow.com/a/20477307
WRT to the second item - aren't the lines output from the build script interpreted entirely independently by cargo?
Yes my point is that this is not implemented, nor was it mentioned in the issue description. I wanted to outline why this isn't trivial to implement today and what needs to be done to close this issue.
If you use gcc for some parts of a build script but also use other files (e.g. code generation) in other parts of a build script, then gcc printing out the files it uses requires the other parts of the build script to also do so to work correctly. That may or may not be the case today.
Even if I manually add println!("cargo:rerun-if-changed=PATH_TO_C_FILE");, my C files are still getting rebuilt. I wonder why. Is there a way to check what the output of build.rs is?
Yes, the output from the build file is saved to target/<target>/build/<crate_name>/output (note there will be multiple directories with your crate name and a different hash).
After a clean build there should be exactly two directories with your crate name: one of them will contain the binary of the compiled build script, and the other will contain the output file.
So, am I correct in thinking that the cc crate will always build C files regardless of if there was a change?
I'm tracking down a rebuild issue, and I'm not sure if cc is supposed to have dependency tracking or not :P
That is correct, cc does not implement any form of incremental recompliation.
In https://github.com/alexcrichton/cc-rs/pull/443#issuecomment-535144089 you mention
While I don't think we can emit rerun-if-* directives by default, it seems reasonable to have an option to opt-in to rerun-if directives perhaps?
Would this still be a good solution? I may be up for it when I have time, because I just got bit by missing a header.