Search code examples
haskellcabal

with-compiler and extra-lib-dirs in cabal for ALL developers


I have a typical stack project layout and I am transitioning to a cabal. The problem is that I should reference extra libraries and installed GHC compiler. My current solution is:

-- cabal.project file:
...
extra-lib-dirs: libs/mylib   -- libs/ is in the project root, where is the cabal file

and

-- cabal.project.local file:
with-compiler: /the/path/to/ghc/exe

The second setting works (compiler's location), but it has a problem: it is an absolute path relevant for A) my computer, B) my OS. But how to do it for all users of the project (they use other OSes and have other locations for GHC)?

Another problem is that relative extra-library-dirs worked for stack, but it does not work for cabal, I get an error that it must be an absolute path. When I changed it to be an absolute one, I built the project successfully but the path is relevant for my OS/file locations only.

Is it possible to replace these 2 settings with something that can be common for ALL developers and to be in our Git repository? I thought there is something ${projectroot} but it seems no such placeholder. And I need some place-hodler for both settings. Or there is way to achieve common code-base for all developers using different OSes and file system layouts?


Solution

  • I am assuming you have a directory like this

    cabal.project
    libs
     |-my-lib
       |- my-lib.cabal
       |- ...
     |-my-other-lib
       |- my-other-lib.cabal
       |- ...
    

    Then your cabal.project looks like this

    packages: lib/my-lib
              lib/my-other-lib
    with-compiler: ghc-8.10.7  
    -- You can delete the line above and cabal will use the compiler in PATH to build the project. 
    -- If you specify the version and developer doesn't have it on the PATH, then he/she should install it.
    

    This information is directly taken from the cabal users guide. You should read it carefully as it is well written. Also, you can take a look to other haskell project and see how they do it. For example pandoc or the cardano node