haskell-jp / questions #99 at 2021-11-12 03:03:18 +0900

stackのLTS18.16で、muslを静的リンクしたaesonに依存するバイナリを作ろうとして躓いています。
再現手順:
1. https://qiita.com/lambda_funtaro/items/5ac47f83616f8c07d4db の通りに設定する(stack.yaml中のdockerのrepoはutdemir/ghc-musl:v22-ghc8107にする)
2. package.yamlのdependenciesにaesonを加える
3. stack build --dockerする
4. ビルドに失敗する↓
Error: While constructing the build
plan, the following exceptions were
encountered:

In the dependencies
for hashable-1.3.0.0:
    integer-gmp must
                match >=0.4 && <1.1, but
                the stack configuration
                has no specified
                version  (latest
                matching version
                is 1.0.3.0)
needed due to test-0.1.0.0
               -> hashable-1.3.0.0

In the dependencies
for integer-logarithms-1.0.3.1:
    integer-gmp must match <1.1, but the
                stack configuration has
                no specified version
                (latest matching version
                is 1.0.3.0)
needed due to test-0.1.0.0
               -> integer-logarithms-1.0.3.1

In the dependencies
for scientific-0.3.7.0:
    integer-gmp needed, but the stack
                configuration has no
                specified version
                (latest matching version
                is 1.0.3.0)
needed due to test-0.1.0.0
               -> scientific-0.3.7.0

Some different approaches to resolving
this:

  * Recommended action: try adding the
    following to your extra-deps
    in (略)/stack.yaml:

- integer-gmp-1.0.3.0@sha256:514e81647473ce380cf1814821664c0dcedc2801ad8dbf41b19a10f916e1cc75,2138

Plan construction failed.
エラーメッセージ最後の指示どおり、 stack.yamlextra-deps
- integer-gmp-1.0.3.0@sha256:514e81647473ce380cf1814821664c0dcedc2801ad8dbf41b19a10f916e1cc75,2138

を追記してもダメでしたか?
追記しても死ぬことを書きそびれてました、エラーメッセージの指示通りextra-depsに追記して再度 stack build --docker したところ、
integer-gmp         > setup: can't find include file ghc-gmp.h
integer-gmp         > 
Progress 1/12
'cabal copy' failed.  Error message:

--  While building package integer-gmp-1.0.3.0 (scroll up to its section to see the error) using:
      /tmp/stack-6497fa01978e9e34/integer-gmp-1.0.3.0/.stack-work/dist/x86_64-linux-dk85569e7f830e7dc606115fd702e078fb/Cabal-3.2.1.0/setup/setup --builddir=.stack-work/dist/x86_64-linux-dk85569e7f830e7dc606115fd702e078fb/Cabal-3.2.1.0 copy
    Process exited with code: ExitFailure 1

Possible causes of this issue:
* No module named "Main". The 'main-is' source file should usually have a header indicating that it's a 'Main' module.
* A cabal file that refers to nonexistent other files (e.g. a license-file that doesn't exist). Running 'cabal check' may point out these issues.
* The Setup.hs file is changing the installation target dir.

のようなエラーを吐いてビルドに失敗しました
これ、静的リンクオプション外して--dockerなしで stack build するとextra-deps無しで通るんですよね
こちらの問題ですね https://github.com/utdemir/ghc-musl/issues/17
ghc-muslではライセンスの都合でinteger-gmpが使えない、と。最後のコメントに
Before GHC 9, GHC supports two integer implementations integer-gmp and integer-simple. Usually, libraries which depend on integer-gmp has flags to make them depend on integer-simple instead. eg: hashable.cabal
とあるとおり、integer-gmpを使う代わりにinteger-simpleを使う必要があります。
今回の場合、scientificやhashableなど、いくつかのパッケージがinteger-gmpに依存しているので、 https://docs.haskellstack.org/en/stable/yaml_configuration/#flags を参考にそれぞれのパッケージでinteger-simpleを利用するよう変えてみてください。
scientific・integer-logarithms・hashableにフラグを設定して、integer-simple-0.1.1.1をextra-depsに加えた状態でビルドしたところ、今度は以下のようなエラーで止まりました
integer-logarithms   > /tmp/stack-fcdd0188ecbca6d6/integer-logarithms-1.0.3.1/src/GHC/Integer/Logarithms/Compat.hs:24:1: error:
integer-logarithms   >     Bad interface file: (略)/8.10.7/lib/x86_64-linux-ghc-8.10.7/integer-simple-0.1.1.1-RAJdiybHJ47N2pZrr0Kz6/GHC/Integer/Logarithms.hi
integer-logarithms   >         Something is amiss; requested module  integer-simple-0.1.1.1:GHC.Integer.Logarithms differs from name found in the interface file integer-simple:GHC.Integer.Logarithms (if these names look the same, try again with -dppr-debug)
integer-logarithms   >    |                 
integer-logarithms   > 24 | import GHC.Integer.Logarithms
integer-logarithms   >    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
integer-logarithms   >                      
hashable             > Configuring hashable-1.3.0.0...
hashable             > Warning:
hashable             >     This package indirectly depends on multiple versions of the same package. This is very likely to cause a compile failure.
hashable             >       package hashable (hashable-1.3.0.0) requires integer-simple-0.1.1.1-RAJdiybHJ47N2pZrr0Kz6
hashable             >       package base (base-4.14.3.0) requires integer-simple-0.1.2.0
hashable             > build
hashable             > Preprocessing library for hashable-1.3.0.0..
hashable             > Building library for hashable-1.3.0.0..
hashable             > [1 of 5] Compiling Data.Hashable.Class
hashable             > Bad interface file: (略)/8.10.7/lib/x86_64-linux-ghc-8.10.7/integer-simple-0.1.1.1-RAJdiybHJ47N2pZrr0Kz6/GHC/Integer/Type.hi
hashable             >     Something is amiss; requested module  integer-simple-0.1.1.1:GHC.Integer.Type differs from name found in the interface file integer-simple:GHC.Integer.Type (if these names look the same, try again with -dppr-debug)
Progress 21/30
integer-simple-0.1.1.1をextra-depsから抜いたらコンパイル通りました……
ありがとうございました~