Skip to content

Add feature to generate cabal_macros.h #2209

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
nh2 opened this issue Nov 10, 2014 · 2 comments
Open

Add feature to generate cabal_macros.h #2209

nh2 opened this issue Nov 10, 2014 · 2 comments

Comments

@nh2
Copy link
Member

nh2 commented Nov 10, 2014

We would like to generate and use cabal_macros.h (e.g. for hlint or our ghc -M based build system) without actually running cabal build.

I was surprised that cabal_macros.h is created by cabal build only, and not by cabal configure.

Also, while you can do cabal build mytarget, there isn't an empty target, so there currently is no way to tell cabal to only generate cabal_macros.h and do no further compilation.

It would be great to have a way to generate only cabal_macros.h; maybe via one of these alternatives:

  • make it part of cabal configure
  • add a flag cabal build
  • add an empty build target in some way (maybe cabal build "")
nh2 added a commit to nh2/ganeti that referenced this issue Nov 10, 2014
This uses `cabal configure` to determine which exact dependency versions
we are compiling against.

MIN_VERSION_* macros are the standard way to build CPP dependency switches
in Haskell packages, and they replace our custom macros (like PARALLEL3).
We can now conditionally compile against any version of our dependencies,
without first having to manually add a flag via autoconf.

All ghc and hlint invocations were adjusted to take these macros into
account.

We now require hlint >= 1.8.60, which support the --cpp-file option,
and any installed version of cabal.

In addition to providing MIN_VERSION_* macros, the `cabal configure`
step makes the build fail at configuration time if the user tries to
compile against a dependency version we don't support; before, this
case led to type errors which were not clearly user errors.

In order to obtain the sought cabal_macros.h, we have to work around
the fact that cabal does not yet provide a way to build only the macros
(see haskell/cabal#2209).
Ideally, they would be created as part of `cabal configure`, but
unfortunately they are created as the first step of `cabal build`.
Thus we `cabal build` a dummy executable (HaskellPackageVersionsDummy)
in a temporary directory to obtain cabal_macros.h.
nh2 added a commit to nh2/ganeti that referenced this issue Nov 10, 2014
This uses `cabal configure` to determine which exact dependency versions
we are compiling against.

MIN_VERSION_* macros are the standard way to build CPP dependency switches
in Haskell packages, and they replace our custom macros (like PARALLEL3).
We can now conditionally compile against any version of our dependencies,
without first having to manually add a flag via autoconf.

All ghc and hlint invocations were adjusted to take these macros into
account.

We now require hlint >= 1.8.60, which support the --cpp-file option,
and any installed version of cabal.

In addition to providing MIN_VERSION_* macros, the `cabal configure`
step makes the build fail at configuration time if the user tries to
compile against a dependency version we don't support; before, this
case led to type errors which were not clearly user errors.
This fixes issue ganeti#988.

In order to obtain the sought cabal_macros.h, we have to work around
the fact that cabal does not yet provide a way to build only the macros
(see haskell/cabal#2209).
Ideally, they would be created as part of `cabal configure`, but
unfortunately they are created as the first step of `cabal build`.
Thus we `cabal build` a dummy executable (HaskellPackageVersionsDummy)
in a temporary directory to obtain cabal_macros.h.
@23Skidoo
Copy link
Member

make it part of cabal configure

IMO, this makes more sense than the current situation. @dcoutts, is there any reason this is done at build time?

@jneira
Copy link
Member

jneira commented Nov 25, 2019

This is a really old one but we are hitting it in the haskell-ide-engine branch that uses cabal-helper to load packages in the ide: as cabal-helper does only a cabal v2-build --only-configure the header is not created and it makes required build the project before open it with the editor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants