cabal.project Per GHC Version
A cabal.project file can be used to configure how Cabal builds a project, similar to the stack.yaml configuration file used by Stack. When using Stack, it is common to create a separate configuration file for each snapshot that is used to build or test the package. I have not done this with Cabal yet, but I have now reached a situation where it is necessary.
My recent PhatSort changes implement testing using HMock. Chris merged my pull request that makes HMock work with GHC 8.6 and GHC 8.8 (described in the HMock Compatibility (Part 2) blog entry), but the change has not yet been included in a release. I therefore need to use cabal.project (and stack.yaml) to configure the build systems to get the HMock source from the git repository instead of Hackage. My cabal.project file looked like the following:
packages:
./*.cabal
source-repository-package
type: git
location: https://github.com/cdsmith/HMock.git
tag: b073d0ed096e38f46f1cb8ab526e2e92f24adbbb
allow-newer:
explainable-predicates-0.1.2.0:base
, explainable-predicates-0.1.2.0:template-haskell
, HMock-0.5.0.0:base
, HMock-0.5.0.0:template-haskell
Note that the allow-newer
configuration is required to
relax the dependency bounds to work with GHC 9.2.1. I tested these
packages using GHC 9.2.1 and submitted issues about bumping the bounds
(explainable-predicates,
HMock).
I hoped that this configuration would only affect builds that have these packages as dependencies. Unfortunately, this is not the case. The builds using GHC 8.2.2 and GHC 8.4.4 do not depend on HMock but attempt to compile it due to the cabal.project configuration, resulting in failure.
To resolve this issue, I created a separate cabal.project
configuration file for each version of GHC that the project supports.
The Makefile
is updated to add --project-file
options when a PROJECT_FILE
argument is passed, and the
continuous integration is configured as follows:
- name: Build
run: cabal new-build --enable-tests --enable-benchmarks --project-file=cabal-${{ matrix.ghc }}.project
- name: Test
run: cabal new-test --enable-tests --project-file=cabal-${{ matrix.ghc }}.project
Running the tests, I noticed that the specified revision of HMock is still
fetched even when it is not a dependency. Investigating, I realized that
it is fetched when running cabal update
. This command is
executed as part of the Haskell setup, so I cannot easily append a
--project-file
option. The tests pass, however, so I will
not worry about it.