commercialhaskell / commercialhaskell/stack

Understand relationship between `stack repl` and Cabal (the library) `repl`

Open
#6,548 1 comment 0 reactions 1 assignee Claimed by @mpilgrem View on GitHub
component: Cabal library component: ghci type: enhancement
Dominant language
Haskell
Stars
4.1k
Forks
850
Avg merge
10h 37m
Merged PRs (30d)
4

Description

Motivation:
* @sheaf's observations here: https://github.com/haskellfoundation/tech-proposals/pull/60#issuecomment-2034340587 ...
* ... here: https://github.com/commercialhaskell/stack/issues/6542#issuecomment-2034348791 ...
* ... here: https://github.com/haskell/cabal/issues/9857#issuecomment-2034465886 ...
* ... and here: https://github.com/haskell/cabal/issues/9856#issuecomment-2034370726.

Is there a reason that Stack avoids the use of Cabal (the library) `repl` (from Cabal >= 2.2)?

Context:
`Stack.Build.ExecutePackage.realConfigAndBuild` (extracts):
~~~haskell
case ( ee.buildOptsCLI.onlyConfigure
, ee.buildOptsCLI.initialBuildSteps && taskIsTarget task
) of
...
(_, True) | null ac.downstream || installedMapHasThisPkg -> do
initialBuildSteps cabal announce
...
where
...
initialBuildSteps cabal announce = do
announce ("initial-build-steps" <> display annSuffix)
cabal KeepTHLoading ["repl", "stack-initial-build-steps"]
~~~

`Stack.GhciCmd.ghciCmd` (extracts):
~~~haskell
ghciCmd ghciOpts =
let boptsCLI = defaultBuildOptsCLI
{ ...
, initialBuildSteps = True
...
}
in withConfig YesReexec $ withEnvConfig AllowNoTargets boptsCLI $ do
bopts <- view buildOptsL
-- override env so running of tests and benchmarks is disabled
let boptsLocal = bopts
{ testOpts = bopts.testOpts { TestOpts.disableRun = True }
, benchmarkOpts =
bopts.benchmarkOpts { BenchmarkOpts.disableRun = True }
}
local (set buildOptsL boptsLocal) (ghci ghciOpts)
~~~

`Stack.GhciCmd.ghci` (extracts):
~~~haskell
-- | Launch a GHCi session for the given project package targets with the given
-- options and configure it with the load paths and extensions of those targets.
ghci :: HasEnvConfig env => GhciOpts -> RIO env ()
ghci opts = do
...
-- Build required dependencies and setup project packages.
buildDepsAndInitialSteps opts $
concatMap (\(pn, (_, t)) -> pkgTargets pn t) localTargets
...
-- Finally, do the invocation of ghci
runGhci
opts
localTargets
mainFile
pkgs
(maybe [] snd mfileTargets)
(nonLocalTargets ++ addPkgs)
relevantDependencies
~~~

History:
* May 2015: https://github.com/commercialhaskell/stack/issues/130 (at that time, there were aspects of Cabal's `repl` that the Stack project did not want to emulate)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.