haskell / haskell/cabal

C source files are not recompiled when headers change

Open
#4,306 3 comments 0 reactions 0 assignees View on GitHub
Cabal: cmd/build recompilation
Dominant language
Haskell
Stars
1.7k
Forks
750
Avg merge
4d 3h
Merged PRs (30d)
28

Description

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: https://github.com/haskell/cabal/issues/24 and https://github.com/haskell/cabal/issues/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?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.