Changes in foreign code used in TH do not trigger recompilation
Failing example:
// f.c
#include <stdio.h>
int f(int x) {
printf("calling f(%d)\n",x);
return x + 1;
}
-- A.hs
{-# LANGUAGE ForeignFunctionInterface #-}
{-# LANGUAGE TemplateHaskell #-}
module A where
import Language.Haskell.TH.Syntax
foreign import ccall f :: Int -> IO Int
do addCStub "#include \"f.c\""
addDependentFile "f.c"
return []
-- B.hs
{-# LANGUAGE ForeignFunctionInterface #-}
{-# LANGUAGE TemplateHaskell #-}
module Main where
import Language.Haskell.TH.Syntax
import A
do i <- runIO $ f 0
[d| fh = i |]
main :: IO ()
main = print fh
$ ghc --make B.hs
[1 of 2] Compiling A ( A.hs, A.o )
[2 of 2] Compiling Main ( B.hs, B.o )
calling f(0)
Linking B ...
$ ./B
1
Edit f.c
:
// f.c
#include <stdio.h>
int f(int x) {
printf("calling f(%d)\n",x);
- return x + 1;
+ return x + 2;
}
Recompiling we can see that B.hs
is not rebuilt and executing the program still shows the old result.
$ ghc --make B.hs
[1 of 2] Compiling A ( A.hs, A.o ) [f.c changed]
Linking B ...
$ ./B
1