Surprising difference between `cabal --with-ghc` and `--with-compiler`

Can anyone explain the difference between these two cabal invocations? I don’t understand it.

% cabal install --with-ghc ghc-9.6 pandoc
The path to the compiler program (or programs used by the
compiler) cannot be specified on a per-package basis in the
cabal.project file (i.e. setting the 'ghc-location' for package 'pandoc').
All packages have to use the same compiler, so specify the path in a
global 'program-locations' section.
% cabal install --with-compiler ghc-9.6 pandoc
Resolving dependencies...
<proceeds to compile as expected>
1 Like

I had never heard of the --with-ghc option. I see it is only mentioned in the documentation about Setup.hs: 8. Setup.hs Commands — Cabal 3.11.0.0 User's Guide. Perhaps it should be deprecated.

2 Likes

2 posts were split to a new topic: How to disable syntax highlighting on Discourse?

If I had to guess, I would expect that --with-ghc is setting the name of the GHC executable only while --with-compiler is being spliced into the name used to invoke GHC, but also other supporting tools like its corresponding ghc-pkg command, etc.

2 Likes

The error message, which is likely misguided anyway (and wrongly assumes the options comes from a project file, not commandline), suggests that --with-ghc is per-package, while --with-compiler is per-project. Probably --with-prog is generally per-package and, by histerical accident, ghc is accepted for prog in this context, though it doesn’t make sense.

4 Likes

Ah, OK, so then would you say @jaror is correct that --with-ghc should be considered deprecated? (I’m not sure why I started using it in the first place, but I have done so for many years.)

I’m just guessing in the dark. Somebody needs to dig into the codebase, understand this, fix the documentation, fix error messages and, eventually, propose a functionality fix, e.g., the deprecation (of only --with-ghc or more of the --with-prog? only on commandline or also in the project file (if the message is not lying that it can appear in the project file)?). Feel free to open a ticket (I doubt there’s one already).

2 Likes

BTW, apparently cabal repl --with-ghc=doctest is an important use case: GitHub - sol/doctest: An implementation of Python's doctest for Haskell, but repl is very different from build or install and doctests are a very delicate and special beast.

3 Likes

OK, ticket opened: Improve behavior around `--with-ghc` · Issue #9394 · haskell/cabal · GitHub

3 Likes

Thank you Tom!

Now a volunteer is very much welcome. :slight_smile:

1 Like