Search code examples
haskellcabalservant

Cabal error `Unknown fields: build-tool-depends` trying to follow the servant tutorial


I'm trying to follow the servant tutorial and I'm running into the Cabal error Unknown fields: build-tool-depends. This is my tutorial.cabal file (I got this from servant's github repo):

name:                tutorial
version:             0.10
synopsis:            The servant tutorial
homepage:            http://haskell-servant.readthedocs.org/
license:             BSD3
license-file:        LICENSE
author:              Servant Contributors
maintainer:          [email protected]
build-type:          Simple
cabal-version:       >=1.10

library
  exposed-modules:     Server
  build-depends:       base == 4.*
                     , base-compat
                     , text
                     , aeson
                     , aeson-compat
                     , blaze-html
                     , directory
                     , blaze-markup
                     , containers
                     , servant == 0.11.*
                     , servant-server == 0.11.*
                     , servant-client == 0.11.*
                     , servant-docs == 0.11.*
                     , servant-js >= 0.9 && <0.10
                     , warp
                     , http-api-data
                     , http-media
                     , lucid
                     , time
                     , string-conversions
                     , bytestring
                     , attoparsec
                     , mtl
                     , random
                     , js-jquery
                     , wai
                     , http-types
                     , transformers
                     , markdown-unlit >= 0.4
                     , http-client
  default-language:    Haskell2010
  ghc-options:         -Wall -pgmL markdown-unlit
  build-tool-depends: markdown-unlit:markdown-unlit

test-suite spec
  type: exitcode-stdio-1.0
  ghc-options: -Wall
  default-language: Haskell2010
  hs-source-dirs: test
  main-is: Spec.hs
  other-modules: JavascriptSpec
  build-depends: base == 4.*
               , tutorial
               , hspec
               , hspec-wai
               , string-conversions

Should cabal build be able to build this? This is the output I get:

➜  servant cabal build
Package has never been configured. Configuring with default flags. If this
fails, please run configure manually.
Warning: tutorial.cabal: Unknown fields: build-tool-depends (line 46)
Fields allowed in this section:
...

cabal --version gives:

cabal-install version 1.24.0.2
compiled using version 1.24.2.0 of the Cabal library

I don't think my ApiType.hs file matters for this error, but here it is just in case:

{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeOperators #-}

module Server where

import Prelude ()
import Prelude.Compat

import Control.Monad.Except
import Control.Monad.Reader
import Data.Aeson.Compat
import Data.Aeson.Types
import Data.Attoparsec.ByteString
import Data.ByteString (ByteString)
import Data.List
import Data.Maybe
import Data.String.Conversions
import Data.Time.Calendar
import GHC.Generics
import Lucid
import Network.HTTP.Media ((//), (/:))
import Network.Wai
import Network.Wai.Handler.Warp
import Servant
import System.Directory
import Text.Blaze
import Text.Blaze.Html.Renderer.Utf8
import qualified Data.Aeson.Parser
import qualified Text.Blaze.Html

type UserAPI =
       "users" :> Get '[JSON] [User]
--  :<|> "user" :> Capture "id" Integer :> Get '[JSON] User
--  :<|> "user" :> ReqBody '[JSON] User :> Post '[JSON] User

data User = User {
  id :: Int,
  name :: String,
  age :: Int,
  email :: String,
  registration_date :: UTCTime
}

instance ToJSON User

users1 :: [User]
users1 =
  [ User 1 "Isaac Newton" 372 "[email protected]" (fromGregorian 1683 3 1)
  , User 2 "Albert Einstein" 136 "[email protected]" (fromGregorian 1905 12 1)
  ]

server1 :: Server UserAPI
server1 = return users1

userAPI :: Proxy UserAPI
userAPI = Proxy

app1 :: Application
app1 = serve userAPI server1

main :: IO ()
main = run 8081 app1

Any help is very welcome!


Solution

  • build-tool-depends is a new field of cabal 2.0. See What's new in Cabal/cabal-install 2.0

    New build-tool-depends field that replaces build-tools and has a better defined semantics (#3708, #1541). cabal-install will now install required build tools and add them to PATH automatically.