pretty-simple
pretty-simple copied to clipboard
Cross-compilation broken by custom Setup.hs used for doctests
Currently, the custom Setup.hs used for doctests causes cross-compilation to fail due to a loingstanding cabal bug.
I set write-ghc-environment-files
to always
in my cabal.project
and then just run doctest
from the command-line as a workaround.
Hmm, yeah, I would like to get away from using a custom setup if it's at all possible. There are a lot of issues around them, and this isn't the kind of library that justifies it. The pretty-simple
tests quite often fail to run for me on GHC 8.10 anyway.
I'm sure there was talk at some point of a proper cabal doctest
command? I'll have a look for that discussion.
Running doctest
from the project route is giving me cannot satisfy -package-id pretty-simple-3.3.0.0-inplace
, even when I have an environment file which contains precisely that (generated by cabal repl --write-ghc-environment-files=always
.
@vmchale How are you getting this to work?
I put them in my cabal.project
file as a line like
write-ghc-environment-files: always
(perhaps you've run into another cabal bug 😬 )
It doesn't seem to make a difference how I specify the flag (file vs. command line), which to be honest is a good thing...
I'm not very familiar with doctest
though. To be clear, you're just running doctest
, with no args, from the pretty-simple
directory? If so then I guess I am hitting a bug.
FWIW, I'm using doctest
0.17 on pretty-simple
's HEAD
(763d7693), with GHC 8.10.2, on Linux.
My workflow is
cabal build --write-ghc-environment-files always
doctest src
For whatever reason doctest
by itself doesn't work. And I set build-type: Simple
in the .cabal
file
(I think cabal repl
doesn't quite do what one wants; it doesn't build pretty-simple
itself)
(I think cabal repl doesn't quite do what one wants; it doesn't build pretty-simple itself)
Aha, you're right! I'd missed that subtlety.
The problem with doctest
is that it doesn't know how to find the required package database when running with the various Haskell build tools (stack
, cabal-v1
, cabal-v2
, haskell environment from nixpkgs, haskell.nix
).
cabal-doctest
is the only reliable solution right now (although it still doesn't work with haskell.nix
).
I don't want to move away from cabal-doctest
until there is some other way to reliably run doctests.
However, as you've seen, the custom Setup.hs
is only for the doctests, so as a workaround you should be able to delete the Setup.hs
, change the build-type
to Simple
, and disable the doctests.
If you wanted to make this process a little easier, please feel free to send a PR putting the doctests under a flag that you can easily disable.
Worth keeping an eye on: https://mail.haskell.org/pipermail/haskell-cafe/2020-August/132570.html
BTW, lens did a similar update recently.
(An older version of lens
and this package breaks with global -split-sections
ghc flag.)
Thanks @dpwiz, that link is very handy.
Looking at the cabal-docspec manual, I think that could be the perfect solution.
If you wanted to make this process a little easier, please feel free to send a PR putting the doctests under a flag that you can easily disable.
Having just tried this, simply changing the one line to build-type: Simple
is enough to get cross-compilation working. But it isn't something that can be put behind a flag AFAICT.
There's a long thread on the Cabal issue tracker about doctests: https://github.com/haskell/cabal/issues/4500
Recently sol commented about using cabal repl
directly with doctest
to run doctests: https://github.com/haskell/cabal/issues/4500#issuecomment-969061372
I'd be interested to see a comparison between cabal repl --with-ghc=doctest
, cabal-docspec
and cabal-doctests
(including whether they easily work with stack
, Nixpkgs haskell stuff, and haskell.nix
).
Looks like there is one more doctest contender in the mix, doctest-parallel:
- https://hackage.haskell.org/package/doctest-parallel
- https://github.com/martijnbastiaan/doctest-parallel
- https://www.reddit.com/r/haskell/comments/rnkof1/ann_doctestparallel_isolate_and_speed_up_your/
One feature of doctest-parallel
is that it apparently parses cabal files to discover modules, so you don't need a custom Setup.hs.
It would be great add a comparison to doctest-parallel
to the list above
There has apparently recently been a PR to cabal that adds a new doctest-related feature:
- PR: https://github.com/haskell/cabal/pull/7688
- repo showing example of using this with doctests: https://github.com/gbaz/cabal-doctest-demo
I haven't looked at this thoroughly, but this might be the best option so far, since it will officially be supported by cabal
.
edit: This has been released in Cabal-3.8.1.0: https://discourse.haskell.org/t/just-released-cabal-3-8-1-0/4920