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

C source files are not recompiled when headers change #4306

Open
amosr opened this issue Feb 8, 2017 · 3 comments
Open

C source files are not recompiled when headers change #4306

amosr opened this issue Feb 8, 2017 · 3 comments

Comments

@amosr
Copy link

amosr commented Feb 8, 2017

For projects with C source files and headers, the check whether it needs to recompile is naive and only looks at whether the source file has changed.
So if you have two files foo.h and foo.c, touching foo.h should cause foo.c to be recompiled.

The same problem exists for .hsc files: #24 and #3087.

One idea for implementing this is to change the checkNeedsRecompilation function (https://github.com/haskell/cabal/blob/master/Cabal/Distribution/Simple/GHC.hs#L1327) to call out to gcc -M, which generates a makefile rule listing the dependencies for that particular file.
We'd need to call gcc -M with the C flags (the include dirs), parse the makefile rule, then go through all those files and see if any are newer than the object.
Does that sound too slow to do every time? Is there an easy way to cache this?

@ezyang
Copy link
Contributor

ezyang commented Feb 8, 2017

Although this seems similar to the problem for hsc files, I actually think these are not related; checkNeedsRecompilation is only called for building C sources (I don't see any call sites), so #3087 must a different bug somewhere else.

#4174 would probably help us implement more accurate recomp avoidance. Barring that, it is probably true that the only way we can figure out whether or not we need to recompile is by getting the makefile rule and testing to see if things are newer.

@amosr
Copy link
Author

amosr commented Feb 8, 2017

Yeah - I suspect to fix the hsc files, you would want to do something similar: call hsc2hs to generate the C file and then run gcc -M on it.

Shake sounds like a much nicer long-term solution

@ezyang
Copy link
Contributor

ezyang commented Mar 7, 2017

Admittedly, it would be less horrible for Cabal to have a bad recompilation checker if there were an easy way to force recompilation. So that might be a short term fix which would be easier to develop a patch for.

As for gcc -M, honestly, I don't think it would take that long, esp. since I don't think people are shoving extremely large piles of C files into the Cabal build system. So, I would take a patch that taught build how to handle this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants