Description
Describe the bug
One of the component (which contains generated .hsc
files) in my package causes any clean cabal repl
(i.e. running cabal repl
after cabal clean
) to fail with ppHsc2hs: broken closure: []
. Running cabal build
or cabal test
reliably makes this issue go away.
This is a bit problematic since haskell-language-server runs cabal repl
(in a clean build directory under ~/.cache/hie-bios/
) to obtain ghc flags used to create ghc API sessions. Which will always fail, and requires users to read the log and manually run cabal build
with the right flags for every component.
I'm not exactly sure what might have caused this bug. Some of my current suspicions are
- The use of hooks to modify components (which might have triggered some bugs related to custom setups)
- Cabal has buggy logic when dealing with hsc files
To Reproduce
I currently do not have time to create a minimal working example. But cloning https://github.com/poscat0x04/shake-fpga-test
and running cabal repl shake-fpga-test-test
should work. (currently requires installing verilator)
Expected behavior
Cabal should correctly handle hsc files.
System information
- linux
- cabal v 3.14
- ghc v 9.8.2
Additional context
This patch can workaround this issue but I'm not sure what's the implications of this change and if it is the right solution.
diff --git a/Cabal/src/Distribution/Simple/PreProcess.hs b/Cabal/src/Distribution/Simple/PreProcess.hs
index 9675d431b..290820119 100644
--- a/Cabal/src/Distribution/Simple/PreProcess.hs
+++ b/Cabal/src/Distribution/Simple/PreProcess.hs
@@ -645,6 +645,7 @@ ppHsc2hs bi lbi clbi =
hacked_index
(map fst (componentPackageDeps clbi)) of
Left index' -> index'
+ Right [] -> hacked_index
Right inf ->
error ("ppHsc2hs: broken closure: " ++ show inf)
isOSX = case buildOS of OSX -> True; _ -> False