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

Use rerun-if features to detect when code needs rebuilding #230

Closed
Diggsey opened this issue Aug 9, 2017 · 8 comments · Fixed by #701
Closed

Use rerun-if features to detect when code needs rebuilding #230

Diggsey opened this issue Aug 9, 2017 · 8 comments · Fixed by #701

Comments

@Diggsey
Copy link

Diggsey commented Aug 9, 2017

No description provided.

@alexcrichton
Copy link
Member

I've historically avoided this for a few reasons:

  • Right now header files aren't tracked
  • If gcc isn'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.

@Diggsey
Copy link
Author

Diggsey commented Aug 10, 2017

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?

@alexcrichton
Copy link
Member

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.

@marco-c
Copy link

marco-c commented May 28, 2018

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?

@Diggsey
Copy link
Author

Diggsey commented May 28, 2018

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.

@vext01
Copy link

vext01 commented Jul 15, 2020

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

@alexcrichton
Copy link
Member

That is correct, cc does not implement any form of incremental recompliation.

@alexeyr
Copy link
Contributor

alexeyr commented Nov 18, 2020

In #443 (comment) 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.

EvanTheB pushed a commit to EvanTheB/cc-rs that referenced this issue Jul 27, 2022
Issue rust-lang#230 is the issue for this, this patch just documents the
current behaviour.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants