Matthias Braun
Matthias Braun

Reputation: 34393

"stack setup --upgrade-cabal" fails, can't find Text.Parsec

After creating a new project using stack new testProject, I have edited testProject.cabal to use the latest version of Cabal:

cabal-version:  2.2.0.0

Running stack setup --upgrade-cabal afterwards produces an error:

[ 12 of 216] Compiling Distribution.Compat.Parsing ( Distribution/Compat/Parsing.hs, Distribution/Compat/Parsing.o )

Distribution/Compat/Parsing.hs:61:1: error:
    Could not find module ‘Text.Parsec’
    Use -v to see a list of the files searched for.
   |
61 | import qualified Text.Parsec as Parsec
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Exit code ExitFailure 1 while running ["ghc","Setup.hs"] in /tmp/stack-cabal-upgrade30389/Cabal-2.2.0.0/

I'm on Arch Linux 4.15.3, stack --version gives

Version 1.6.3, Git revision b27e629b8c4ce369e3b8273f04db193b060000db (5454 commits) x86_64 hpack-0.20.0

stack ghc -- --version:

The Glorious Glasgow Haskell Compilation System, version 8.2.2

How can I get around this error and upgrade Cabal using Stack?

Upvotes: 3

Views: 216

Answers (1)

duplode
duplode

Reputation: 34398

The problem you describe happens because:

  1. Cabal 2.2.0.0, unlike the earlier versions, has parsec as a dependency. To account for that, parsec is one of the core packages bundled with GHC from GHC 8.4.1 onwards.

  2. stack setup --upgrade-cabal installs Cabal at a "global" level, which is cross-snapshot but tied to the GHC version. As a consequence, it only uses packages bundled with GHC (as opposed to packages in any snapshot). See Stack issue #3049 and the other issues linked therein for discussion of this point.

That being so, I believe there is no solution to this issue, unless you are willing to change your project to a resolver/snapshot that uses GHC 8.4.1.

P.S.: Unless you need a specific Cabal feature or bugfix included in 2.2.0.0, you may want to reconsider whether you actually want to upgrade Cabal. Quoting the Stack user guide:

stack setup --upgrade-cabal can install a newer version of the Cabal library, used for performing actual builds. You shouldn't generally do this, since new Cabal versions may introduce incompatibilities with package sets, but it can be useful if you're trying to test a specific bugfix.

Upvotes: 3

Related Questions