How to get build / set stack to include resource files (configs, images, etc.)
After putting the stack as a step to start writing non-trivial haskell programs (more than one file), I ran into the problem of not knowing how to get the stack to recognize .ini files, etc. It doesn't seem to fit in the .cabal or stack.yaml files anywhere.
To clarify: after starting the build / installing the stack, the folder with the generated .exe file has no resources, and therefore, of course, the program crashes with a bunch of I / O errors (file not found).
+3
source to share
1 answer
There are two options. I assume you are looking for data files . To do this, you essentially:
- Add the appropriate files to the box
data-files
in the file.cabal
so they are installed when the package is created - Add the module
Paths_package_name
to yoursother-modules
in your.cabal
file (replacepackage_name
with your package name) - Import the module
Paths_*
if needed - Use the generated function
getDataFileName :: FilePath -> IO FilePath
to get the absolute path to the data file you want.
An alternative is to embed the content of the data file inside the executable itself using Template Haskell, for example with the file-embed package .
+4
source to share