Servantのexampleのcabalファイルを作成する
下記にあるexampleのgreet.hs
用のcabalファイルを作ります。
cabal init
にて対話形式で必要な項目を入力していきます。
foo$ cabal init Package name? [default: servant02] greet Package version? [default: 0.1.0.0] Please choose a license: 1) GPL-2 2) GPL-3 3) LGPL-2.1 4) LGPL-3 5) AGPL-3 6) BSD2 * 7) BSD3 8) MIT 9) ISC 10) MPL-2.0 11) Apache-2.0 12) PublicDomain 13) AllRightsReserved 14) Other (specify) Your choice? [default: BSD3] 8 Author name? [default: bar] foo Maintainer email? [default: aaa@gmail.com] foo@gmail.com Project homepage URL? Project synopsis? greet Project category: * 1) (none) 2) Codec 3) Concurrency 4) Control 5) Data 6) Database 7) Development 8) Distribution 9) Game 10) Graphics 11) Language 12) Math 13) Network 14) Sound 15) System 16) Testing 17) Text 18) Web 19) Other (specify) Your choice? [default: (none)] 18 What does the package build: 1) Library 2) Executable Your choice? 2 What is the main module of the executable: * 1) Main.hs 2) Other (specify) Your choice? [default: Main.hs] 2 Please specify? greet.hs Source directory: * 1) (none) 2) src 3) Other (specify) Your choice? [default: (none)] What base language is the package written in: * 1) Haskell2010 2) Haskell98 3) Other (specify) Your choice? [default: Haskell2010] Add informative comments to each field in the cabal file (y/n)? [default: n] y Guessing dependencies... Generating LICENSE... Warning: LICENSE already exists, backing up old version in LICENSE.save0 Generating Setup.hs... Warning: Setup.hs already exists, backing up old version in Setup.hs.save0 Generating ChangeLog.md... Warning: ChangeLog.md already exists, backing up old version in ChangeLog.md.save0 Generating greet.cabal... You may want to edit the .cabal file and add a Description field.
そのまま実行しようとすると、依存関係のライブラリの指定がなくてエラーになります。Guessing dependencies...
とありますが、完全には推測してくれないようです。
foo$ cabal run greet.cabal ./greet.cabal has been changed. Re-configuring with most recently used options. If this fails, please run configure manually. Resolving dependencies... Configuring greet-0.1.0.0... Preprocessing executable 'greet' for greet-0.1.0.0... [1 of 1] Compiling Main ( greet.hs, dist/build/greet/greet-tmp/Main.o ) [Servant changed] greet.hs:8:1: error: Failed to load interface for ‘Data.Aeson’ It is a member of the hidden package ‘aeson-1.0.2.1’. Perhaps you need to add ‘aeson’ to the build-depends in your .cabal file. Use -v to see a list of the files searched for. greet.hs:11:1: error: Failed to load interface for ‘Data.Text’ It is a member of the hidden package ‘text-1.2.2.1’. Perhaps you need to add ‘text’ to the build-depends in your .cabal file. Use -v to see a list of the files searched for. greet.hs:13:1: error: Failed to load interface for ‘Network.Wai’ It is a member of the hidden package ‘wai-3.2.1.1’. Perhaps you need to add ‘wai’ to the build-depends in your .cabal file. Use -v to see a list of the files searched for. greet.hs:14:1: error: Failed to load interface for ‘Network.Wai.Handler.Warp’ It is a member of the hidden package ‘warp-3.2.9’. Perhaps you need to add ‘warp’ to the build-depends in your .cabal file. Use -v to see a list of the files searched for. greet.hs:16:1: error: Failed to load interface for ‘Servant’ It is a member of the hidden package ‘servant-server-0.9.1.1’. Perhaps you need to add ‘servant-server’ to the build-depends in your .cabal file. Use -v to see a list of the files searched for.
生成されたgreet.cabal
ファイルに、下記の部分を追加しました。バージョンは省いています。
59 -- Other library packages from which modules are imported. 60 build-depends: base >=4.9 && <4.10, -- カンマを追加 61 aeson, -- 追加 62 text, -- 追加 63 wai, -- 追加 64 warp, -- 追加 65 servant-server -- 追加
実行します。
foo$ cabal run greet.cabal ./greet.cabal has been changed. Re-configuring with most recently used options. If this fails, please run configure manually. Resolving dependencies... Configuring greet-0.1.0.0... Preprocessing executable 'greet' for greet-0.1.0.0... Running greet... ^C foo$
最終的なファイルは下記です。