1

To embed some static files in a build, I'm using: https://hackage.haskell.org/package/file-embed-0.0.10.1/docs/Data-FileEmbed.html

It allows you to do:

MyFile.hs

myFile :: Data.ByteString.ByteString
myFile = $(embedFile "something/external.txt")

To embed files into the produced binary.

However, one irksome thing is that cabal doesn't know that a file using embedFile depends on the file it loads (and therefore changes to something/external.txt don't cause MyFile to be re-built on build).

Is there any way to tell cabal about this dependency? The only solution I have now is to just touch the Haskell file to cause it to be recompiled, but this is tedious.

Bailey Parker
  • 15,599
  • 5
  • 53
  • 91

1 Answers1

2

addDependentFile is part of template Haskell. It tells ghc to use that file in dependency calculations - cabal isn't even needed.

embedFile should be calling that. The fact that it isn't makes me suspicious about the library. Still, you can create a helper that looks something like this:

embed :: FilePath -> Q Exp
embed p = addDependentFile p >> embedFile p

Just mind TH's staging restrictions, and put that in a file that doesn't use it.

Carl
  • 26,500
  • 4
  • 65
  • 86