Skip to content
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

Declaring TH dependency in .cabal file #28

Open
hvr opened this issue Jun 10, 2016 · 2 comments
Open

Declaring TH dependency in .cabal file #28

hvr opened this issue Jun 10, 2016 · 2 comments

Comments

@hvr
Copy link

hvr commented Jun 10, 2016

Currently, happstack has

Flag template_haskell
    Description: Template Haskell is available on this system
    Default: True
    Manual: True

...

Library:
  if (flag(template_haskell) && !(arch(arm)))
    Build-Depends:     template-haskell
    cpp-options:       -DTEMPLATE_HASKELL

...

  Extensions: TemplateHaskell

There's a couple of problems here (with cabal-1.24 & GHC 8.0)

If the TH-flag is set to false (or arch=arm), this package still won't build when GHC doesn't support TH, because then extensions: TemplateHaskell will still be in effect, and GHC will fail complaining it doesn't support TH.

And with cabal-1.24, the solver will already exclude packages during solving where extensions: TemplateHaskell when GHC doesn't support that extension.

Moreover, arch(arm) is not the only platform lacking TH support. However, since cabal knows when your environment supports TH, you should let cabal decide.

Consequently, I suggest the following definitions instead:

Use an automatic flag for declaring TH support, and make sure this flag doesn't have any other pressure applied other than other-extensions: TemplateHaskell or default-extensions: TemplateHaskell, i.e.

Flag template_haskell
    Description: Template Haskell is available on this system
    Default: True
    Manual: False

Library:
  -- the TH library is available even in environments lacking -XTemplateHaskell support
  -- placing this outside the conditional allows adding upper bounds after-the-fact on hackage w/o adding solver-pressure to the flag
  Build-Depends: template-haskell
  if flag(template_haskell)
    cpp-options:       -DTEMPLATE_HASKELL
    -- other-extensions doesn't enable the extension; this only declares which LANGUAGE pragmas may be used
    other-extensions: TemplateHaskell

this will cause cabal (starting with 1.24) to set the template_haskell flag depending on whether the compiler supports TH.

/cc @bergmark @phadej

@stepcut
Copy link
Member

stepcut commented Jun 10, 2016

Does this patch,

ede159b

Correctly implement your suggestions?

@hvr
Copy link
Author

hvr commented Jun 10, 2016

@stepcut yes, looks good!

While we're at it, I'd have a few more suggestions :-)

I suspect that happstack-server doesn't support any GHC version before 7.0; in that case I'd suggest to use Cabal-Version: >= 1.10

Then I see that the code makes seems to make use of {-# LANGUAGE #-} anyway; and the obsolete exceptions: ... declaration is the deprecated name for default-exceptions: ..., in fact if you update the cabal-version field, cabal will tell you:

Warning: For packages using cabal-version: >= 1.10 the extensions field is deprecated. The new default-extensions field lists extensions that are used in all modules in the component, while the other-extensions field lists extensions that are used in some modules, e.g. via the {-# LANGUAGE #-} pragma.

So I'd recommend to try to make more use of other-extensions if you use {-# LANGUAGE #-} anyway. Fwiw, I'm working extending the cabal tooling to help maintain the other-extensions list.

PS: I'll try to build happstack-server on a TH-less GHC to see if there's anything else to take care of

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

No branches or pull requests

2 participants