Building a Haskell project with GitHub workflows fails with libffi error only on ghc-9.2

I have a GitHub action that looks like this:

name: build and test on ubuntu
on: [push]
jobs:
  build:
    runs-on: ubuntu-24.04
    strategy:
      matrix:
        ghc: ['9.6', '9.4', '9.2']
    steps:
      - uses: actions/checkout@v4
      - uses: haskell-actions/setup@v2
        with:
          ghc-version: ${{ matrix.ghc }}
          cabal-version: '3.0.0.0' # Exact version of Cabal      - 
      - name: install hdf5
        run: sudo apt-get install -y libhdf5-dev
      - name: build and test with cabal
        run: cabal test

This works for ghc-9.6 and ghc-9.4. With ghc-9.2, however, it fails with:

dist-newstyle/build/x86_64-linux/ghc-9.2.8/hdf5-1.8.11/t/hdf5-test/build/hdf5-test/hdf5-test: error while loading shared libraries: libffi.so.7: cannot open shared object file: No such file or directory

Is there a way to solve this? And can anyone explain the error?

Hey! Can you share the link to the repo?

GHCup uses the following bindist:

It appears ubuntu 24 doesn’t provide libffi7 anymore: Ubuntu – Package Search Results -- libffi

I don’t see any other official bindist that is built with libffi8 for GHC 9.2.8.

That means I’d have to build it myself. Also see: Build fresh versions of old bindists · Issue #903 · haskell/ghcup-hs · GitHub

The main issues with building GHC stuff downstream at the moment is:

  • there’s no github CI to build GHC yet (my private runners are on GH, for various reasons)
  • the test suite is not run, because
    • it’s incredibly flaky
    • the test bindist is constantly broken (running the test suite in the same env that GHC was built is wrong, but that’s what GHC is currently doing on gitlab)

It might be fixed.

It is fixed. Thank you very much!

Can you also fix it for ghc-9.0? One of my collaborators is using Debian stable, which ships with this ghc version.

I think the correct fix might actually be to remove pkgconfig-depends: libffi: hs-hdf5/hdf5.cabal at 18be07afb6ea1c84fae22b98882974266559900d · picca/hs-hdf5 · GitHub

That makes it pass for me. Apparently you end up with double linkage to libffi if you specify it explicitly:

root@2ca973777cb2:~/hs-hdf5# ldd /root/hs-hdf5/dist-newstyle/build/x86_64-linux/ghc-9.2.8/hdf5-1.8.11/t/hdf5-test/build/hdf5-test/hdf5-test
	linux-vdso.so.1 (0x00007ffe12701000)
	libhdf5_serial.so.103 => /lib/x86_64-linux-gnu/libhdf5_serial.so.103 (0x00007f68e9e30000)
	libffi.so.7 => not found
	libgmp.so.10 => /lib/x86_64-linux-gnu/libgmp.so.10 (0x00007f68e9daf000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f68e9bce000)
	libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f68e9aef000)
	libcrypto.so.3 => /lib/x86_64-linux-gnu/libcrypto.so.3 (0x00007f68e966a000)
	libcurl.so.4 => /lib/x86_64-linux-gnu/libcurl.so.4 (0x00007f68e95bb000)
	libsz.so.2 => /lib/x86_64-linux-gnu/libsz.so.2 (0x00007f68e95b6000)
	libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f68e9597000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f68ea1e8000)
	[...]
	libffi.so.8 => /lib/x86_64-linux-gnu/libffi.so.8 (0x00007f68e8b4b000)

I’m not sure exactly what is going on there.

Indeed! Thanks for the hint!

pkgconfig-depends says “uses pkgconfig to look up the libs here, then link them.” perhaps that helps explain the issue?

Why does it find the internal libffi that’s shipped with GHC and links to it although it’s not in LD_LIBRARY_PATH or anything else?

ghc automatically bundles libffi and links it. see the comprehensive discussion in this haddock documentation: