@@ -194,9 +194,10 @@ cabalAction cradles workDir mc l projectFile fp loadStyle = do
194194 }
195195 Just (componentDir, ghc_args) -> do
196196 deps <- liftIO $ cabalCradleDependencies projectFile workDir componentDir
197- final_args <- case cabalFeatures of
198- CabalWithRepl -> liftIO $ expandGhcOptionResponseFile ghc_args
199- CabalWithGhcShimWrapper -> pure ghc_args
197+ usesResponseFiles <- usesResponseFilesForAllGhcOptions progVersions
198+ final_args <- case usesResponseFiles of
199+ True -> liftIO $ expandGhcOptionResponseFile ghc_args
200+ False -> pure ghc_args
200201 CradleLoadResultT $ pure $ CradleSuccess
201202 ComponentOptions
202203 { componentOptions = final_args
@@ -595,6 +596,37 @@ determineCabalLoadFeature vs = do
595596 | otherwise -> pure CabalWithGhcShimWrapper
596597 _ -> pure CabalWithGhcShimWrapper
597598
599+ -- | As `cabal repl` started to hit maximum cli invocation length, we changed how repl arguments are
600+ -- passed to GHC. In `cabal 3.15`, `cabal 3.16.0.0`, `cabal 3.17` and onwards, ghc options are
601+ -- passed to GHC via response files.
602+ --
603+ -- This breaks HLS release binary distributions before 2.12, as neither HLS nor hie-bios are capable of handling
604+ -- response files at the top-level.
605+ --
606+ -- In particular, `cabal 3.16.0.0` was released with this change and no HLS bindist before 2.12 works
607+ -- with `cabal 3.16.0.0`.
608+ -- To make `cabal 3.16.*` series compatible with released HLS binaries, we reverted the response file
609+ -- change for the ghc options. This change will apply once `cabal 3.16.1.*` is released.
610+ -- Note, in `cabal 3.17`, i.e. cabal HEAD, we still pass the arguments via response files and will do that for the
611+ -- `cabal 3.18` release.
612+ --
613+ -- So, we have a weird matrix now, between some commit in `cabal 3.15` and `cabal 3.16`, ghc arguments
614+ -- are supplied encoded in a response file, while in `>= cabal 3.16.1`, the arguments are passed verbatim.
615+ -- Then, later on in `cabal-3.17`, we use response files again.
616+ --
617+ -- 'usesResponseFilesForAllGhcOptions' encodes all of this history.
618+ usesResponseFilesForAllGhcOptions :: MonadIO m => ProgramVersions -> m Bool
619+ usesResponseFilesForAllGhcOptions vs = do
620+ cabal_version <- liftIO $ runCachedIO $ cabalVersion vs
621+ -- determine which load style is supported by this cabal cradle.
622+ case cabal_version of
623+ Just ver
624+ | ver >= makeVersion [3 , 15 ] && ver <= makeVersion [3 , 16 , 0 , 0 ] -> pure True
625+ | ver >= makeVersion [3 , 17 ] -> pure True
626+ | otherwise -> pure False
627+ _ -> pure False
628+
629+
598630-- | When @cabal repl --with-repl@ is called in a project with a custom setup which forces
599631-- an older @lib:Cabal@ version, then the error message looks roughly like:
600632--
0 commit comments