Skip to content

Declaring TH dependency in .cabal file #28

Open

Description

@hvr

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

Activity

  1. stepcut commented on Jun 10, 2016

    @stepcut
    Member

    Does this patch,

    ede159b

    Correctly implement your suggestions?

  2. hvr commented on Jun 10, 2016

    @hvr
    Author

    @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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions