haskell / cabal

Official upstream development repository for Cabal and cabal-install
https://haskell.org/cabal
Other
1.63k stars 697 forks source link

code-generators documentation is unclear about which GHC options are passed #9238

Open mpickering opened 1 year ago

mpickering commented 1 year ago

The code-generators documentation is a bit unclear about which component the options passed to the generation executable are intended to compile.

I performed some investigation and the GHC options which are passed to the code generator are actually the options you need to build the test executable rather than any of the library components.

Therefore I think this limits the utility of this feature as it can't work unless there is a lucky alignment that the same options work for your doctests as would work for your test executable. One case I tried which failed was adding ghc-options: -XRoleAnnotations to the library stanza, which caused the doctest to fail with:

src/MyLib.hs:16:1: error:
    • Illegal role annotation for A;
      did you intend to use RoleAnnotations?
    • while checking a role annotation for ‘A’

This is in contrast to the previous cabal-docspec approach which generated a file which contained the options which were used to build the package.

Mikolaj commented 1 year ago

Pinging @gbaz, since this looks like a useful feedback for the new and promising code generators feature.

gbaz commented 1 year ago

I'd definitely welcome a patch to the documentation to specify this.

Of a mixed mind if we'd want to change the behavior or not -- grabbing options or other settings from a different stanza could be weird (and possibly tricky to implement just from how the code is structured). We could suggest common stanzas or the like as a way to make this easy to do, at least.