You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi @LeventErkok. The discussion in that PR is long and it looks like my original PR description became stale as the patch progressed. Based on this comment by @alt-romes it looks like the haddock-version-cpp option was never introduced and the decision was made to remove the __HADDOCK_VERSION__ macro altogether. Apologies for the inconvenience. What is your use-case for the macro?
For my particular case, I'd like to hide doc-test setup segments from generated Haddock output. Without having a way to tell whether we're running under haddock or not, this is impossible to do.
At the end of the day, it seems like it'd be useful to have a mechanism for users to determine if haddock is the starting point. I understand the motivation for avoiding rebuilds, but if the user chooses to do so, there should be a way; to maintain old behavior if nothing else.
@LeventErkok hi, it's unfortunate that this has broken your workflow. Let's try to work out a fix.
I would appreciate it if you could post an example of what exactly you are trying to achieve with doc-test so that I can understand your use case better.
My understanding is that re-introducing HADDOCK_VERSION is a step backwards, even though I wouldn't be opposed to re-introducing it temporarily to ease migration.
In particular, perhaps the right question is "why does doc-test force the doc-tests to be part of the haddock comments?". It's maybe a limitation of the tool to require doc-tests to be in the haddocks rather than attached in a different way to a function -- it makes sense to want doctests either on or off haddocks.
Or, perhaps, it is more that you want to selectively disable parts of a haddock comment; but that begs the question why did you write it as part of a haddock in the first place.
I will also explain what it is we need (although maybe it's better to do that somewhere else?), but I did not get around to it yet.
If the intent is simply to tell "we are generating Haddock" from "we are compiling a package", maybe the following workaround is okay?
flag for-haddock
description:
Define this flag during Haddock generation
default: False
manual: True
library
if flag(for-haddock)
CPP-Options: -DFOR_HADDOCK
and then if you invoke it as
$ cabal haddock -ffor-haddock
the macro will be defined so you can tune your Haskell source files to do the right thing for Haddock, whereas during normal compilation you would of course not set this flag and get the behaviour you want for normal code generation.
Of course, if your package is on Stackage, the documentation on the Stackage webpage will not generate the correct version, and you'll also need to manually upload documentation to Hackage to get it right there.
@DigitalBrains1 Your workaround works like a charm and handles my use case! In fact, perhaps this should be the recommended method as the user is explicitly opting in to the recompilation cost.
@alt-romes I'm happy to close this ticket; perhaps except to mention @DigitalBrains1's workaround as the recommended solution in some cabal documentation?
I've just created issue #10852 where I list why we need control over the Haddock generation, so the Cabal devs know what weird hoops users actually make their tool jump through ;-).
Sadly, the approach with a Cabal flag has problems:
You must always remember this flag to build docs,
you must upload documentation on Hackage manually (I didn't find a way to use custom flags for building docs on Hackage),
(most annoying) a user who builds a code that depends on such a package with --enable-documentation must know this flag as well to simply not let the build fail (I use --optghc=-DNGX_CSTUB to trick Haddock not to link to undefined symbols, and thus this is my case).
These issues can be resolved by using Cabal's Custom build. For this, put file Setup.hs in the root directory of the project.
Here, -DNGX_CSTUB plays the same role as -DFOR_HADDOCK.
Cabal file (a fragment)
build-type: Custom
custom-setup
setup-depends: base >=4.8&&<5
, Cabal >=3.0.0.0&&<4
Note though, that the Custom build approach is being currently replaced by Cabal's Setup hooks. Unfortunately, I didn't find a way to customize GHC options for Haddock like this with Setup hooks.
Activity
FinleyMcIlwaine commentedon Mar 8, 2025
Hi @LeventErkok. The discussion in that PR is long and it looks like my original PR description became stale as the patch progressed. Based on this comment by @alt-romes it looks like the
haddock-version-cppoption was never introduced and the decision was made to remove the__HADDOCK_VERSION__macro altogether. Apologies for the inconvenience. What is your use-case for the macro?LeventErkok commentedon Mar 8, 2025
For my particular case, I'd like to hide doc-test setup segments from generated Haddock output. Without having a way to tell whether we're running under haddock or not, this is impossible to do.
Based on clash-lang/clash-compiler#2902, I think Clash has similar needs. @DigitalBrains1 might want to comment further.
At the end of the day, it seems like it'd be useful to have a mechanism for users to determine if haddock is the starting point. I understand the motivation for avoiding rebuilds, but if the user chooses to do so, there should be a way; to maintain old behavior if nothing else.
mpickering commentedon Mar 11, 2025
I think the proper mechanism to fix this would be to make "haddock" into a way (the same as
static,dynamicetc)alt-romes commentedon Mar 14, 2025
@LeventErkok hi, it's unfortunate that this has broken your workflow. Let's try to work out a fix.
I would appreciate it if you could post an example of what exactly you are trying to achieve with doc-test so that I can understand your use case better.
My understanding is that re-introducing
HADDOCK_VERSIONis a step backwards, even though I wouldn't be opposed to re-introducing it temporarily to ease migration.In particular, perhaps the right question is "why does doc-test force the doc-tests to be part of the haddock comments?". It's maybe a limitation of the tool to require doc-tests to be in the haddocks rather than attached in a different way to a function -- it makes sense to want doctests either on or off haddocks.
Or, perhaps, it is more that you want to selectively disable parts of a haddock comment; but that begs the question why did you write it as part of a haddock in the first place.
Thank you for bringing this up.
DigitalBrains1 commentedon Mar 14, 2025
I will also explain what it is we need (although maybe it's better to do that somewhere else?), but I did not get around to it yet.
If the intent is simply to tell "we are generating Haddock" from "we are compiling a package", maybe the following workaround is okay?
and then if you invoke it as
the macro will be defined so you can tune your Haskell source files to do the right thing for Haddock, whereas during normal compilation you would of course not set this flag and get the behaviour you want for normal code generation.
Of course, if your package is on Stackage, the documentation on the Stackage webpage will not generate the correct version, and you'll also need to manually upload documentation to Hackage to get it right there.
LeventErkok commentedon Mar 14, 2025
@DigitalBrains1 Your workaround works like a charm and handles my use case! In fact, perhaps this should be the recommended method as the user is explicitly opting in to the recompilation cost.
@alt-romes I'm happy to close this ticket; perhaps except to mention @DigitalBrains1's workaround as the recommended solution in some cabal documentation?
DigitalBrains1 commentedon Mar 25, 2025
I've just created issue #10852 where I list why we need control over the Haddock generation, so the Cabal devs know what weird hoops users actually make their tool jump through ;-).
lyokha commentedon Feb 19, 2026
Sadly, the approach with a Cabal flag has problems:
--enable-documentationmust know this flag as well to simply not let the build fail (I use--optghc=-DNGX_CSTUBto trick Haddock not to link to undefined symbols, and thus this is my case).These issues can be resolved by using Cabal's Custom build. For this, put file Setup.hs in the root directory of the project.
Setup.hs
Here,
-DNGX_CSTUBplays the same role as-DFOR_HADDOCK.Cabal file (a fragment)
Note though, that the Custom build approach is being currently replaced by Cabal's Setup hooks. Unfortunately, I didn't find a way to customize GHC options for Haddock like this with Setup hooks.