commercialhaskell / stack

The Haskell Tool Stack
http://haskellstack.org
BSD 3-Clause "New" or "Revised" License
3.95k stars 842 forks source link

Stack fails with `Cabal-3.11.0.0` (GHC >= 9.10) #6540

Open mpilgrem opened 3 months ago

mpilgrem commented 3 months ago

GHC 9.10.0.20240328 is available (Alpha 2, first alpha for Windows). However stack build with:

snapshot: nightly-2024-03-30
compiler: ghc-9.10.0.20240328 # Override the compiler version in the snapshot

# Not needed once Stack has setup GHC 9.10.0.20240328:
setup-info:
  ghc:
    windows64:
      9.10.0.20240328:
        url: https://downloads.haskell.org/ghc/9.10.1-alpha2/ghc-9.10.0.20240328-x86_64-unknown-mingw32.tar.xz
        # Can be extended with SHA protections etc: see https://docs.haskellstack.org/en/stable/yaml_configuration/#setup-info

fails with (extract, reformatted for clarity):

Warning: Stack has not been tested with GHC versions 9.10 and above, and using 9.10.0.20240328,
         this may fail.
Warning: Stack has not been tested with Cabal versions 3.12 and above, but version 3.11.0.0 was
         found, this may fail.
...
[2 of 3] Compiling StackSetupShim   ( C:\sr\setup-exe-src\setup-shim-9p6GVs8J.hs, C:\sr\setup-exe-src\setup-shim-9p6GVs8J.o )

C:\sr\setup-exe-src\setup-shim-9p6GVs8J.hs:38:28: error: [GHC-88464]
    Variable not in scope:
      initialBuildSteps
        :: FilePath
           -> PackageDescription
           -> LocalBuildInfo
           -> Distribution.Verbosity.Verbosity
           -> IO ()
   |
38 |             | null rest -> initialBuildSteps distPref pkg_descr lbi verbosity
   |                            ^^^^^^^^^^^^^^^^^

Error: [S-6374]
       While building simple Setup.hs (scroll up to its section to see the error) using:
       ...\x86_64-windows\ghc-9.10.0.20240328\bin\ghc-9.10.0.20240328.exe 
       -rtsopts 
       -threaded 
       -clear-package-db 
       -global-package-db 
       -hide-all-packages 
       -package base 
       -main-is StackSetupShim.mainOverride 
       -package Cabal-3.11.0.0 
       C:\sr\setup-exe-src\setup-9p6GVs8J.hs
       C:\sr\setup-exe-src\setup-shim-9p6GVs8J.hs 
       -o C:\sr\setup-exe-cache\x86_64-windows\tmp-Cabal-simple_9p6GVs8J_3.11.0.0_ghc-9.10.0.20240328.exe
       Process exited with code: ExitFailure 1
mpilgrem commented 3 months ago

Haddocks for Cabal-3.11.0.0: https://ghc.gitlab.haskell.org/ghc/doc/libraries/Cabal-3.11.0.0-inplace/index.html

initialBuildSteps was:

-- | Runs 'componentInitialBuildSteps' on every configured component.
initialBuildSteps :: FilePath -- ^"dist" prefix
                  -> PackageDescription  -- ^mostly information from the .cabal file
                  -> LocalBuildInfo -- ^Configuration information
                  -> Verbosity -- ^The verbosity to use
                  -> IO ()
initialBuildSteps distPref pkg_descr lbi verbosity =
    withAllComponentsInBuildOrder pkg_descr lbi $ \_comp clbi ->
        componentInitialBuildSteps distPref pkg_descr lbi clbi verbosity
mpilgrem commented 3 months ago

The history:

What Stack is doing is this: before using ghc --interactive, it uses replHook (with initialBuildSteps) as a way of getting Cabal to create the autogenerated files for every configured component. To use initialBuildSteps, Stack needs access to (a) the 'dist' prefix (FilePath) (b) PackageDescription (c) LocalBuildInfo (d) Vebosity - replHook is one way to get that information (some of it - the 'dist' prefix, verbosity - is provided via the ReplFlags value).

Stack introduced this to cause Cabal to create the autogenerated files for every configured component, without building everything else, making stack ghci or stack repl more efficient.

mpilgrem commented 3 months ago

Related question: https://github.com/haskellfoundation/tech-proposals/pull/60#issuecomment-2028475305

hasufell commented 3 months ago

It is confusing and depressing that Cabal invests little to no energy to understand whether they're breaking other main downstream users.

Did you open an issue at Cabal?

mpilgrem commented 3 months ago

@hasufell, the corresponding Cabal issue is https://github.com/haskell/cabal/issues/9856.

mpilgrem commented 3 months ago

There is now a temporary workaround in Stack's master branch, as Cabal-3.11.0.0 exports what is needed for Stack to recreate the missing initialBuildSteps.