(HEAD + PackageImports + multiple package versions) don't mix
This is an issue that I've noticed somewhat recently when testing head.hackage
patches locally with HEAD—see head.hackage!188 (comment 394908). The issue requires:
- The use of of GHC HEAD,
- Building a package that uses
PackageImports
, and - Multiple installations of the same library in one's
cabal
store, but with different versions
Here is a somewhat minimal way to reproduce the issue. You will need the following files in a new directory:
cabal-version: 2.4
-- ghc-bug.cabal
name: ghc-bug
version: 0.1
build-type: Simple
library
exposed-modules: Lib
build-depends: base, base-orphans
default-language: Haskell2010
-- Lib.hs
{-# LANGUAGE PackageImports #-}
module Lib where
import "base-orphans" Data.Orphans ()
Once you have ghc-bug.cabal
and Lib.hs
, perform the following steps:
-
Make sure you do not have any prior installations of
base-orphans
in yourcabal
store for GHC HEAD. -
Run
cabal build -w <path-to-ghc-head> --constraint="base-orphans==0.8.6"
. This should succeed. -
Run
cabal build -w <path-to-ghc-head> --constraint="base-orphans==0.8.5"
. This will mysteriously fail with:Lib.hs:5:1: error: Could not load module ‘Data.Orphans’ It is a member of the hidden package ‘base-orphans-0.8.6’. Perhaps you need to add ‘base-orphans’ to the build-depends in your .cabal file. | 5 | import "base-orphans" Data.Orphans () | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Here are all the steps together:
$ ls
ghc-bug.cabal Lib.hs
$ cabal build -w ~/Software/ghc-9.3.20211203/bin/ghc --constraint="base-orphans==0.8.6"
Resolving dependencies...
Build profile: -w ghc-9.3.20211203 -O1
In order, the following will be built (use -v for more details):
- ghc-bug-0.1 (lib) (first run)
Configuring library for ghc-bug-0.1..
Preprocessing library for ghc-bug-0.1..
Building library for ghc-bug-0.1..
[1 of 1] Compiling Lib ( Lib.hs, /home/ryanglscott/Documents/Hacking/Haskell/ghc-bug/dist-newstyle/build/x86_64-linux/ghc-9.3.20211203/ghc-bug-0.1/build/Lib.o, /home/ryanglscott/Documents/Hacking/Haskell/ghc-bug/dist-newstyle/build/x86_64-linux/ghc-9.3.20211203/ghc-bug-0.1/build/Lib.dyn_o )
$ cabal build -w ~/Software/ghc-9.3.20211203/bin/ghc --constraint="base-orphans==0.8.5"
Resolving dependencies...
Build profile: -w ghc-9.3.20211203 -O1
In order, the following will be built (use -v for more details):
- ghc-bug-0.1 (lib) (configuration changed)
Configuring library for ghc-bug-0.1..
Preprocessing library for ghc-bug-0.1..
Building library for ghc-bug-0.1..
[1 of 1] Compiling Lib ( Lib.hs, /home/ryanglscott/Documents/Hacking/Haskell/ghc-bug/dist-newstyle/build/x86_64-linux/ghc-9.3.20211203/ghc-bug-0.1/build/Lib.o, /home/ryanglscott/Documents/Hacking/Haskell/ghc-bug/dist-newstyle/build/x86_64-linux/ghc-9.3.20211203/ghc-bug-0.1/build/Lib.dyn_o ) [Data.Orphans changed]
Lib.hs:5:1: error:
Could not load module ‘Data.Orphans’
It is a member of the hidden package ‘base-orphans-0.8.6’.
Perhaps you need to add ‘base-orphans’ to the build-depends in your .cabal file.
|
5 | import "base-orphans" Data.Orphans ()
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Note that:
-
The error message mentions
base-orphans-0.8.6
, even though we're specifically trying to build withbase-orphans-0.8.5
. -
The mysterious
Could not load module ‘Data.Orphans’
failure will persist even after acabal clean
. The only workaround I've been able to discover is to completely delete one'scabal
store for GHC HEAD, which will allow you to build the package withbase-orphans-0.8.5
. (However, doing so will then prevent you from building the package with other versions, such asbase-orphans-0.8.6
!) -
This is only reproducible with GHC HEAD. Older versions such as GHC 9.2.1 do not exhibit this issue:
$ cabal build -w ghc-9.2.1 --constraint="base-orphans==0.8.6" Resolving dependencies... Build profile: -w ghc-9.2.1 -O1 In order, the following will be built (use -v for more details): - ghc-bug-0.1 (lib) (first run) Configuring library for ghc-bug-0.1.. Preprocessing library for ghc-bug-0.1.. Building library for ghc-bug-0.1.. [1 of 1] Compiling Lib ( Lib.hs, /home/ryanglscott/Documents/Hacking/Haskell/ghc-bug/dist-newstyle/build/x86_64-linux/ghc-9.2.1/ghc-bug-0.1/build/Lib.o, /home/ryanglscott/Documents/Hacking/Haskell/ghc-bug/dist-newstyle/build/x86_64-linux/ghc-9.2.1/ghc-bug-0.1/build/Lib.dyn_o ) $ cabal build -w ghc-9.2.1 --constraint="base-orphans==0.8.5" Resolving dependencies... Build profile: -w ghc-9.2.1 -O1 In order, the following will be built (use -v for more details): - ghc-bug-0.1 (lib) (configuration changed) Configuring library for ghc-bug-0.1.. Preprocessing library for ghc-bug-0.1.. Building library for ghc-bug-0.1.. [1 of 1] Compiling Lib ( Lib.hs, /home/ryanglscott/Documents/Hacking/Haskell/ghc-bug/dist-newstyle/build/x86_64-linux/ghc-9.2.1/ghc-bug-0.1/build/Lib.o, /home/ryanglscott/Documents/Hacking/Haskell/ghc-bug/dist-newstyle/build/x86_64-linux/ghc-9.2.1/ghc-bug-0.1/build/Lib.dyn_o ) [Data.Orphans changed]
I'm using cabal-install-3.6.2.0
, in case that is relevant. I don't know how to reproduce the issue without cabal-install
, but since this only happens on GHC HEAD, I suspect this is a GHC issue rather than a cabal-install
one.