2019年1月18日金曜日

mqtt-hsを使う時の注意点

stack でmqtt-hsを使おうとした時につまずいた点をまとめておく。
haskell初心者のため、正しい対処かどうかが不明です。


https://github.com/k00mi/mqtt-hs/blob/master/examples/subscribe.hs
のサンプルを動かしてみる。
package.yamlに下記を追加。


  dependencies:
      - mqtt-hs
      - stm

stack buildしたが、


Error: While constructing the build plan, the following exceptions were encountered:

In the dependencies for mqtt-sample2-0.1.0.0:
    mqtt-hs needed, but the stack configuration has no specified version  (latest matching version is 1.0.2)
needed since mqtt-sample2 is a build target.

Some different approaches to resolving this:

  * Consider trying 'stack solver', which uses the cabal-install solver to attempt to find some working build configuration. This can be
    convenient when dealing with many complicated constraint errors, but results may be unpredictable.

  * Recommended action: try adding the following to your extra-deps in /Users/xxxxx/git/yyyy/mqtt-sample2/stack.yaml:

mqtt-hs-1.0.2@sha256:db49cf78d8fb9dbffc01c2bc8cb4f8657b796865fdb7c4711ed59cddd8418f87

Plan construction failed.

extra-depsに追加しろと言われたので、追加。



extra-deps:
    - mqtt-hs-1.0.2

またエラーが出た。


Error: While constructing the build plan, the following exceptions were encountered:

In the dependencies for mqtt-hs-1.0.2:
    base-4.12.0.0 from stack configuration does not match >=4.6 && <4 .12="" span="">  (latest matching version is 4.11.1.0)
    network-2.8.0.0 from stack configuration does not match >=2.0 && <2 .7="" span="">  (latest matching version is 2.6.3.6)
    singletons-2.5.1 from stack configuration does not match >=0.9 && <2 .5="" span="">  (latest matching version is 2.4.1)
    stm-2.5.0.0 from stack configuration does not match >=2.4 && <2 .5="" span="">  (latest matching version is 2.4.5.1)
needed due to mqtt-sample2-0.1.0.0 -> mqtt-hs-1.0.2

Some different approaches to resolving this:

  * Set 'allow-newer: true' in /Users/xxxx/.stack/config.yaml to ignore all version constraints and build anyway.

  * Consider trying 'stack solver', which uses the cabal-install solver to attempt to find some working build configuration. This can be
    convenient when dealing with many complicated constraint errors, but results may be unpredictable.

  * Build requires unattainable version of base. Since base is a part of GHC, you most likely need to use a different GHC version with the
    matching base.

Plan construction failed.

allow-newer:trueにするのは嫌なので、stack solverを実行してみる。
しかしこれでも怒られる。


Using configuration file: stack.yaml
Using cabal packages:
- ./

Using resolver: lts-13.3

Warning: Installed version of cabal-install (2.2.0.0) is newer than stack has been tested with.  If you run into difficulties, consider downgrading.
         
Using compiler: ghc-8.6.3
Asking cabal to calculate a build plan...
Trying with packages from lts-13.3 and 1 external packages as hard constraints...
Attempt failed.

>>>> Cabal errors begin
Warning: Unknown/unsupported 'ghc' version detected (Cabal 2.2.0.1 supports
'ghc' version < 8.5):
/Users/xxxx/.stack/programs/x86_64-osx/ghc-8.6.3/bin/ghc is version 8.6.3
Warning: cannot determine version of /usr/bin/strip :
""
CallStack (from HasCallStack):
  die', called at ./Distribution/Client/Install.hs:238:21 in main:Distribution.Client.Install
cabal: Could not resolve dependencies:
[__0] trying: mqtt-sample2-0.1.0.0 (user goal)
[__1] trying: mqtt-hs-1.0.2 (dependency of mqtt-sample2)
[__2] next goal: base (dependency of mqtt-sample2)
[__2] rejecting: base-4.12.0.0/installed-4.1... (conflict: mqtt-hs =>
base>=4.6 && <4 .12="" span="">
[__2] rejecting: base-4.12.0.0 (constraint from non-upgradeable package
requires installed instance)
[__2] rejecting: base-4.11.1.0, base-4.11.0.0, base-4.10.1.0, base-4.10.0.0,
base-4.9.1.0, base-4.9.0.0, base-4.8.2.0, base-4.8.1.0, base-4.8.0.0,
base-4.7.0.2, base-4.7.0.1, base-4.7.0.0, base-4.6.0.1, base-4.6.0.0,
base-4.5.1.0, base-4.5.0.0, base-4.4.1.0, base-4.4.0.0, base-4.3.1.0,
base-4.3.0.0, base-4.2.0.2, base-4.2.0.1, base-4.2.0.0, base-4.1.0.0,
base-4.0.0.0, base-3.0.3.2, base-3.0.3.1 (constraint from main config
/private/var/folders/q1/rf5gg7zj7h9c07hn60_m1tcr0000gn/T/cabal-solver31325/cabal.config
requires ==4.12.0.0)
After searching the rest of the dependency tree exhaustively, these were the
goals I've had most trouble fulfilling: base (30), mqtt-hs (5), mqtt-sample2
(3)

<<<< Cabal errors end

Could not parse cabal-install errors:

>>>> Cabal errors begin
Warning: Unknown/unsupported 'ghc' version detected (Cabal 2.2.0.1 supports
'ghc' version < 8.5):
/Users/xxxxxxx/.stack/programs/x86_64-osx/ghc-8.6.3/bin/ghc is version 8.6.3
Warning: cannot determine version of /usr/bin/strip :
""
CallStack (from HasCallStack):
  die', called at ./Distribution/Client/Install.hs:238:21 in main:Distribution.Client.Install
cabal: Could not resolve dependencies:
[__0] trying: mqtt-sample2-0.1.0.0 (user goal)
[__1] trying: mqtt-hs-1.0.2 (dependency of mqtt-sample2)
[__2] next goal: base (dependency of mqtt-sample2)
[__2] rejecting: base-4.12.0.0/installed-4.1... (conflict: mqtt-hs =>
base>=4.6 && <4 .12="" span="">
[__2] rejecting: base-4.12.0.0 (constraint from non-upgradeable package
requires installed instance)
[__2] rejecting: base-4.11.1.0, base-4.11.0.0, base-4.10.1.0, base-4.10.0.0,
base-4.9.1.0, base-4.9.0.0, base-4.8.2.0, base-4.8.1.0, base-4.8.0.0,
base-4.7.0.2, base-4.7.0.1, base-4.7.0.0, base-4.6.0.1, base-4.6.0.0,
base-4.5.1.0, base-4.5.0.0, base-4.4.1.0, base-4.4.0.0, base-4.3.1.0,
base-4.3.0.0, base-4.2.0.2, base-4.2.0.1, base-4.2.0.0, base-4.1.0.0,
base-4.0.0.0, base-3.0.3.2, base-3.0.3.1 (constraint from main config
/private/var/folders/q1/rf5gg7zj7h9c07hn60_m1tcr0000gn/T/cabal-solver31325/cabal.config
requires ==4.12.0.0)
After searching the rest of the dependency tree exhaustively, these were the
goals I've had most trouble fulfilling: base (30), mqtt-hs (5), mqtt-sample2
(3)

<<<< Cabal errors end

CallStack (from HasCallStack):
  error, called at src/Stack/Solver.hs:131:25 in stack-1.9.3-AFEUqDV1V61AarVAbZ7WId:Stack.Solver

ghcのバージョンが問題らしいログ。
package.yamlのresolverが結構新しいし、mqtt-hsでテストがpassしているバージョンではないらしい。


resolver: lts-13.3

テストの通っているghcのバージョンに合わせる。

resolver: lts-11.22

無事buildができた。