haskell.compiler.ghc902Binary: fix (system) libffi header discovery

The GHC 9.0.2 bindist expects the headers of libffi to be found under
/Applications/XCode.app instead of /Library (which is the case for later
GHC bindists which I copied the code from). Correctly substituting this
path will prevent GHC from using the bundled and thus outdated libffi
headers that are broken for some reason or other.

That these bundled headers were installed was actually a bug in hadrian
which created the bindists because it ignored use-system-libffi before
GHC 9.2. (This was actually the issue I noticed first because it hides
the actual problem: Because GHC installed these headers, GHC found some
version of ffi.h and ffitarget.h instead of correctly failing due to
missing headers which would indicate that package db is broken.) For the
sake of completeness, we can also solve this problem by deleting these
headers in postInstall.
This commit is contained in:
sternenseemann 2025-07-01 13:40:22 +02:00
parent 190346e1cf
commit fbbdcddada

View File

@ -313,7 +313,7 @@ stdenv.mkDerivation {
# To link RTS in the end we also need libffi now
find . -name 'rts*.conf' \
-exec sed -e '/^[a-z-]*library-dirs/a \ ${lib.getLib libffi}/lib' \
-e 's@/Library/Developer/.*/usr/include/ffi@${lib.getDev libffi}/include@' \
-e 's@/.*/Developer/.*/usr/include/ffi@${lib.getDev libffi}/include@' \
-i {} \;
''
+
@ -363,13 +363,23 @@ stdenv.mkDerivation {
makeFlags = lib.optionals stdenv.buildPlatform.isDarwin [ "XATTR=/does-not-exist" ];
# Patch scripts to include runtime dependencies in $PATH.
postInstall = ''
for i in "$out/bin/"*; do
test ! -h "$i" || continue
isScript "$i" || continue
sed -i -e '2i export PATH="${lib.makeBinPath runtimeDeps}:$PATH"' "$i"
done
'';
postInstall =
''
for i in "$out/bin/"*; do
test ! -h "$i" || continue
isScript "$i" || continue
sed -i -e '2i export PATH="${lib.makeBinPath runtimeDeps}:$PATH"' "$i"
done
''
# On Darwin, GHC doesn't install a bundled libffi.so, but instead uses the
# system one (see postUnpack). Due to a bug in Hadrian, the (bundled) libffi
# headers are installed anyways. This problem has been fixed in GHC 9.2:
# https://gitlab.haskell.org/ghc/ghc/-/merge_requests/8189. While the system
# header should shadow the GHC installed ones, remove them to be safe.
+ lib.optionalString (stdenv.hostPlatform.isDarwin && binDistUsed.isHadrian or false) ''
echo Deleting redundant libffi headers:
find "$out" '(' -name ffi.h -or -name ffitarget.h ')' -print -delete
'';
# Apparently necessary for the ghc Alpine (musl) bindist:
# When we strip, and then run the