Home > Back-end >  Failing to build Haskell project with `persistent-postgresql` on Mac with M1 chip
Failing to build Haskell project with `persistent-postgresql` on Mac with M1 chip

Time:09-28

I'm trying to build my Yesod web app with GHC 9.0.1 via stack

resolver: nightly-2021-09-02

My application uses PostgreSQL database. There are custom persist fields in my code derived via derivePersistField. Build failing with following error message:

<command line>: dlopen(/Users/arthurfayzrakhmanov/.stack/snapshots/x86_64-osx/b9ed0f8360016ada5efeb53015219761394cfd2d563da5d48a402d192c951f0a/9.0.1/lib/x86_64-osx-ghc-9.0.1/libHSpostgresql-libpq-0.9.4.3-4UpE2VczKgl8p7NC0fd3Q8-ghc9.0.1.dylib, 5): Symbol not found: _PQclear
  Referenced from: /Users/arthurfayzrakhmanov/.stack/snapshots/x86_64-osx/b9ed0f8360016ada5efeb53015219761394cfd2d563da5d48a402d192c951f0a/9.0.1/lib/x86_64-osx-ghc-9.0.1/libHSpostgresql-libpq-0.9.4.3-4UpE2VczKgl8p7NC0fd3Q8-ghc9.0.1.dylib
  Expected in: flat namespace       
 in /Users/arthurfayzrakhmanov/.stack/snapshots/x86_64-osx/b9ed0f8360016ada5efeb53015219761394cfd2d563da5d48a402d192c951f0a/9.0.1/lib/x86_64-osx-ghc-9.0.1/libHSpostgresql-libpq-0.9.4.3-4UpE2VczKgl8p7NC0fd3Q8-ghc9.0.1.dylib

I have PostgreSQL 13 installed via brew.

What is proper setup for PostgreSQL use with persistent on Macs with M1 chip?

Thanks in advance.

CodePudding user response:

I was able to build persistent-postgresql having:

  • PostgreSQL installed via brew install postgresql
  • GHC v8.10.7 and cabal-install installed via brew install ghc cabal-install
  • stack installed via brew install haskell-stack
    (previously I had manually installed stack and upgraded it to latest git version)
  • Switched my project resolver to LTS-18.10 to match compiler version to system one (8.10.7)
  • Using stack build --system-ghc to build my project with stack.
  • or cabal build.

There some drawbacks with this approach:

  • brewed stack unable to install any GHC and stuck to use system compiler

    > stack setup
    I don't know how to install GHC for (OSX,AArch64), please install manually

  • brew install ghc@9 fails with recommendation to build it from source, which is unsupported and it fails indeed:

    ==> make
    Last 15 lines from /Users/arthurfayzrakhmanov/Library/Logs/Homebrew/ghc@9/04.make:
    adc

  • Related